Hi All,

I have tried every fix on my try or tryCatch that I have found on the
internet, but so far have not been able to get my R code to continue with
the "for loop" after the lmer model results in an error.

Here is two attemps of my code, the input is a 3D array file, but really
any function would do....

metatrialstry<-function(mydata){

a<-matrix(data=NA, nrow=dim(mydata)[3], ncol=5)
#colnames(a)=c("sens", "spec", "corr", "sens_se", "spec_se",
"counter")#colnames(a)=c("sens", "spec", "corr", "sens_se", "spec_se")
k=1
for(ii in 1:dim(mydata)[3]){
    tmp<-mydata[,,ii]
    tmp1<-as.data.frame(tmp)
    names(tmp1)=c("persons", "d1", "tp", "fn", "fp", "fn", "detect", "d0",
"outcome")
    lm1<-try(lmer(outcome~0+d1+d0+(0+d1+d0 | persons), family=binomial,
data=tmp1, nAGQ=3), silent=T)
    if(class(lm1)[1]!='try-error'){
        a[ii,1]=lm1@fixef[1]
        a[ii,2]=lm1@fixef[2]
        a[ii,3]=vcov(lm1)[1,2]/prod(sqrt(diag(vcov(lm1))))
        a[ii,4:5]=sqrt(diag(vcov(lm1)))
        }
    }
    #k=k+1
    #a[ii,6]=k

    return(a)
}

#########################################
######### try / try catch ###############
#########################################



metatrialstry<-function(mydata){

a<-matrix(data=NA, nrow=dim(mydata)[3], ncol=5)
#colnames(a)=c("sens", "spec", "corr", "sens_se", "spec_se", "counter")
colnames(a)=c("sens", "spec", "corr", "sens_se", "spec_se")
#a[,6]=rep(0, length(a[,6]))
for(ii in 1:dim(mydata)[3]){
    tmp<-mydata[,,ii]
    tmp1<-as.data.frame(tmp)
    names(tmp1)=c("persons", "d1", "tp", "fn", "fp", "fn", "detect", "d0",
"outcome")
    lm1<-tryCatch(lmer(outcome~0+d1+d0+(0+d1+d0 | persons),
family=binomial, data=tmp1, nAGQ=3), error=function(e) e)
    a[ii,1]=lm1@fixef[1]
    a[ii,2]=lm1@fixef[2]
    a[ii,3]=vcov(lm1)[1,2]/prod(sqrt(diag(vcov(lm1))))
    a[ii,4:5]=sqrt(diag(vcov(lm1)))
    }
    return(a)
}


Any guidance would be greatly appreciated...

thanks!
Lisa

-- 
Lisa Wang
email: wang.lisay@gmail.com
cell: +49 -0176-87786557
Tübingen, Germany, 72070

	[[alternative HTML version deleted]]

