13

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,201.6,116.9,72.2,46.3,30.4,64.8)

Now I'm using the Chi-squared goodness of fit test to see how well my model performs. I wrote the following:

chisq.test(expected,actual) 

but it doesn't work. Can you help me with this?

4

1 回答 1

15

X^2 = 10.2 在 7 个自由度会给你 ap ~ 0.18 。

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

您应该在参数下传递预期值p。确保将值缩放为总和为 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

这与 X^2 测试正在做什么有关。你给函数一个模型 ( ) 并问 - 我的数据来自“生成”的人口的expected可能性有多大?observedexpected

于 2012-07-10T08:25:11.347 回答