extract_structure {LearnVizLMM}R Documentation

Image of the data structure

Description

extract_structure generates an image of the multilevel data structure. It does this in two steps. First, characteristics of the group(s) or grouping factor(s) are identified via the model input or the n_gf, gf_description, and gf_names inputs. Second, this information is used to run DiagrammeR::grViz(), which returns an image.

Usage

extract_structure(
  model = NULL,
  n_gf = NULL,
  gf_description = NULL,
  gf_names = NULL,
  gf_nlevels = NULL,
  gf3_index = "i",
  label_levels = "yes",
  export_type = "print"
)

Arguments

model

Code for fitting a nlme::lme() or lme4::lmer() model given as a string.

n_gf

Number of groups or grouping factors: 1, 2, or 3. Only applies if model is NULL.

gf_description

Description of the structure of the groups or grouping factors: "nested", "crossed", "crossed with nested", or "crossed within nested". Only applies if n_gf is greater than 1 and model is NULL.

gf_names

Character vector of the names of group(s) or grouping factor(s). For nested, order names by level from highest to lowest. Must be a vector of length equal to n_gf. Only applies if model is NULL.

gf_nlevels

Optional numeric or character vector of the number of levels for each group or grouping factor in the model or gf_names.

gf3_index

String for the index of the highest-level group or grouping factor. Only applies if n_gf is 3. Default is "i".

label_levels

Indicates whether levels of the data structure should be labeled on the left-hand side of the figure (default) or not (label_levels = "no").

export_type

Export type can be "print" (default), "png" to save as a PNG file, or "text" to get the input used to run DiagrammeR::grViz().

Value

A PNG (export_type = "png"), character (export_type = "text"), or object of class htmlwidget that will print in the R console, within R Markdown documents, and within Shiny output bindings (export_type = "print").

Examples

# Using the model input
extract_structure(model = "lme(Score ~ type, random=list(School=pdDiag(~1+type),Class=~1))")
extract_structure(model = "lme(Weight ~ Time, random=~Time|Subject, data)",
                  gf_nlevels = 47)
extract_structure(model = "lmer(Strength ~ 1 + (1|Machine) + (1|Worker))",
                  gf_nlevels = c("23", "J"))

# Using the n_gf, gf_description, and gf_names inputs
extract_structure(n_gf = 1,
                  gf_names = "Subject")
extract_structure(n_gf = 3,
                  gf_description = "nested",
                  gf_names = c("District", "School", "Class"),
                  gf_nlevels = c(8, 15, 5),
                  label_levels = "no")

[Package LearnVizLMM version 1.0.0 Index]