n_compare {quest} | R Documentation |
Test for Equal Frequency of Values (chi-square test of goodness of fit)
Description
n_compare
tests whether all the values for a variable have equal
frequency with a chi-square test of goodness of fit. n_compare
does
not currently allow for user-specified unequal frequencies of values; this is
possible with chisq.test
. The function also calculates
the counts and overall percentages for the value frequencies.
prop_test
is simply a wrapper for chisq.test
plus
some extra calculations.
Usage
n_compare(x, simulate.p.value = FALSE, B = 2000)
Arguments
x |
atomic vector. Probably makes sense to contain relatively few unique values. |
simulate.p.value |
logial vector of length 1 specifying whether the
p-value should be based on a Monte Carlo simulation rather than the classic
formula. See |
B |
integer vector of length 1 specifying how much Monte Carlo
simulations run. Only used if |
Value
list of numeric vectors containing statistical information about the frequency comparison: 1) nhst = chi-square test of goodness of fit stat info in a numeric vector, 2) count = numeric vector of length 3 with table of counts, 3) percent = numeric vector of length 3 with table of overall percentages
1) nhst = chi-square test of goodness of fit stat info in a numeric vector
- diff_avg
average difference in subsample sizes (i.e., |ni - nj|)
- se
NA (to remind the user there is no standard error for the test)
- X2
chi-square value
- df
degrees of freedom (# of unique values = 1)
- p
two-sided p-value
2) count = numeric vector of length 3 with table of counts with an additional element for the total. The names are 1. "n_'lvl[k]'", 2. "n_'lvl[j]'", 3. "n_'lvl[i]'", ..., X = "total"
3) percent = numeric vector of length 3 with table of overall percentages with an additional element for the total. The names are 1. "n_'lvl[k]'", 2. "n_'lvl[j]'", 3. "n_'lvl[i]'", ..., X = "total"
See Also
chisq.test
the workhorse for n_compare
,
props_test
for multiple dummy variables,
prop_diff
for chi-square test of independence,
Examples
n_compare(mtcars$"cyl")
n_compare(mtcars$"gear")
n_compare(mtcars$"cyl", simulate.p.value = TRUE)
# compare to chisq.test()
n_compare(mtcars$"cyl")
chisq.test(table(mtcars$"cyl"))