indepchisq.test {LearningStats} | R Documentation |
Chi-squared Independence Test for Categorical Data.
Description
indepchisq.test
allows to computes Chi-squared independence hypothesis test for two categorical values.
Usage
indepchisq.test(Oij, x, y, alpha = 0.05, plot = TRUE, lwd = 1)
Arguments
Oij |
observed frequencies. A numeric matrix, a table or a data.frame with the
observed frequencies can be passed. If missing, arguments |
x |
a vector (numeric or character) or factor with the first categorical variable. |
y |
a vector (numeric or character) or factor with the second categorical variable. It should be of the same
length as |
alpha |
a single number in (0,1), significance level. |
plot |
a logical indicating whether to plot the rejection region and p-value. |
lwd |
a single number indicating the line width of the plot. |
Details
The expected frequencies are calculated as follows
E_{ij}=\frac{n_{i\bullet}\times n_{\bullet j}}{n},
and the test statistic is given by
T = \sum_{i,j} \frac{(n_{ij} - E_{ij})^2}{E_{ij}},
T \in \chi^2_{(r-1)(s-1)}
, where n
is the number of observations, n_{i\bullet}
is the marginal frequency of category i of variable x, n_{\bullet j}
is the marginal frequency of category j of variable y, r is the number of categories in
variable x and s the number of categories in variable y.
The null hypothesis is rejected when T > \chi^2_{(r-1)(s-1),1-\alpha}
, where \chi^2_{(r-1)(s-1),1-\alpha}
is the 1-\alpha
quantile of a \chi^2
distribution with (r-1)(s-1)
degrees of freedom.
Value
A list with class "lstest
" and "htest
" containing the following components:
statistic |
the value of the test statistic. |
parameter |
the degrees of freedom of the statistic's distribution. |
p.value |
the p-value of the test. |
estimate |
a numeric matrix with the estimated frequencies Eij. |
method |
a character string indicating the method used. |
data.name |
a character string giving the names of the data. |
alpha |
the significance level. |
dist.name |
a character string indicating the distribution of the test statistic. |
statformula |
a character string with the statistic's formula. |
reject.region |
a character string with the reject region. |
obs.freq |
a numeric matrix with the observed frequencies Oij. |
Examples
Oij <- matrix(c( 20, 8,
934, 1070,
113, 92), ncol = 2, byrow = TRUE)
indepchisq.test(Oij)