[R] Sorting data for multiple regressions

Petr PIKAL petr.pikal at precheza.cz
Mon Aug 6 09:25:42 CEST 2007


Hi

r-help-bounces at stat.math.ethz.ch napsal dne 04.08.2007 07:49:16:

> Well, R has a by() function that does what you want, and its help page 
> contains an example of doing regression by group.
> 
> (There are other ways.)

E.g. you can split your data into list

d.s <- split(data, data$site)

and then use lapply to perform your task on all parts of this list
result <- lapply(d.s, function)

Regards
Petr

> 
> On Fri, 3 Aug 2007, Paul Young wrote:
> 
> > So I am trying to perform a robust regression (fastmcd in the robust
> > package) on a dataset and I want to perform individual regressions 
based
> 
> fastmcd does not do regression ... or I would have adapted the ?by 
> example to show you.
> 
> > on the groups within the data.  We have over 300 sites and we want to
> > perform a regression based on the day of week and the hour for every
> > site.  I was wondering if anyone knows of a "'by' command similar to 
the
> > one used in SAS that automatically groups the data for the 
regressions.
> > If not, does anyone have any tips on how to split the data into 
smaller
> > sets and then perform the regression on each set.  I am new to R, so I
> > don't know all of the common work arounds and such.  At the moment the
> > only method I can think of is to split the data using condition
> > statements and manually running the regression on each set.  Thanks or
> > your help
> >
> > -Paul
> 
> 
> -- 
> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list