0

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.

Community
  • 1
  • 1
  • I think you want `Relevant <- names(Select)[Select[ ,4] == TRUE]`. – eipi10 Feb 24 '16 at 19:04
  • can I recommend (1) `sig.formula <- reformulate(Relevant,response="Percent_Mite._rel_abundc")` instead of your current `sig.formula` call (2) **not doing this at all** for statistical reasons (e.g. see [here](http://www.danielezrajohnson.com/stepwise.pdf) ? – Ben Bolker Feb 24 '16 at 19:26
  • You can. Statistics is really not my field and every hint I can get is greatly appreciated. What would you do with the dataset at hand? – user2952422 Feb 24 '16 at 20:43

1 Answers1

2

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] )
Jeffrey Evans
  • 2,325
  • 12
  • 18