chisq.test2 {cpd}R 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:

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)

[Package cpd version 0.3.2 Index]