Skip to content
Prev 165001 / 398503 Next

Noobie question, regression across levels

AllenL wrote:
Don't know if you can do it directly in lmList, but:

splitdat <- split(mydata,splitfactor)
lengths <- sapply(splitdat,nrow)  ## NOT sapply(splitdat,length)
splitdat <- splitdat[lengths>minlength]
lmfun <- function(d) { lm(y~x,data=d) }
myLmList <- lapply(splitdat,lmfun) 

OR

lengths <- sapply(split(mydata,splitfactor),nrow)
badlevels <- levels(splitfactor)[lengths<minlength]
subdata <- subset(mydata,!splitfactor %in% badlevels)

  and then proceed with lmList

  of course, I didn't test any of this ...

 Ben Bolker