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 × 2
#>             p p.signif
#> *       <dbl> <chr>   
#> 1 0.000000711 ****    

attr(res, "descriptives")
#> # A tibble: 3 × 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 × 9
#>   group1 group2     n estimate conf.low conf.high           p      p.adj p.adj…¹
#> * <chr>  <chr>  <dbl>    <dbl>    <dbl>     <dbl>       <dbl>      <dbl> <chr>  
#> 1 red    yellow   131    0.618    0.529     0.702 0.00851        2.55e-2 *      
#> 2 red    white    108    0.75     0.657     0.828 0.000000191    5.72e-7 ****   
#> 3 yellow white     77    0.649    0.532     0.755 0.0117         3.5 e-2 *      
#> # … with abbreviated variable name ¹​p.adj.signif


# Question 2: comparing observed to expected proportions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# this is a goodness-of-fit test
expected.p <- c(red = 0.5, yellow = 0.33, white = 0.17)
res <- multinom_test(tulip, expected.p)
res
#> # A tibble: 1 × 2
#>       p p.signif
#> * <dbl> <chr>   
#> 1 0.942 ns      
attr(res, "descriptives")
#> # A tibble: 3 × 3
#>   group  observed expected
#>   <chr>     <dbl>    <dbl>
#> 1 red          81     79  
#> 2 yellow       50     52.1
#> 3 white        27     26.9

# Pairwise comparisons against a given probabilities
pairwise_binom_test_against_p(tulip, expected.p)
#> # A tibble: 3 × 10
#>   group  observed expected     n estimate conf.low conf.high     p p.adj p.adj…¹
#> * <chr>     <dbl>    <dbl> <dbl>    <dbl>    <dbl>     <dbl> <dbl> <dbl> <chr>  
#> 1 red          81     79     158    0.513    0.432     0.593 0.811     1 ns     
#> 2 yellow       50     52.1   158    0.316    0.245     0.395 0.800     1 ns     
#> 3 white        27     26.9   158    0.171    0.116     0.239 1         1 ns     
#> # … with abbreviated variable name ¹​p.adj.signif