R users, I've still been hashing out bits and pieces related to my initial question as seen here and now I'm quite stuck.
http://stackoverflow.com/questions/12270578/skipping-over-an-error-warning-in-an-lme-loop-in-r
Here is the code using mtcars as an example dataset. I want to save the lower and upper confidence intervals for every response variable as listed below (but not for the intercept, though I still need its other coefficients for the lme but I've got that already), all in one go (my real dataset is very large and I'm trying to automate it as much as possible)
library(log10)
library(nlme)
library(lattice)
responseVariables = c("mpg",
"disp",
"hp")
carModels <- list()
carModelNames <- list()
coint<- list()
coint2<- list()
coint$fixed <- list()
lower<- list()
upper<- list()
carCIlower <- list()
carCIupper <- list()
for (i in responseVariables){
print("Doing: ")
print(i)
mtcars$tmp <- as.numeric(mtcars[,i])
tmpLme <- lme( log10(tmp) ~ I(log10(wt)), random = ~1 | carb / gear / am, data=mtcars,na.action=na.omit )
carModels <- append(carModels, list(tmpLme))
carModelNames <- append(carModelNames,i)
coint <- try(intervals(tmpLme))
if (inherits(coint, "try-error")) {
tmpLme <- lme(log10(tmp) ~ log10(wt), random = ~1 | carb / gear, data=mtcars, na.action=na.omit);
coint <- try(intervals(tmpLme));
} else if (inherits(coint, "try-error")) {
tmpLme <- lme(log10(tmp) ~ log10(wt), random = ~1 | carb / gear, data=mtcars, na.action=na.omit, method="ML");
coint <- try(intervals(tmpLme));
} else if (inherits(coint, "try-error")) {
tmpLme <- lme(log10(tmp) ~ log10(wt), random = ~1 | carb, data=mtcars, na.action=na.omit);
coint <- try(intervals(tmpLme));
#}
coint2<- append(coint, list(tmpLme))
lower <- dim(coint2$fixed)[1]
upper <- dim(coint2$fixed)[1]
carCIlower <- append(carCIlower, coint2$fixed[2,1],lower)
carCIupper <- append(carCIupper, coint2$fixed[2,3],upper)
vs_wt <- cbind(carModelNames , carCIlower , carCIlower )
}
}
Currently I can get the CI values if I run the commands for each response variable, but not as part of the loop. The loop doesn't proceed past the coint2 statement. Well it does but it doesn't give me answers for coint2 and beyond. Or if I run those lines again it'll only give me values for the last item in the loop (i=hp). Also I see there's an unbalanced curly bracket (I've commented it out to show you) but if I use it gives me the lower CI for "disp" for the lower and upper CI for all resp variables.
Can someone point out what's missing?