[R-sig-ME] looping with multiple response variables lme4

Joehanes, Roby (NIH/NHLBI) [F] roby.joehanes at nih.gov
Fri Apr 6 16:17:52 CEST 2012


Hi Justus:

I think you forgot to surround the formula with quotes, like this:
stmLM <- as.formula(paste(Response[i],"~ccov + x5k_c + ltr + x5k_fr + elev + (1|P_ID) + (1|mtx) + (1|site)"))

The error is basically saying you are trying to paste a string into a formula, which does not work.

Hope this helps,
Roby


On Apr 5, 2012, at 9:29 PM, Justus Deikumah wrote:

> Dear lme4 professionals
> 
> Thank you for any help on the subject matter.
> 
> I am doing a linear mixed effects modelling with 10 response variables and 5 predictors using lme4. I have 126 model combinations if I run my model with one response variable at a time. This seems very manual and will take the rest of my PhD. I have tried haven read some of your recent papers on loops and iterations so I have tried to write a sript for this with help from some friends as follows:
> What I want the loop to do for me is to model each response with all the candidate predictors, drop one predictor and run the models again for all the 126 combinations. Then I want to produce Estimated coefficients of fixed effects, SD, SE, AICs etc as output that can be sent into an excel template for model averaging?
> attach(var1)
> Response <- c("gnst", "spst", "fvt", "Oph", "cniv", "frgv", "gniv", "inct","omnv","Sobs", "ACE", "Chao1","Chao2", "Abund")
> 
> ## Output storage step up
> results <- vector("list", length(Response))
> ##Start the loop
> #Create the formula string
> #stmLM <- as.formula(paste(Response[i]~ccov + x5k_c + ltr + x5k_fr + elev + (1|P_ID) + (1|mtx) + (1|site)))
> 
> 
> 
> lmer <- lmer(stmLM)
> 
> # Save the results{
> results[[i]] <- summary(lmer)
> }
> {
> print(results[[i]])
> }
> My problem is anytime I reach summary and results portion of the analysis then i receive the error message below;
> 
> Error: length(formula <- as.formula(formula)) == 3 is not TRUE
> this is making my R-training uneasy for me. Can someone pls tell me what is wrong as I believe there may be a problem with the for loop of which i am new to anyway. What does the error message say? Has anyone any scripts for this??I am using the imer function? What kind of object doest lmer produce?
> Hope someone understands my question and can help, Please!!
> Thank you
> 
> 
> 
> Deikumah Justus
> PhD Candidate (Confirmed) - Landscape Ecology & Conservation
> Landscape Ecology and Conservation Group
> School of Geography, Planning and Environmental Management
> The University of Queensland
> Brisbane Qld 4072
> Australia
> 
> Chamberlain Building (35)
> Campbell Rd - St Lucia Campus
> 
> W: http://www.gpem.uq.edu.au/cser-jdeikumah
> E: j.deikumah2 at uq.edu.au
> M: +61 424481796, +61 479094200
> If you don't like something, Change it. If you can't change it, change your Attitude. DON'T COMPLAIN (Maya Angelou)
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models




More information about the R-sig-mixed-models mailing list