Chi-squared goodness of fit test in R

后端 未结 1 1272
自闭症患者
自闭症患者 2021-02-04 10:03

I have a vector of observed values and also a vector of values calculated with model:

actual <- c(1411,439,214,100,62,38,29,64)
expected <- c(1425.3,399.5         


        
1条回答
  •  囚心锁ツ
    2021-02-04 10:14

    X^2 = 10.2 at 7 degrees of freedom will give you a p ~ 0.18 .

    > 1-pchisq(10.2, df = 7)
    [1] 0.1775201
    

    You should pass on the expected values under argument p. Make sure you scale your values to sum to 1.

    > chisq.test(actual, p = expected/sum(expected))
    
        Chi-squared test for given probabilities
    
    data:  actual 
    X-squared = 10.2581, df = 7, p-value = 0.1744
    

    This about what X^2 test is doing. You give the function a model (expected) and ask - how likely it is that my observed data came from a population that "generated" expected?

    0 讨论(0)
提交回复
热议问题