[R] means over factors in mlm terms

Richard M. Heiberger rmh at temple.edu
Tue Nov 21 18:52:26 CET 2006


## Thank you, Michael, for the example.  I believe you are looking
## for the natural extension to mlm of the proj function.
## Here is the lapply workaround from which that extension
## might be written
##
## Rich

sapply(soils, class)
soils$Group <- factor(soils$Group)
soils$Block <- factor(soils$Block)
sapply(soils, class)

result <- list()
for (i in names(soils)[6:14])
result[[i]] <- aov(soils[[i]] ~ Block + Contour*Depth, data=soils)

proj(result[[1]])

lapply(result, proj)

model.tables(result[[1]], type="means")
lapply(result, model.tables, type="means")

## Exercise for the reader
##  1. defined proj.lm to be proj.aov when it makes sense
##  2. extend the above to the proj.mlm method
##  3. collapse the projections to tables
##     (this is actually how model.tables is written).
##  4. extend model.tables to the lm and mlm when it makes sense.



More information about the R-help mailing list