0

I've looked at some of the answers for this question already, there were only two I found helpful and I still cannot get my loop to execute. I am struggling to use a fixed formula for the MCMCglmm package. I have a lot of models to test with this package, and I would like to make a loop to make the work easier. Each time I run MCMCglmm my intention is to do so with a "fixed" formula, and through each iteration of the loop I want to change one of the variables and input a modified version of the "fixed" formula. Here is my code thus far:

for (i in 5:10){
    fixed <- as.formula(paste(as$area_pva ~ as$apva_1yr + as$year + as.numeric(unlist(as[i]))))
    print(fixed)

    model <- MCMCglmm(fixed=fixed,
                    rcov=~units, family="gaussian",
                    data=as,start=NULL, prior=NULL, random=NULL, tune=NULL,
                    pedigree=NULL, nodes=NULL, scale=FALSE, nitt=30000,
                    thin=30, burnin=1000, pr=TRUE, pl=TRUE, verbose=TRUE, 
                    DIC=TRUE, singular.ok=FALSE, saveX=TRUE, saveZ=TRUE, 
                    saveXL=TRUE, slice=FALSE, ginverse=NULL)

   summary(model)


}

Please, if you can help me make this loop execute properly I would appreciate it.

Kait
  • 1

1 Answers1

0

Never mind, I've got the answer. I needed to make the whole formula a series of strings, like this:

fixed <- as.formula(paste("as$area_pva~as$apva_1yr+as$year+", colnames(as)[i], sep=""))

It works perfectly now.

Kait
  • 1