我试图将rpy2导入到python中,我收到此错误:
RuntimeError: The R home directory could not be determined.
Try to install R <https://www.r-project.org/>,
set the R_HOME environment variable to the R home directory, or
add the directory of the R interpreter to the PATH environment variable.
Run Code Online (Sandbox Code Playgroud)
我完全迷失在这里,因为我不知道这告诉我什么.我试图搜索如何设置环境变量,但找不到任何对我有帮助的详细信息.如果答案可以非常简单,我会很感激,因为我只是一个新手.我正在运行OSX 10.11.
谢谢(我的第一篇文章,如果我忽略了发布中的任何规则,我道歉)
我正在尝试对拟合优度进行 Pearson 卡方检验。以下是拟合泊松分布的示例:
data <- rpois(200,50)
estimate <- mean(data)
freq.os<-table(data)
yfit <- dpois(as.integer(names(freq.os)), estimate)
chisq.test(x = freq.os, p = yfit)
# Error in chisq.test(x = freq.os, p = yfit) : probabilities must sum to 1.
Run Code Online (Sandbox Code Playgroud)
当我评估时sum(yfit),我得到 0.999839。
那么如何产生一组加起来为1的概率值呢?谢谢!
编辑
其实我找到了一个解决方法:
chisq.test(freq.os, yfit)
Run Code Online (Sandbox Code Playgroud)
但我chisq.test()对它告诉我的工作方式感到非常困惑df = 429。我想df = n - k - 1,在这种情况下应该是 35,其中k = 1lambda 和n = number卡方和中的项。我哪里做错了?