chi-square - two sample test in r

本秂侑毒 提交于 2019-12-12 04:33:54

问题


There is in R a function to perform a chi-square two sample test ?http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/chi2samp.htm

For example I whant to prove if x = rnorm(100) and y = rnorm(100) come from the same distribution.

I tried to use the chisq.test function, but I think it is not correct because it gives me a very large p-value

> chisq.test(rnorm(100),runif(100))

    Pearson's Chi-squared test

data:  rnorm(100) and runif(100)
X-squared = 9900, df = 9801, p-value = 0.239

thank you


回答1:


I have similar data - binned length frequencies of fish from two different sampling methods. Because my data are binned, as I understand it, it is not appropriate to use the KS test, because that test requires continuous data. So, I too, came across the Chi Square two sample test offered by DataPlot at the link you provide: http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/chi2samp.htm

I installed the Dataplot software, and communicated with the contact person for the test when I had problems. I've also run it in R, and gotten the same result (a good check). Here's what I coded in R:

col1=c(2,4,22,46,81,103,238,65,82,9,58,2) col2=c(0,0,1,1,0,10,32,22,20,4,0,0) chisq.test(cbind(col1,col2))

Pearson's Chi-squared test

data: cbind(col1, col2) X-squared = 53.782, df = 11, p-value = 1.293e-07

NOTE: Dataplot did not mind if I had a bin that had zeros for both of my samples, but R does - after much frustration I realized this, removed the shared 0s, and R gave me the same test stat, df, and p value that I got with DataPlot. Hope this helps!



来源:https://stackoverflow.com/questions/44036740/chi-square-two-sample-test-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!