Performs an exact multinomial test. Alternative to the chi-square test of goodness-of-fit-test when the sample size is small.

multinom_test(x, p = rep(1/length(x), length(x)), detailed = FALSE)

Arguments

x

numeric vector containing the counts.

p

a vector of probabilities of success. The length of p must be the same as the number of groups specified by x, and its elements must be greater than 0 and less than 1.

detailed

logical value. Default is FALSE. If TRUE, a detailed result is shown.

Value

return a data frame containing the p-value and its significance.

The returned object has an attribute called args, which is a list holding the test arguments.

See also

Examples

# Data tulip <- c(red = 81, yellow = 50, white = 27) # Question 1: are the color equally common ? #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # this is a test of homogeneity res <- multinom_test(tulip) res
#> # A tibble: 1 x 2 #> p p.signif #> * <dbl> <chr> #> 1 0.000000711 ****
attr(res, "descriptives")
#> # A tibble: 3 x 3 #> group observed expected #> <chr> <dbl> <dbl> #> 1 red 81 52.7 #> 2 yellow 50 52.7 #> 3 white 27 52.7
# Pairwise comparisons between groups pairwise_binom_test(tulip, p.adjust.method = "bonferroni")
#> # A tibble: 3 x 9 #> group1 group2 n estimate conf.low conf.high p p.adj p.adj.signif #> * <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> #> 1 red yellow 131 0.618 0.529 0.702 8.51e-3 2.55e-2 * #> 2 red white 108 0.75 0.657 0.828 1.91e-7 5.72e-7 **** #> 3 yellow white 77 0.649 0.532 0.755 1.17e-2 3.50e-2 *
# Question 2: comparing observed to expected proportions #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # this is a goodness-of-fit test expected.p <- c(red = 1/2, yellow = 1/3, white = 1/6) res <- multinom_test(tulip, expected.p) res
#> # A tibble: 1 x 2 #> p p.signif #> * <dbl> <chr> #> 1 0.903 ns
attr(res, "descriptives")
#> # A tibble: 3 x 3 #> group observed expected #> <chr> <dbl> <dbl> #> 1 red 81 79 #> 2 yellow 50 52.7 #> 3 white 27 26.3
# Pairwise comparisons against a given probabilities pairwise_binom_test_against_p(tulip, expected.p)
#> # A tibble: 3 x 10 #> group observed expected n estimate conf.low conf.high p p.adj #> * <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 red 81 79 158 0.513 0.432 0.593 0.811 1 #> 2 yell… 50 52.7 158 0.316 0.245 0.395 0.674 1 #> 3 white 27 26.3 158 0.171 0.116 0.239 0.915 1 #> # … with 1 more variable: p.adj.signif <chr>