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.
n_compare(x, simulate.p.value = FALSE, B = 2000)
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
average difference in subsample sizes (i.e., |ni - nj|)
NA (to remind the user there is no standard error for the test)
chi-square value
degrees of freedom (# of unique values = 1)
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"
atomic vector. Probably makes sense to contain relatively few unique values.
logial vector of length 1 specifying whether the
p-value should be based on a Monte Carlo simulation rather than the classic
formula. See chisq.test
for details.
integer vector of length 1 specifying how much Monte Carlo
simulations run. Only used if simulate.p.value
= TRUE. See
chisq.test
for details.
chisq.test
the workhorse for n_compare
,
props_test
for multiple dummy variables,
prop_diff
for chi-square test of independence,
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"))
Run the code above in your browser using DataLab