我有一个错误,只有当我通过rpy2从用户定义函数调用lrtest(从lmtest包)时才会发生。在
右侧:
continuous.test <- function(dat) {
require('lmtest')
options(warn=-1)
model <- lm(formula='pheno ~ .', data=dat)
anova <- lrtest(model,'interaction')
pval <- anova$"Pr(>Chisq)"[2]
}
当我从R解释器调用这个函数时,一切都正常运行。但是,当从下面的python代码片段调用时,我收到一个错误。注意,这个特定的python文件成功地调用了rpy2。在
Python:
^{pr2}$错误:
Error in is.data.frame(data) : object 'dat' not found
Traceback (most recent call last):
File "./test_r_.py", line 83, in <module>
pval = continuous_test(kway_dat)
File "/usr/lib/python2.6/site-packages/rpy2-2.2.6dev_20120806-py2.6-linux-x86_64.egg/rpy2/robjects/functions.py", line 82, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/rpy2-2.2.6dev_20120806-py2.6-linux-x86_64.egg/rpy2/robjects/functions.py", line 34, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in is.data.frame(data) : object 'dat' not found
故障排除:
任何帮助都会很好。谢谢大家!在
找到答案
问题是lrtest内部要求更新模型。一旦进入lrtest,dat就超出了范围。通过手动更新模型并使用lrtest的替代调用lrtest(model0,model1),这个问题就完全避免了。在
感谢阿希姆·泽利斯,他非常迅速地回答了。在
用一个独立的例子来帮助你会更容易(这样你就可以准确地再现你正在经历的事情)。在
一个可能的答案仍然是:您可能需要检查文件的内容
/path/to/user/defined/file/perm_test.r
确实是你想象的那样。在我还添加了一个自包含的存根:
相关问题 更多 >
编程相关推荐