Re: [S] Fw: difference between predict

Prof Brian D Ripley (ripley@stats.ox.ac.uk)
Tue, 25 Aug 1998 11:55:02 +0100 (BST)


On Tue, 25 Aug 1998, alain Le Tertre wrote:

> I have received some e-mail from people who need the answer, but no answer,
> even from s-help.
> So, i'll resend my question.
> -----Original Message-----
> From: alain Le Tertre <alain@worldnet.fr>
> To: s-news <s-news@wubios.wustl.edu>
> Date: mercredi 29 juillet 1998 10:24
> Subject: difference between predict
>
>
> >In S-plus 4 guide to statistics p 221, "Specifying type="terms" allows you
> >to compute the component of the prediction for each term separately.
> Summing
> >the columns of the matrix and adding the constant (intercept) term is
> >equivalent to specifying type="link"".
> >So try :
> >zzz_gam(Kyphosis ~ poly(Age, 2) + s(Start), data = kyphosis)
> >cbind(predict(zzz,type="link"),zzz$coef[1]+rowSums(predict(zzz,type="terms"
> )
> >))
> >give you :
> >1 1.6582944 2.059893
> > 2 1.1161389 1.517737
> > 3 1.6671144 2.068713
> > 4 1.1938420 1.595441
> > 5 0.8517588 1.253357
> > 6 0.8213737 1.222972
> > 7 1.0687632 1.470362
> > 8 1.0036325 1.405231
> > 9 1.1289169 1.530515
> >10 1.2703754 1.671974
> >11 1.1993687 1.600967
> >[snip]
> >Did i misunderstand something?

Yes, you forgot what you did. That is not the answer I get in any version
of S-PLUS, including 4.0. For predict(zzz,type="terms") I get

> predict(zzz,type="terms")
poly(Age, 2) s(Start)
1 0.08258339 0.365834444
2 0.01648093 -0.110218544
3 0.09140342 0.365834444
4 -0.19312593 0.177091404
5 -0.19925564 -0.158862081
6 -0.19925564 -0.189247205
7 0.06061139 -0.201724696
8 -0.01699679 -0.189247205
9 0.10828761 -0.189247205
10 0.05548536 0.005013464
...
attr(, "constant"):
[1] 1.209877

> zzz$coef
(Intercept) poly(Age, 2)1 poly(Age, 2)2 s(Start)
1.611475 0.5337308 -0.8190983 -0.03494037

but the data has mean 1.2099 and the prediction terms have mean zero.
You added in the intercept without telling us, I guess. Certainly I do not
get the intercept in any version I have tried.

That Guide is often wrong, including here. You need to add in the
constant attribute.

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news