Dear Jeff, One way to do this is with by():
summaries <- by(example, Individual, function(data){ mod <- glm(Type~Dwater+Habitat, data=data, family=binomial) list(AIC=AIC(mod), coef=coef(mod)) }) sapply(summaries, function(x) x$coef) rowMeans(sapply(summaries, function(x) x$coef)) sapply(summaries, function(x) x$AIC) I hope this helps, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox -------------------------------- > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Row > Sent: Monday, October 31, 2005 12:01 PM > To: r-help@stat.math.ethz.ch > Subject: [R] GLM > > Hello R-users, > > I am a relatively new user of R and I have a question > regarding glm. I want to run the function GLM on multiple > individuals separately and then get means for summary > statistics such as AIC and coef. Is there a way to do this in > R without separately going through each individual and > subsetting the dataset, getting the summary statistics and > averaging them? For example, in the dataset below I would > like to run the function: > > >glm(Type~Dwater+Habitat, data=example, family=binomial()) > > on each individual separately and then get the average for > the coef's Dwater and Habitat for the 3 individuals. > > >example > Individual Type Dwater Habitat > 1 1 0 40 0 > 2 1 1 80 1 > 3 1 0 30 0 > 4 1 1 90 0 > 5 2 0 15 1 > 6 2 1 95 1 > 7 2 0 20 0 > 8 2 1 75 1 > 9 3 0 15 0 > 10 3 1 60 1 > 11 3 0 10 1 > 12 3 1 95 0 > > Thanks, > > Jeff. > > ______________________________________________ > R-help@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 ______________________________________________ R-help@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