[19158] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Interactions in additive models

daemon@ATHENA.MIT.EDU (Ken Richardson)
Wed Sep 8 23:04:40 1999

Message-Id: <199909090254.OAA01286@storm.niwa.cri.nz>
From: "Ken Richardson" <k.richardson@niwa.cri.nz>
To: s-news@wubios.wustl.edu
Date: Thu, 9 Sep 1999 14:57:49 +12
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7BIT
In-Reply-To: <s7d4dc9b.053@smtp.dnr.state.mn.us>


A further clarification of the method for handling the above, from 
Charles Anderson (see below). 

I've tried the method and it works. Unfortunately, I 
can only fit a few levels of the factor before running out of 
memory, since have a large set of data to deal with. Looks like I'll 
have to use some other approach.

Thanks to Charles for his reply.
_____________________________________________
I think you need to have a group factor in each of the examples to 
get the right answers.  The smoothed terms in GAM are fit with mean 
0, thus the factor is needed to allow separate intercepts.  I th 
grpfact <- factor(grp) gam(y ~ grpfact + lo(t1, u1) + lo(t2, u2) + x, 
na.action=na.gam.replace) 

And the second example:

grpfact <- factor(grp)    # in creating the dataframe
work.gam <- gam(y ~ grpfact + s(G1) + s(G2), data=work,                           
na.action=na.gam.replace)       


Charles Anderson
___________________________________
>>> "Ken Richardson" <k.richardson@niwa.cri.nz> 09/03/99 09:31AM >>>

Last week I asked the question below and got some helpful 
suggestions which are included at the end of the message. Haven't 
had time to try yet, but it looks hopeful. Many thanks to all who 
replied.

> Hello everyone
> 
> I would like to be able to fit separate 2-dimensional smooth 
> surfaces within levels of a factor in a generalised additive model.
> 
> The book Statistical models in S (Chambers & Hastie) notes that S
> did not (at the time of writing) support interactions between smooth
> terms and factors.
> 
> Has this situation changed since that time?
> 
> Ken
> 
____________________________

I don't believe that the situation has changed, at least not in Splus 
3.x (which is what I use).  However, there are a couple of ways of 
getting around the problem --- a bit clumsy, but serviceable. 

First of all, if you don't have any covariates or parameters common to the
different levels of the factor, then you can just fit separate GAMs (one
for each level) and then combine the results at the end.  

More commonly, you will have parameters in common 
(eg.  y ~ s_i (t, u) + x, 
where s_i(t, u) is the smooth surface for level i of the factor, and x is
an extra covariate that is observed across all factor levels).  
In that case, you can insert new variables into the data frame as follows.  

Suppose you have two levels of the factor (i=1, 2), and you want a
separate smooth surface over t and u for each level.  
Put in four new variables:
  1) t1   (t, but replace all entries corresponding to i=2 with NA);
  2) u1   (u, but replace all entries corresponding to i=2 with NA);
  3) t2   (t, but replace all entries corresponding to i=1 with NA);
  4) u2   (u, but replace all entries corresponding to i=1 with NA).

You should then be able to fit 

gam(y ~ lo(t1, u1) + lo(t2, u2) + x, na.action=na.gam.replace) 

Rachel Fewster
____________________________________________________
To my (limited!) knowledge gam() does not produce 'smoothed' interactions,
they are only linear. This topic has been discussed a few weeks ago. 

You have to use the na.replace option:

work.gam <- gam(y ~ grp + s(G1) + s(G2), data=work,                           
na.action=na.gam.replace)       

here, G1 and G2 are two variables in the dataframe, each having only data
for it's own group and NA's for the rest. GRP is the factor that defines
the two groups.

e.g.

GRP   G1   G2
1     245  NA
1     244  NA
1     300  NA
2     NA   155
2     NA   187
2     NA   201


Thanks to Rachel Fewster and Charles Anderson!!


have a look to the internet archive at:
http://lib.stat.cmu.edu/s-news/Burst/10877 

http://wubios.wustl.edu/s-news/s-news-archive/199906/msg00163.html              
http://wubios.wustl.edu/s-news/s-news-archive/199906/msg00177.html 

http://wubios.wustl.edu/s-news/s-news-archive/199805/msg00057.html              
http://wubios.wustl.edu/s-news/s-news-archive/199809/msg00045.html 

Matthias Richard
----------------------------------------


Ken Richardson
National Institute of Water and Atmospheric Research, Greta Point,
PO BOX 14-901, Kilbirnie, Wellington, New Zealand

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

Ken Richardson
National Institute of Water and Atmospheric Research, Greta Point,
PO BOX 14-901, Kilbirnie, Wellington, New Zealand

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

home help back first fref pref prev next nref lref last post