The suggested duplicate, Extract the full p.value from chisq.test, doesn’t answer my question.
The answer there is about the p-value output is not in the format as expected. My question has nothing to do with p-value. My concern is on degree of freedom.
If the observation group is n, number of unknow parameters in distribution is r, then in chi-square test, the degree of freedom should be n-r-1. But in chisq.test output, it is always n-1.
The is my confusion.
I am running chi-square test of goodness of fit, the observation data was well groupped to observation freq.
I assume the data obey the normal distribution N(μ σ^2), while μ and σ^2 are unknown. So I use their estimation. Consequently, I calculate out the probabilities and input in vector p
>x<-c(6,13,14,27,25,19,10,6) #observation freq
>p<-c(0.0505, 0.0874, 0.1533, 0.2088, 0.2088, 0.1533, 0.0874, 0.0505)
#probabilities from normal distribution
test_result<-chisq.test(x=x,p=p)
test_result
Chi-squared test for given probabilities
data: x
X-squared = 1.8468, df = 7, p-value = 0.9678
my question:
from the out put, the degree of freedon is 7 (df=7), I know because the data was in 8 groups so df=8-1=7
However, that is perfect if the parameters (μ and σ^2) in normal distribution is precise. In this case, they are unknow and I used ther estimations. The degree of freedon should be 8-2-1=5 (there are two unknow parameters)
How to run chi-square test when there are unknow parameters in probability density function?
$endgroup$
5
What you’re asking is not possible for the ‘chisq.test’ function because the degrees of freedom are calculated from the data provided to the function and there is no option to tell the function to adjust this value.
You can run the test normally, as you have done, and then recalculate the p-value using ‘pchisq()’ by supplying the adjusted degrees of freedom.
pchisq(test_result$statistic, df=test_result$parameter - 2, lower.tail=FALSE)
$endgroup$