Learn R Programming

mixlm (version 1.4.0)

hasseMod: Hasse Diagram from Linear Model

Description

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.

Usage

hasseMod(object, manualTerms=NULL, manualParents=NULL, 
         meanName="M", errorName="(E)")

Value

A list with the levels of the diagram and the adjacency matrix.

Arguments

object

A linear model object, e.g., lm.

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)").

Author

Kristian Hovde Liland

See Also

Examples

Run this code
# Random data
dat <- 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 factors
mod <- lm(y~A*B*C + D + E%in%D, data=dat)
(an <- Anova(mod, type="II"))
H <- hasseMod(mod)
if (FALSE)  # Requires installation of Rgraphviz
library(Rgraphviz)
hasse(H$hasse, parameters=list(cluster = FALSE, arrows = "none", edgeColor = "darkred"))


# Linear model with repeated measures where Ind is nested in A
modv <- lm(y~A*r(B) + r(Ind), data=dat)
(anv <- Anova(mod, type="II"))
Hv <- hasseMod(modv, manualTerms=c("Ind"), manualParents=list(c("A")))
if (FALSE)  # Requires installation og Rgraphviz
hasse(Hv$hasse, parameters=list(cluster = FALSE, arrows = "none", edgeColor = "darkred"))

Run the code above in your browser using DataLab