Skip to content
Back to formatted view

Raw Message

Message-ID: <x28yk2cgc1.fsf@biostat.ku.dk>
Date: 2004-01-21T00:09:50Z
From: Peter Dalgaard
Subject: Combining several regressions
In-Reply-To: <400DBDA7.8050009@auckland.ac.nz>

Hadley Wickham <h.wickham at auckland.ac.nz> writes:

> For example, I want to fit separate loess regressions for each value
> of some conditioning value.  I can do the regressions with
> by(data.frame, conditioning.variable, function(subset) { loess(y ~ x,
> subset) })  but I'm at a loss as how to get the fitted values out and
> match them up with the rows in the original dataset.

> Any suggestions?

[Untested!]

b <- by(data.frame, conditioning.variable, 
        function(subset) { loess(y ~ x, subset) })

unsplit(lapply(b,fitted), conditioning.variable)

You might need to replace the by() by an

  lapply(split(data.frame,cond.var), FUN)

construction, but it doesn't look like it should be necessary.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907