Re: [R] lmList, tapply() and lm()

From: Jonathan Baron <baron_at_psych.upenn.edu>
Date: Fri, 15 Feb 2008 16:22:43 -0500

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

______________________________________________
R-help_at_r-project.org 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.
Received on Fri 15 Feb 2008 - 21:17:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Feb 2008 - 21:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive