Regarding chisq.test (x, p) function for goodness of fit, how does R tell the degree of freedom of chi-square?

93 Views Asked by At

If I test x against a Poisson hypothesis, then I use mean(x) as lambda to calculate p so df = k - 2; if against a Normal hypothesis, then I use mean(x) and var(x) to calculate p so df = k - 3. How can R return a chisq value without knowing the df lost by parameter estimated to get p?

#say I have some data that I want to test against Poisson
data = c(0, 0, 0, 1, 0, 1, 2, 2); 
lambda = mean(data); #0.75
bins = c(0, 1, 2, 3); #bins for grouping data
x = c(4, 2, 2, 0); #number of observations for bins
p = dpois(bins, lambda);
chisq.test(x, p=p, rescale.p=TRUE)
#the df should be number of bins - 1 - number of estimates, so 2, but R gave df = 3, ignoring (not knowing) the 1df lost in lambda.

I group the original observations into a frequency vector (x) based on bins and assign null-hypothesis probabilities to a vector (p) based on bins using original data to estimate unknown null-hypothesis distribution parameters. Then call chisq.test(x, p=p, rescale.p=TRUE) to test x against some distribution assumption. Is it the right way to do such a test?

0

There are 0 best solutions below