Description Usage Arguments Details Value Note References Examples
View source: R/multinom.test.R
Computes exact pvalues for multinomial goodnessoffit tests based on multiple test statistics, namely, Pearson's chisquare, the loglikelihood ratio and the probability mass statistic. Implements the algorithm detailed in Resin (2020). Estimates based on the classical asymptotic chisquare approximation or MonteCarlo simulation can also be computed.
1 2 3 4 5 6 7 8 9  multinom.test(
x,
p,
stat = "Prob",
method = "exact",
theta = 1e04,
timelimit = 10,
N = 10000
)

x 
Vector of nonnegative integers  number of times each outcome was observed. 
p 
A vector of positive numbers  the hypothesized probabilities for each outcome. Need not sum to 1, but only encode hypothesized proportions correctly. 
stat 
Test statistic to be used. Can be "Prob" for the probability mass, "Chisq" for Pearson's chisquare and "LLR" for the loglikelihood ratio. 
method 
Method used to compute the pvalues. Can be "exact", "asymptotic" and "MonteCarlo". 
theta 
Parameter used with the exact method. pvalues less than theta will not be determined precisely. Values >= 10^8 are recommended. Very small pvalues (< 10^8) may be falsified by rounding errors. 
timelimit 
Time limit in seconds, after which the exact method is interrupted to avoid long runtime. 
N 
Number of samples generated by the MonteCarlo approach. 
The "exact" method implements the algorithm detailed in Resin (2020). The method improves on the full enumeration implemented in some other R packages.
It should work well if the number of categories is small. To avoid long runtimes the exact computation is interrupted after timelimit
seconds.
However, it may take longer than the specified time limit for the actual interrupt to occur. Only pvalues greater theta
are determined precisely.
For pvalues less than theta
, the algorithm will only determine that the pvalue is smaller than theta
.
The "asymptotic" method returns classical chisquare approximations. The asymptotic approximation to the probability mass statistic is detailed in Section 2 of Resin (2020).
The "MonteCarlo" method returns estimates based on N
random draws from the hypothesized distribution.
A list with class "mgof" containing

As input by user. 

As input by user. 

As input by user or default. 

As input by user or default. 

As input by user or default. 

Exact pvalues or NA. WARNING: Values less than theta are NOT exact pvalues, but only imply that the actual pvalue is less than that value. 

Asymptotic approximation to pvalues or NA. 

MonteCarlo estimated pvalues or NA. 
The first pvalue (e.g., pvals_ex[1]
) is obtained from the probability mass, the second from Pearson's chisquare and the third from the loglikelihood ratio.
Each method computes pvalues for all three test statistics simultaneously.
Resin, J. (2020), A Simple Algorithm for Exact Multinomial Tests, Preprint https://arxiv.org/abs/2008.12682
1 2 3 4 5 6 7 8 9 10 11  # Test fairness of a die (that is, whether each side has the same probability)
p_fair = rep(1/6,6) # Hypothesized probabilities for each side
x = c(16,17,12,15,15,25) # Observed number of times each side appeared on 100 throws
# Exact multinomial test (using probability ordering by default):
multinom.test(x,p_fair)
# Exact multinomial test using loglikelihood ratio:
multinom.test(x,p_fair,stat = "LLR")
# Classical chisquare test (using asymptotics to estimate pvalue and Pearson's chisquare):
multinom.test(x,p_fair,stat = "Chisq",method = "asymptotic")
# Using MonteCarlo approach and probability ordering
multinom.test(x,p_fair,stat = "Prob",method = "MonteCarlo")

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.