[R] lmList, tapply() and lm()
Jonathan Baron
baron at psych.upenn.edu
Fri Feb 15 22:22:43 CET 2008
Here is an example I just did. I _LOVE_ lmList(). It is such a great
convenience compared to the following. But right now it doesn't work
for "family=binomial", so I had to do it differently. This is not
your example, but it should give you an idea. The [[5]] was because I
was interested only in the 5th coefficient for each subject (the
interaction term). Note that I used coef() because I was interested
only in the coefficients.
l1g <- by(d1,subject,function(x)
coef(glm(achoice ~ lnlra*session+lnpodd,data=x,family=binomial))[[5]])
On 02/15/08 11:00, Marc Belisle wrote:
> Howdee,
>
> *** I know that the lmList() function exists, yet I don't want to use it.
> ***
>
> Would anyone be kind enough to tell how I can apply the function lm() to
> each level of a given factor so to obtain the intercept and slope for each
> factor level within a matrix?
>
> For instance, suppose a dataframe containing 3 variables: id, x and y.
>
> I want to compute the function lm() for each level contained in id, as
> lmList would do...
>
> Thanks for your time,
--
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron
More information about the R-help
mailing list