[R] Noobie question, regression across levels
Ben Bolker
bolker at ufl.edu
Wed Dec 17 15:32:47 CET 2008
AllenL wrote:
>
> Much thanks! This helped a lot. Another quick one:
> In using the lmList function in the nlme package, is it possible to subset
> my data according to the number of observations in each level? (ie. I
> obviously want to include only those levels in which the observations are
> of sufficient size for regression). What is the best way to exclude
> factors of insufficient size? Can I do it inside the lmList function? I've
> read the requisite help files etc. and two hours later am still confused.
> Thanks in advance,
> Allen
>
>
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
--
View this message in context: http://www.nabble.com/Noobie-question%2C-regression-across-levels-tp21020222p21054226.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list