This function extracts terms from a linear model object and creates a Hasse diagram of the terms. The function is useful for visualizing the structure of a linear model. If the model contains random effects, these are placed in parentheses in the diagram. Manually placed terms are supported to some extent, see example for usage.
manualTerms: A vector of terms that should be placed manually in the diagram.
manualParents: A list of vectors with the parents of the terms in manualTerms.
meanName: The name of the mean term (default = "M").
errorName: The name of the error term (default = "(E)").
Returns
A list with the levels of the diagram and the adjacency matrix.
Author(s)
Kristian Hovde Liland
See Also
lm
Examples
# Random datadat <- data.frame(A = factor(rep(c(1,2),32)), B = factor(rep(c(1,1,2,2),16)), C = factor(rep(c(1,1,1,1,2,2,2,2),8)), Ind = factor(rep(c(1,1,1,1,2,2,2,2),8)), D = factor(rep(c(rep(1,8),rep(2,8)),4)), E = factor(rep(c(rep(1,16),rep(2,16)),2)))dat$y = rnorm(64)# Linear model with interactions and nested factorsmod <- lm(y~A*B*C + D + E%in%D, data=dat)(an <- Anova(mod, type="II"))H <- hasseMod(mod)## Not run:# Requires installation of Rgraphvizlibrary(Rgraphviz)hasse(H$hasse, parameters=list(cluster =FALSE, arrows ="none", edgeColor ="darkred"))## End(Not run)# Linear model with repeated measures where Ind is nested in Amodv <- lm(y~A*r(B)+ r(Ind), data=dat)(anv <- Anova(mod, type="II"))Hv <- hasseMod(modv, manualTerms=c("Ind"), manualParents=list(c("A")))## Not run:# Requires installation og Rgraphvizhasse(Hv$hasse, parameters=list(cluster =FALSE, arrows ="none", edgeColor ="darkred"))## End(Not run)