Skip to content

gam questions

6 messages · Henric Nilsson, Brian Ripley, Simon Wood

#
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:

            
That's not very helpful: pagination of manuals depends on the paper size, 
for example.
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.
#
- 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
_____________________________________________________________________
#
At 10:07 2003-06-03 +0100, Prof Brian Ripley wrote:

            
It's the gam.predict example. Instead of pred<-predict.gam(b,newd) I tried 
pred<-predict.gam(b).
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>
#
On Tue, 3 Jun 2003, Henric Nilsson wrote:

            
(Yes, that is current AFAIK.)

The example works.  If you alter it as you state, there is a warning
(only), and that is a bug in mgcv. object$dim == 0 makes no sense as it is
[1] 1 1 1 1

Either all() or any() is needed, but Simon will have to tell you which.
#
- Ok, thanks - this is a bug I missed, I'll fix it. The results should be
unaffected, though. Simon