Hi all R users ! I'm using gamm function from Simon Wood's mgcv package, to fit a spatial regression Generalized Additive Mixed Model, as covariates I have the geographical longitude and latitude locations of indexed data. I include a random effect for each district (dist) so the code is fit <- gamm(y~s(lon,lat,bs="tp", m=2)+offset(log(exp.)), random=list(dist=~1), family="poisson", niterPQL=30) when I run the gamm function I obtain the next error message: %%% Maximum number of PQL iterations: 30 iteration 1 iteration 2 ... iteration 8 iteration 9 iteration 10 Error in chol(XVX + S) : the leading minor of order 29 is not positive definite %%% Could be any problem in gamm() ??? -- [[alternative HTML version deleted]]
Well, it's certainly a problem detected by gamm, but whether it's a fundamental statistical problem with this model/data combination or something fixable by taking an alternative approach within gamm I can't tell. Would you be able to send me the data used here (I promise not to use it for anything else, of course), so I can figure out where the problem is? best, Simon> I'm using gamm function from Simon Wood's mgcv package, to fit a spatial > regression Generalized Additive Mixed Model, as covariates I have the > geographical longitude and latitude locations of indexed data. I include a > random effect for each district (dist) so the code is > > fit <- gamm(y~s(lon,lat,bs="tp", m=2)+offset(log(exp.)), > random=list(dist=~1), family="poisson", niterPQL=30) > > when I run the gamm function I obtain the next error message: > > %%% > Maximum number of PQL iterations: 30 > iteration 1 > iteration 2 > ... > iteration 8 > iteration 9 > iteration 10 > Error in chol(XVX + S) : the leading minor of order 29 is not positive > definite > %%% > > Could be any problem in gamm() ??? > > -- > > [[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.--> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283
Thanks for sending the data... The problem is triggered by only having one observation per district, so that you have a random effect for each datum. This causes the correlation of the parameter estimates/predictions for the smooth term to become so high that covariance matrix of the smooth coefficients is no longer +ve definite. You can easily see the very high correlations by replacing the smooth with a low order polynomial in lon and lat and fitting with glmmPQL --- the correlation for the fixed effect parameters is rather high. I can patch gamm so that it provides an answer anyway: but it will only produce extremely high variance estimates for the smooth, reflecting the fundamental identifiability problem in separating the smooth variation from the random effect for a model with a random effect for each datum. best, Simon On Tuesday 02 October 2007 15:50, Dae-Jin Lee wrote:> Hi all R users ! > > I'm using gamm function from Simon Wood's mgcv package, to fit a spatial > regression Generalized Additive Mixed Model, as covariates I have the > geographical longitude and latitude locations of indexed data. I include a > random effect for each district (dist) so the code is > > fit <- gamm(y~s(lon,lat,bs="tp", m=2)+offset(log(exp.)), > random=list(dist=~1), family="poisson", niterPQL=30) > > when I run the gamm function I obtain the next error message: > > %%% > Maximum number of PQL iterations: 30 > iteration 1 > iteration 2 > ... > iteration 8 > iteration 9 > iteration 10 > Error in chol(XVX + S) : the leading minor of order 29 is not positive > definite > %%% > > Could be any problem in gamm() ??? > > -- > > [[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.--> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283
Dae-Jin, Thanks for your (offline) persistance: you are right the problem is with `gamm'. There was a dimension dropping error in `formXtViX' (called by `gamm') for group sizes of 1 (as occurs when you have a random effect per observation). This will be fixed in mgcv_1.3-28. best, Simon On Tuesday 02 October 2007 15:50, Dae-Jin Lee wrote:> Hi all R users ! > > I'm using gamm function from Simon Wood's mgcv package, to fit a spatial > regression Generalized Additive Mixed Model, as covariates I have the > geographical longitude and latitude locations of indexed data. I include a > random effect for each district (dist) so the code is > > fit <- gamm(y~s(lon,lat,bs="tp", m=2)+offset(log(exp.)), > random=list(dist=~1), family="poisson", niterPQL=30) > > when I run the gamm function I obtain the next error message: > > %%% > Maximum number of PQL iterations: 30 > iteration 1 > iteration 2 > ... > iteration 8 > iteration 9 > iteration 10 > Error in chol(XVX + S) : the leading minor of order 29 is not positive > definite > %%% > > Could be any problem in gamm() ??? > > -- > > [[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.--> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK > +44 1225 386603 www.maths.bath.ac.uk/~sw283