[R] Noobie question, regression across levels
RichardLang
allen.larocque at gmail.com
Wed Dec 17 04:02:19 CET 2008
Much thanks! This helped a lot. Another quick one:
In using the lmList function in the nlme package, is it possible to subset
my data according to the number of observations in each level? (ie. I
obviously want to include only those levels in which the observations are of
sufficient size for regression). What is the best way to exclude factors of
insufficient size? Can I do it inside the lmList function? I've read the
requisite help files etc. and two hours later am still confused.
Thanks in advance,
Allen
Ben Bolker wrote:
>
>
>
> RichardLang wrote:
>>
>> I've just started using R last week and am still scratching my head.
>>
>> I have a data set and want to run a separate regression across each level
>> of a factor (treating each one separately). The data right now is
>> arranged such that the value of the factor along which I want to "split"
>> my data is one column among many.
>> Best way to do this?
>>
>> Thanks!
>>
>
> You can check out lmList function in the nlme package, or more crudely:
>
> lmfun <- function(d) { lm(y~x,data=d) }
> myLmList <- lapply(split(mydata,splitfactor),lmfun)
>
> even more compactly/confusingly:
>
> myLmList <- lapply(split(mydata,splitfactor),lm,formula=y~x)
>
> good luck
> Ben Bolker
>
>
>
--
View this message in context: http://www.nabble.com/Noobie-question%2C-regression-across-levels-tp21020222p21046298.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list