Skip to content
Prev 165045 / 398503 Next

Noobie question, regression across levels

This is what I ended up using:

Data.subset<-data.frame(PlotFinal,YearFinal,BioFinal,ritFinal)     ###Subset
of main dataset
Data.length<-sapply(split(Data.subset,PlotFinal),nrow)       ### The number
of data points in each plot 

Data.sub<-split(Data.subset,PlotFinal)         ##Split Data.subset by
PlotFinal
Good.levels<-Data.sub[Data.length>10]       ##Take only those Plots that
have >10 years of observation

lmfun<-function(Good.levels)
{lm(ritFinal~BioFinal+YearFinal,data=Good.levels)}   ##Set up the 
###regression function
lmList<-lapply(Good.levels,lmfun)                       ###Apply above
function to all "good levels"

coef.List<-lapply(lmList,coef)          ###List of the coefficients of EACH
above regression

This seems to have worked beautifully.
So, my current problem is extracting the coefficients from "coef.List" (and
I think this is getting to the roof of my general confusion). coef.List
seems to be a list of a list of lm objects, right? How come them I cannot
call them by their position directly (ie. coef.List[1] gives me the first lm
object. I cannot seem to call the first coefficient in this object (the
intercept).) 
My goal is to have a bunch of new lists, each one listing a subset of
coefficients from each regression (ie. one will be a list of all the
intercepts, another the mean of all the "YearFinal" effects, etc).

Thanks again in advance for help with all these noobie questions!
Ben Bolker wrote: