I\'d like to do the following and need some help:
Calculate slope and intercept for \"Height\" over \"Age\" [lm(Height~Age)] separately for
(A) each individ
One way to do regression analysis separately for each level and then combine slopes and intercepts in data frame, is to use function ddply()
from library plyr
.
library(plyr)
ddply(example,"Individual",function(x) coefficients(lm(Height~Age,x)))
Individual (Intercept) Age
1 Jack 26.29188 11.11421
2 Jen 22.10660 11.56345
3 Jill 18.33249 12.04315
4 Tony 33.02030 11.96447
ddply(example,"Gender",function(x) coefficients(lm(Height~Age,x)))
Gender (Intercept) Age
1 F 20.21954 11.80330
2 M 29.65609 11.53934