Test two multinomial datasets
multinom.test.Rd
Peforms a two-sample test for two multinomial vectors testing \(H_0:\) the underlying multinomial probability vectors are the same vs. \(H_1:\) they are different.
Arguments
- x, y
Integer vectors (or matrices/dataframes containing multiple integer vector observations as rows).
x
andy
must be the same type and dimension. Ifx
andy
are matrices (or dataframes), the \(i^th\) row ofx
will be tested against the \(i^th\) row ofy
for all \(i\) in 1..nrow(x)
. Alternatively,x
can be a list of two vectors, matrices, or dataframes to be compared. In this case,y
is NULL by default.
Value
The statistic
and its associated p-value
.
If x
and y
are either matrices or dataframes, a
statistic
and p-value
will be returned for each row.
See also
Amanda Plunkett & Junyong Park (2018) Two-Sample Test for Sparse High Dimensional Multinomial Distributions, TEST, https://doi.org/10.1007/s11749-018-0600-8
Examples
#Generate two vectors from the same distribution:
data <- genMultinomialData(sample_size=1)
#Perform test (the following three calls of multinom.test are equivalent):
multinom.test(x=data[[1]], y=data[[2]])
#> $statistic
#> [1] 0.8647447
#>
#> $pvalue
#> [1] 0.1935895
#>
multinom.test(data)
#> $statistic
#> [1] 0.8647447
#>
#> $pvalue
#> [1] 0.1935895
#>
data |> multinom.test()
#> $statistic
#> [1] 0.8647447
#>
#> $pvalue
#> [1] 0.1935895
#>
#Generate 1000 vectors from each of two different distributions:
data <- genMultinomialData(null_hyp=FALSE,sample_size=1000)
#Perform test (compare the ith row of x to the ith row of y for all rows):
result <- multinom.test(x=data[[1]],y=data[[2]])
#Return power of test at the alpha=0.05 level:
alpha <- 0.05
mean(result$pvalue<alpha)
#> [1] 1