I have a script which, given a response variable and predictors, generates all possible model combinations. I have saved all combinations for my data in a list (length 155). I have written a loop which, on each iteration, uses the next formula on the list:
prico.models.exp <- foreach(z = 1:length(model.formulae), .packages=c("nlme")) %dopar% {
gls(as.formula(model.formulae[z]),data=prico,subset=Freq>50,correlation=corExp(form=~x+y, nugget=T),na.action=na.omit,method="ML",control=xx)
}
When I view the model summaries of each output, the model is listed as as.formula(model.formulae[z])
and not the actual formula (in my example, model 1 would be richness ~ lai
). The correct response and predictors have been used as the model coefficients are correct. For example:
Generalized least squares fit by maximum likelihood
Model: as.formula(model.formulae[z])
Data: prico
Subset: Freq > 50
Log-likelihood: 66.02798
Coefficients:
(Intercept) lai
3.149229862 0.007314029
Correlation Structure: Exponential spatial correlation
Formula: ~x + y
Parameter estimate(s):
range nugget
3.634669e+04 2.123560e-11
Degrees of freedom: 88 total; 86 residual
Residual standard error: 0.2020574
It is important that the model is transferred from the list to the model summary as other functions (e.g. model.avg in MuMIn) requires a formula in the model summary to work. Is it possible to use a loop and keep the formula in the model summary?