Dear all, I'm a fairly new R user having two questions regarding gam: 1. The prediction example on p. 38 in the mgcv manual. In order to get predictions based on the original data set, by leaving out the 'newdata' argument ("newd" in the example), I get an error message "Warning message: the condition has length > 1 and only the first element will be used in: if (object$dim == 0) m <- 0 else m <- length(object$sp)" I suspected that it had somthing to do with the data not being attached, but when fitting a gam with an attached data set I got the same error. Why? 2. I've fitted a glm y~a+x+a:x, where a is a 3 level factor and x is a continuous covariate. If I want to fit a similar gam model, is it correct to fit y~a+s(x)+s(x,by=a.1)+s(x,by=a.2)+s(x,by=a.3), where a.1--a.3 are dummy variables representing each level of the factor? Or is the s(x) term redundant? Any hints are greatly appreciated. Best wishes, Henric --------------------------------------------------------------------------------------- Henric Nilsson, Statistician Statisticon AB, ?stra ?gatan 31, SE-753 22 UPPSALA Phone (Direct): +46 (0)18 18 22 37 Mobile: +46 (0)70 211 68 36 Fax: +46 (0)18 18 22 33 <http://www.statisticon.se>
On Tue, 3 Jun 2003, Henric Nilsson wrote:> I'm a fairly new R user having two questions regarding gam: > > 1. The prediction example on p. 38 in the mgcv manual.That's not very helpful: pagination of manuals depends on the paper size, for example.> In order to get > predictions based on the original data set, by leaving out the 'newdata' > argument ("newd" in the example), I get an error message > > "Warning message: the condition has length > 1 and only the first element > will be used in: if (object$dim == 0) m <- 0 else m <- length(object$sp)" > > I suspected that it had somthing to do with the data not being attached, > but when fitting a gam with an attached data set I got the same error. Why?That is a warning not an error! It was a bug in mgcv a while back. Do you have the latest version of mgcv (and of R, for that matter)? I am not seeing this any more. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
> 2. I've fitted a glm y~a+x+a:x, where a is a 3 level factor and x is a > continuous covariate. If I want to fit a similar gam model, is it correct > to fit y~a+s(x)+s(x,by=a.1)+s(x,by=a.2)+s(x,by=a.3), where a.1--a.3 are > dummy variables representing each level of the factor? Or is the s(x) term > redundant?- yes the s(x) term is redundant and in the current mgcv version will likely cause spectacular nonsense as a result of lack of identifiability in the smooth part of the model (mgcv 0.9 will cope with this when released, but it's still much better to use an identifiable smooth model). Simon _____________________________________________________________________> Simon Wood simon at stats.gla.ac.uk www.stats.gla.ac.uk/~simon/ >> Department of Statistics, University of Glasgow, Glasgow, G12 8QQ >>> Direct telephone: (0)141 330 4530 Fax: (0)141 330 4814
At 10:07 2003-06-03 +0100, Prof Brian Ripley wrote:> > 1. The prediction example on p. 38 in the mgcv manual. >That's not very helpful: pagination of manuals depends on the paper size, >for example.It's the gam.predict example. Instead of pred<-predict.gam(b,newd) I tried pred<-predict.gam(b).>Do you have the latest version of mgcv (and of R, for that matter)?I'm running R 1.7.0 under Windows 2000 with mgcv 0.8-8. Best, Henric --------------------------------------------------------------------------------------- Henric Nilsson, Statistician Statisticon AB, ?stra ?gatan 31, SE-753 22 UPPSALA Phone (Direct): +46 (0)18 18 22 37 Mobile: +46 (0)70 211 68 36 Fax: +46 (0)18 18 22 33 <http://www.statisticon.se>