R,GLM 模型:从完整模型中选择重要变量

R, GLM model: Selection of significant variables from full model

我需要 运行 一个 GLM,并尝试 select 使用 this 方法的重要变量。但是,我不断收到错误消息。

输入为:

global.model2<-lm(Percent_Mite._rel_abundc ~ Heightc + logNutrientsc + logNDSc + logNNNc + logOxygenc + Patchc + Precipitationc)

那我运行

Select <- summary(global.model2)$coeff < 0.05

导致

                 Estimate Std. Error t value Pr(>|t|)
(Intercept)        TRUE      FALSE    TRUE    FALSE
Heightc            TRUE      FALSE    TRUE    FALSE
logNutrientsc     FALSE      FALSE   FALSE    FALSE
logNDSc            TRUE      FALSE    TRUE     TRUE
logNNNc           FALSE      FALSE   FALSE     TRUE
logOxygenc         TRUE      FALSE    TRUE    FALSE
Patchc            FALSE      FALSE   FALSE    FALSE
Precipitationc     TRUE      FALSE    TRUE    FALSE

下一个:

Relevant <- names(Select)[Select == TRUE]

这里,结果是

NULL

和以下命令

sig.formula <- as.formula(paste("Percent_Mite._rel_abundc ~",paste(Relevant, collapse= "+")))

导致错误消息

"Error in parse(text = x, keep.source = FALSE) : <text>:2:0: unexpected end of input 1: Percent_Mite._rel_abundc ~ ^

我做错了什么?一些变量应该很重要。

您正在对矩阵进行运算,但代码假定为向量。我相信您想要生成布尔向量而不是 return 整个 table 系数。

( Select <- summary(global.model2)$coeff[-1,4] < 0.05 )  
( Relevant <- names(Select)[Select == TRUE] )