Reputation: 45
I need to run a GLM and have tried to select the significant variables with this approach. However, I keep getting an error message.
The input is:
global.model2<-lm(Percent_Mite._rel_abundc ~ Heightc + logNutrientsc + logNDSc + logNNNc + logOxygenc + Patchc + Precipitationc)
Then I run
Select <- summary(global.model2)$coeff < 0.05
resulting in
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
Next:
Relevant <- names(Select)[Select == TRUE]
Here, the result is
NULL
and the following command
sig.formula <- as.formula(paste("Percent_Mite._rel_abundc ~",paste(Relevant, collapse= "+")))
results in the error message
"Error in parse(text = x, keep.source = FALSE) :
<text>:2:0: unexpected end of input
1: Percent_Mite._rel_abundc ~
^
What am I doing wrong? Some of the variables should be significant.
Upvotes: 0
Views: 744
Reputation: 2397
You are operating on a matrix but the code is assuming a vector. I believe that you want to produce the Boolean vector and not return the entire table of coefficients.
( Select <- summary(global.model2)$coeff[-1,4] < 0.05 )
( Relevant <- names(Select)[Select == TRUE] )
Upvotes: 2