R中的卡方拟合优度检验 [英] Chi-squared goodness of fit test in R

查看:56
本文介绍了R中的卡方拟合优度检验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个观察值向量和一个用模型计算的值向量:

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?

推荐答案

X^2 = 10.2 at 7 自由度会给你一个 p ~ 0.18 .

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

您应该在参数 p 下传递预期值.确保将值调整为总和为 1.

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

这是关于 X^2 测试在做什么.你给函数一个模型(expected)并询问 - 我的观察到数据来自生成"expected的总体的可能性有多大?

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?

这篇关于R中的卡方拟合优度检验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆