get_model() extracts the model formula or bracket notation from a single
loglm or glm object.
Arguments
- x
For
get_model(): aloglmorglmobject. Forget_models(): aglmlistorloglmlistobject.- type
Type of output:
"brackets"for loglinear bracket notation (e.g.,"[AB] [C]"), or"formula"for R formula notation. Forglmandglmlistobjects, only"formula"is meaningful.- abbrev
Logical or integer. If
TRUEor a positive integer, abbreviate factor names to that many characters (default 1 whenTRUE). Only applies to bracket notation.- ...
Additional arguments passed to
loglin2stringsuch assepandcollapse.
Details
get_models() does the same for each model in a
loglmlist or glmlist object.
These are useful for labeling models in summaries and plots.
For loglm objects created by seq_loglm, the bracket
notation is stored in the model.string component. For other loglm
objects, it is constructed from the margin component using
loglin2string.
For glm objects, the formula is extracted using formula().
Model notation
For loglmlist objects created by seq_loglm, the bracket
notation distinguishes between models fit to marginal sub-tables and
models fit to the full table. Parentheses are used for marginal
sub-tables, e.g., "(Class) (Sex)", while square brackets are used
for the full table, e.g., "[Class,Sex,Age] [Survived]".
The abbrev argument can be used to abbreviate factor names
for more compact display, e.g., "[C,S,A] [S]".
See also
glmlist, loglmlist,
loglin2string, LRstats,
seq_mosaic
Other glmlist functions:
Kway(),
LRstats(),
glmlist(),
mosaic.glmlist()
Other loglinear models:
assoc_graph(),
glmlist(),
joint(),
plot.assoc_graph(),
seq_loglm()
Examples
data(Titanic)
tit.joint <- seq_loglm(Titanic, type = "joint")
# Single model
get_model(tit.joint[[2]])
#> [1] "(Class) (Sex)"
get_model(tit.joint[[4]])
#> [1] "[Class,Sex,Age] [Survived]"
get_model(tit.joint[[4]], abbrev = TRUE)
#> [1] "[C,S,A] [S]"
get_model(tit.joint[[4]], type = "formula")
#> [1] "~Class:Sex:Age + Survived"
# Model list
get_models(tit.joint)
#> joint.1 joint.2
#> "= Class" "(Class) (Sex)"
#> joint.3 joint.4
#> "(Class,Sex) (Age)" "[Class,Sex,Age] [Survived]"
get_models(tit.joint, type = "formula")
#> joint.1 joint.2
#> "~Class" "~Class + Sex"
#> joint.3 joint.4
#> "~Class:Sex + Age" "~Class:Sex:Age + Survived"
# With abbreviated factor names
get_models(tit.joint, abbrev = TRUE)
#> joint.1 joint.2 joint.3 joint.4
#> "= Class" "(C) (S)" "(C,S) (A)" "[C,S,A] [S]"
get_models(tit.joint, abbrev = 2)
#> joint.1 joint.2 joint.3 joint.4
#> "= Class" "(Cl) (Sx)" "(Cl,Sx) (Ag)" "[Cl,Sx,Ag] [Sr]"
