indepchisq.test: Chi-squared Independence Test for Categorical Data.

Description Usage Arguments Details Value Examples

View source: R/indepchisq.test.R

Description

indepchisq.test allows to computes Chi-squared independence hypothesis test for two categorical values.

Usage

1
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 and y must be supplied.

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 x.

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 = ∑_{i,j} \frac{(n_{ij} - E_{ij})^2}{E_{ij}},

T \in χ^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 > χ^2_{(r-1)(s-1),1-α}, where χ^2_{(r-1)(s-1),1-α} is the 1-α quantile of a χ^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

1
2
3
4
Oij <- matrix(c( 20,    8,
                934, 1070,
                113,   92), ncol = 2, byrow = TRUE)
indepchisq.test(Oij)

LearningStats documentation built on April 21, 2021, 9:06 a.m.