chisq.test2: Pearson's Chi-squared Test for Count Data

chisq.test2R Documentation

Pearson's Chi-squared Test for Count Data

Description

chisq.test2 performs Pearson chi-squared goodness-of-fit test for count data

Usage

chisq.test2(obs, p.esp, npar = NULL, grouping = FALSE)

Arguments

obs

a numeric vector with the counts

p.esp

a numeric vector with the expected probabilities of the same length of obs. They must sum 1.

npar

an integer specifying the number of parameters of the model. By default npar is NULL, so the degrees of freedom of the chi-squared statistics are the number of classes minus 1.

grouping

a logical indicating whether to group in classes with expected frequency greater than or equal to 5. By default grouping is FALSE.

Value

A list with class "htest" containing the following components:

  • statistic: the value of the chi-squared test statistic.

  • df: the degrees of freedom of the approximate chi-squared distribution.

  • p.value: the p-value for the test.

  • observed: the observed counts.

  • observed.grouped: the observed counts grouped in classes with expected frequency greather or equal to 5.

  • expected: the expected counts under the null hypothesis.

  • expected.grouped: the expected counts under the null hypothesis grouped in classes with expected frequency greather or equal to 5.

  • residuals: the Pearson residuals computed as (observed - expected) / sqrt(expected).

Examples

set.seed(123)
x <- rctp(500, -1.5, 1, 2)
table(x)
obs <- c(172, 264, 57, 6, 0, 1)
fit <- fitctp(x)
p.esp <- c(dctp(0:(length(obs)-1),fit$coefficients[1],fit$coefficients[2],
           fit$coefficients[3])[1:(length(obs)-1)],1-sum(dctp(0:(length(obs)-1),
           fit$coefficients[1],fit$coefficients[2],fit$coefficients[3])[1:(length(obs)-1)]))
chisq.test2(obs, p.esp)
chisq.test2(obs, p.esp, grouping = TRUE)
chisq.test2(obs, npar= 3, p.esp)

cpd documentation built on Sept. 24, 2023, 1:07 a.m.

Related to chisq.test2 in cpd...