I have to do statistical analyses on a data set. I would like to create all the possible models and to test them with the dredge function but it doesn't work. Indeed, when I type:
我需要对数据集进行统计分析,我想创建所有可能的模型,并使用挖掘功能对它们进行测试,但它不起作用。事实上,当我类型:
glm1<-glm(presabs~dca1+dca2+se1+se2, family=binomial(logit))
dredge(glm1)
I got this error:
我得到这个错误:
Erreur dans dredge(glm1) :
'global.model''s 'na.action' argument is not set and options('na.action') is "na.omit"
Can someone help me?
有人能帮助我吗?
2 个解决方案
#1
22
I know this has been solved, however I came across the same issue and think there is a better way.
我知道这个问题已经解决了,但是我遇到了同样的问题,我认为有更好的办法。
The issue with using options(na.action = "na.fail")
is that it changes the global settings of R. If you have a large script changing the global settings will potentially impact on other sections of your code where you implicitly rely on R's default settings. There are two ways to avoid this:
使用选项的问题(na。action = "na.fail")表示它改变了R的全局设置,如果你有一个大的脚本改变全局设置,那么全局设置将潜在地影响到你的代码的其他部分,在那里你隐式地依赖于R的默认设置。有两种方法可以避免这种情况:
- After using
dredge
change the settings back viaoptions(na.action = "na.omit")
. - 使用dredge后,通过选项(na)改变设置。action =“na.omit”)。
OR the better way...
或者更好的办法……
- Utilise the regression function's ability to "set the argument". In your case:
- 利用回归函数的能力“设置参数”。在你的例子:
glm1<-glm(presabs~dca1+dca2+se1+se2, family=binomial(logit), na.action = "na.fail")
glm1 < glm(presabs ~ dca1 + dca2 + se1 + se2,家庭=二项(分对数)、na。action =“na.fail”)
#2
8
See ?dredge
:
看到了什么?泥:
# Example from Burnham and Anderson (2002), page 100:
data(Cement)
options(na.action = "na.fail") # prevent fitting models to different datasets
fm1 <- lm(y ~ ., data = Cement)
dd <- dredge(fm1)
If you skip the second line, your described error pops up, as the models are fitted to different datasets (due to removal of NAs).
如果跳过第二行,就会弹出所描述的错误,因为模型适合于不同的数据集(由于删除了NAs)。
#1
22
I know this has been solved, however I came across the same issue and think there is a better way.
我知道这个问题已经解决了,但是我遇到了同样的问题,我认为有更好的办法。
The issue with using options(na.action = "na.fail")
is that it changes the global settings of R. If you have a large script changing the global settings will potentially impact on other sections of your code where you implicitly rely on R's default settings. There are two ways to avoid this:
使用选项的问题(na。action = "na.fail")表示它改变了R的全局设置,如果你有一个大的脚本改变全局设置,那么全局设置将潜在地影响到你的代码的其他部分,在那里你隐式地依赖于R的默认设置。有两种方法可以避免这种情况:
- After using
dredge
change the settings back viaoptions(na.action = "na.omit")
. - 使用dredge后,通过选项(na)改变设置。action =“na.omit”)。
OR the better way...
或者更好的办法……
- Utilise the regression function's ability to "set the argument". In your case:
- 利用回归函数的能力“设置参数”。在你的例子:
glm1<-glm(presabs~dca1+dca2+se1+se2, family=binomial(logit), na.action = "na.fail")
glm1 < glm(presabs ~ dca1 + dca2 + se1 + se2,家庭=二项(分对数)、na。action =“na.fail”)
#2
8
See ?dredge
:
看到了什么?泥:
# Example from Burnham and Anderson (2002), page 100:
data(Cement)
options(na.action = "na.fail") # prevent fitting models to different datasets
fm1 <- lm(y ~ ., data = Cement)
dd <- dredge(fm1)
If you skip the second line, your described error pops up, as the models are fitted to different datasets (due to removal of NAs).
如果跳过第二行,就会弹出所描述的错误,因为模型适合于不同的数据集(由于删除了NAs)。