Reputation: 25
I'm running glmulti()
to select the covariables for my linear model and I'm stuck into the opposite problem of this question: namely, I don't get how to ask glmulti
to test also the interactions among covariables.
That is what I've tried so far (the first three point are needed to avoid retyping all the variables and the interactions):
First, wrote a dummy model with all my explanatory variables squaring them so the model would also include the interactions among them.
FullModel.PSS <- lm(formula = PSS ~ 1 + (DBH + Heigth + Nord + Est + Altitude + Dominance + Age + CompIndx)^2, data = PSS.df)
Then I saved the summary to extract the names of all the terms included in the model, hence of the covariables and their interactions. This allowed me to extract all their names, so I can simply type my vector instead of listing them all.
SummaryFullModel <- summary(FullModel)
Variables <- rownames(SummaryFullModel$coefficients)[-1]
I prepared a character vector with the formula of the full model.
ModelFormula < -paste0("PSS ~", paste(Variables, collapse = "+"))
It appears in this way:
"PSS~DBH+Heigth+Nord+Est+Altitude+Dominance+Age+CompIndx+DBH:Heigth+DBH:Nord+DBH:Est+DBH:Altitude+DBH:Dominance+DBH:Age+DBH:CompIndx+Heigth:Nord+Heigth:Est+Heigth:Altitude+Heigth:Dominance+Heigth:Age+Heigth:CompIndx+Nord:Altitude+Nord:Dominance+Nord:Age+Nord:CompIndx+Est:Altitude+Est:Dominance+Est:Age+Est:CompIndx+Altitude:Dominance+Altitude:Age+Altitude:CompIndx+Dominance:Age+Dominance:CompIndx+Age:CompIndx"
And here it is glmulti itself, where molst likely I misunderstood the syntax and I can't get in which way I did it.
I tried first
BestMode<-glmulti(y = ModelFormula, data = PSS, level = 2, method = "h", fitfunction = lm, crit = "bic", plotty = F)
It's been running for three days. Sure, it's testing also the interactions as well - I can see some have been included in the best model so far - but I fear it's evaluating also interactions between interactions and explanatory variables, something that I'd deem of a way too higher level.
So I tried
BestModel<-glmulti(y = "PSS ~ 1 + DBH + Heigth + Nord + Est + Altitude + Dominance + Age + CompIndx", data = PSS.df, level = 2, method = "h", fitfunction = lm, crit = "bic", plotty = F)
and this one too is still running. My reasoning wasthat the level = 2
would ensure glmulti
would test the variables and their interactions, but it's likely doing something more computational-intensive.
I eventually tried
BestMode<-glmulti(y = ModelFormula, data = PSS, level = 1, method = "h", fitfunction = lm, crit = "bic", plotty = F)
In howe it would consider the interactions as covariates. This time it took some second but, looking at the screen output, it wasn't boithered to account for iteraction terms into the model. My hypothesis is that it couldn't do so beacause interaction terms aren't given in the dataframe.
Hence my question: Can somebody enlight me on how to include the interaction terms? Thanks
Upvotes: 0
Views: 29