Done it!
It solves my problem.
Thank you very much
At 22:12 30/4/2008, Andrew Robinson wrote:>Tomas,
>
>I suggest that you use
>
>try()
>
>Andrew
>
>On Wed, Apr 30, 2008 at 05:30:05PM +0200, Tomas Goicoa wrote:
> > Dear R users,
> >
> > I want to conduct a small simulation study and I have to use the lme
> > function in a loop to save the restricted log likelihood.
> > However, for one simulated data set the lme function gives this error
> >
> >
> > Error en lme.formula(yboot ~ X[, -1], data = data.fr, random =
Z.block) :
> > nlminb problem, convergence error code = 1
> > message = singular convergence (7)
> >
> > and then, the simulation stops. I would like to skip this
> > simulated data, and then continue with the loop, but I cannot find
> > the way of doing this. I am using R2.6.2.
> >
> > Can anybody tell me if I can write a condition to avoid the
> "problematic" data?
> >
> > I Have also obtained similar errors
> >
> > Error en lme.formula(yboot ~ X[, -1], data = data.fr, random =
Z.block) :
> > nlminb problem, convergence error code = 1
> > message = false convergence (8)
> >
> >
> >
> >
> > My data can be reproduced as follows
> >
> >
> > library(splines)
> > library(nlme)
> >
> >
> > x<-c(rep(1993:2007,9))
> > barrio<-factor(c(rep(1:9,rep(15,9))))
> >
> > xl<-min(x)-0.00001
> > xr<-max(x)+0.00001
> > ndx<-4
> > bdeg<-3
> > pord<-2
> > dx <- (xr-xl)/ndx
> > knots <- seq(xl-bdeg*dx, xr+bdeg*dx, by=dx)
> >
> > B<-spline.des(knots,x,bdeg+1,0*x)$design
> >
> > m=ncol(B)
> > D=diff(diag(m),differences=pord)
> > P=t(D)%*%D
> > P.svd=svd(t(D)%*%D)
> > U=(P.svd$u)[,1:(m-pord)]
> > d=(P.svd$d)[1:(m-pord)]
> > Delta=diag(1/sqrt(d))
> > Z=B%*%U%*%Delta
> > X=NULL
> > for(i in 0:(pord-1)){X=cbind(X,x^i)}
> >
> > ### This X and Z matrix are the matrices in the mixed model
> > representation of a spline
> >
> >
> > n<-nrow(X)
> > Id<- factor(rep(1,n))
> > Z.block<-list(list(Id=pdIdent(~Z-1)),list(barrio=pdIdent(~1)))
> > Z.block<-unlist(Z.block,recursive=FALSE)
> >
> > fijos2<-c(-326.9178203,0.1645375 )
> > ef.spline<-c(-0.2214524, -0.1649163, -0.1649163, 0.8878776,
-0.2214524)
> >
> > set.seed(48)
> > ef.error<-rnorm(135,0,sqrt(0.03073974))
> >
> > where
> >
> > ef.spline are standardized random effects, and errores are the
residuals.
> >
> >
> >
> >
> > My loop looks like this
> >
> >
> > B<-1000
> > y.boot<-array(0,c(nrow(Z),B))
> > log.comp<-array(0,B)
> >
> >
> > while(i<B){
> > i<-i+1
> > spline<-sample(ef.spline,size=ncol(Z),replace=T)
> > errores<-sample(ef.error,size=nrow(Z),replace=T)
> > y.boot[,i]<-X%*%fijos2+Z%*%spline+errores
> > yboot<-y.boot[,i]
> > data.fr <- groupedData( yboot ~ X[,-1] |Id ,data > >
data.frame(yboot,X,Z,barrio))
> > log.comp[i]<-lme(yboot~X[,-1],data=data.fr,random=Z.block)$logLik
> > }
> >
> >
> >
> > The idea is to add a condition in the loop such that
> >
> > if(condition......) {i<-i-1}
> >
> > and then substitute the "problematic" data by a new one,
> >
> > Many thanks,
> >
> > Tomas Goicoa
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>--
>Andrew Robinson
>Department of Mathematics and Statistics Tel: +61-3-8344-6410
>University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
>http://www.ms.unimelb.edu.au/~andrewpr
>http://blogs.mbs.edu/fishing-in-the-bay/