Builds a compact table of the estimates of a model fitted with
defm_mle(). Instead of listing the terms one after the other, the
table has two sections:
summary_table(
object,
as_texreg = FALSE,
labels = NULL,
omit = NULL,
digits = 3L,
se = c("below", "side"),
stars = c(0.001, 0.01, 0.05),
model = NULL,
...
)
# S3 method for class 'defm_summary_table'
format(x, type = c("text", "html", "markdown"), ...)
# S3 method for class 'defm_summary_table'
print(x, ...)
# S3 method for class 'defm_summary_table'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)An object returned by defm_mle().
When TRUE, returns a texreg object with all the terms
listed one by one (see texreg_fancy()). All other formatting arguments
are ignored.
Named character vector (or list) to rename the elements of
the table, e.g., c(y0 = "Smoking", x1 = "Female"). Names can be
outcome names, covariate names, "(Intercept)", "Main", or the name of
a term without the covariate interaction (e.g., "Num. of ones").
Outcome names are also replaced within motifs.
Regular expression. Terms whose (original) name matches it are excluded from the table.
Integer. Number of decimals for the estimates and standard errors.
Either "below" (standard errors in a separate row under the
estimate) or "side" (standard errors next to the estimate).
Numeric vector of p-value thresholds for the significance
stars. The smallest value gets the most stars. NULL omits the stars.
Optional DEFM object used to fit the model. Used to retrieve the names of the outcomes and covariates. Only needed for fits that do not store them (see details).
Ignored.
An object of class defm_summary_table.
Character. Either "text", "html", or "markdown".
Ignored.
summary_table() returns an object of class defm_summary_table, a
list with the elements sections (for each section, matrices with the
estimates est, standard errors se, p-values p, and the original
term names term), coefs (the full table of coefficients), gof
(goodness-of-fit statistics), and settings. If as_texreg = TRUE,
a texreg object.
format() returns a character vector with the lines of the table.
as.data.frame() returns a data frame with the columns coef, se,
and pvalues, one row per term (the format returned by
summary_table() in earlier versions of the package).
Outcome-specific (logit) terms: a matrix with one column per
outcome and one row per covariate interaction ((Intercept) for the
main logit term). Cells are empty when the model does not include
that combination.
Joint and transition (Markov) terms: one row per motif
(co-occurrence, e.g., {y0, y1}, and transitions, e.g.,
{y0} > {y0, y1}) and one column per interaction (Main for the
term without interaction). Other terms, e.g., td_ones(), are also
reported here.
Motifs are written using the td_formula() notation: a leading 0
marks an outcome equal to zero.
The table is printed to the console as plain text. Use format() with
type = "html" or type = "markdown" to get the table as HTML or as a
Markdown pipe table. Within Quarto and R Markdown documents, the table
is rendered automatically (HTML for HTML output and Markdown otherwise).
The terms are classified by their names. Fits returned by defm_mle()
store the outcome and covariate names, which makes the classification
exact. For other mle objects, the names are taken from model or, if
possible, from the model object used in the fit.
data(valentesnsList)
mymodel <- new_defm(
id = valentesnsList$id,
Y = valentesnsList$Y,
X = valentesnsList$X,
order = 0
)
td_logit_intercept(mymodel)
td_logit_intercept(mymodel, covar = "Hispanic")
td_formula(mymodel, "{y0, y1}")
init_defm(mymodel)
ans <- defm_mle(mymodel)
summary_table(ans)
#> ====================================================================
#> Outcome-specific (logit) terms
#> --------------------------------------------------------------------
#> alcohol tobacco mj
#> --------------------------------------------------------------------
#> (Intercept) -1.753*** -3.722*** -3.396***
#> (0.115) (0.233) (0.233)
#> Hispanic 1.496*** 0.347 1.944***
#> (0.130) (0.233) (0.245)
#> ====================================================================
#> Joint and transition (Markov) terms
#> --------------------------------------------------------------------
#> Main
#> --------------------------------------------------------------------
#> {alcohol, tobacco} 2.047***
#> (0.215)
#> ====================================================================
#> N = 1730; AIC = 4343.791; BIC = 4381.983; Log-likelihood = -2164.896
#> *** p < 0.001; ** p < 0.01; * p < 0.05
# Renaming, standard errors to the side, and two decimals
summary_table(
ans,
labels = c(mj = "Marijuana", Hispanic = "Hispanic (yes)"),
se = "side",
digits = 2
)
#> =====================================================================
#> Outcome-specific (logit) terms
#> ---------------------------------------------------------------------
#> alcohol tobacco Marijuana
#> ---------------------------------------------------------------------
#> (Intercept) -1.75*** (0.12) -3.72*** (0.23) -3.40*** (0.23)
#> Hispanic (yes) 1.50*** (0.13) 0.35 (0.23) 1.94*** (0.25)
#> =====================================================================
#> Joint and transition (Markov) terms
#> ---------------------------------------------------------------------
#> Main
#> ---------------------------------------------------------------------
#> {alcohol, tobacco} 2.05*** (0.21)
#> =====================================================================
#> N = 1730; AIC = 4343.79; BIC = 4381.98; Log-likelihood = -2164.90
#> *** p < 0.001; ** p < 0.01; * p < 0.05
# HTML and Markdown versions
format(summary_table(ans), type = "html")
#> [1] "<table class=\"defm-summary-table\" style=\"margin: 10px auto; border-collapse: collapse; border-spacing: 0px; border-top: 2px solid #000000; border-bottom: 2px solid #000000;\">"
#> [2] "<tr><th colspan=\"4\" style=\"padding: 6px 8px 2px 8px; text-align: left; font-style: italic;\">Outcome-specific (logit) terms</th></tr>"
#> [3] "<tr style=\"border-bottom: 1px solid #000000;\"><th style=\"padding: 2px 8px;\"></th><th style=\"padding: 2px 8px; text-align: center;\">alcohol</th><th style=\"padding: 2px 8px; text-align: center;\">tobacco</th><th style=\"padding: 2px 8px; text-align: center;\">mj</th></tr>"
#> [4] "<tr><td style=\"padding: 2px 8px; text-align: left;\">(Intercept)</td><td style=\"padding: 2px 8px; text-align: center;\">-1.753***</td><td style=\"padding: 2px 8px; text-align: center;\">-3.722***</td><td style=\"padding: 2px 8px; text-align: center;\">-3.396***</td></tr>"
#> [5] "<tr><td style=\"padding: 2px 8px; text-align: left;\"></td><td style=\"padding: 2px 8px; text-align: center;\">(0.115)</td><td style=\"padding: 2px 8px; text-align: center;\">(0.233)</td><td style=\"padding: 2px 8px; text-align: center;\">(0.233)</td></tr>"
#> [6] "<tr><td style=\"padding: 2px 8px; text-align: left;\">Hispanic</td><td style=\"padding: 2px 8px; text-align: center;\">1.496***</td><td style=\"padding: 2px 8px; text-align: center;\">0.347</td><td style=\"padding: 2px 8px; text-align: center;\">1.944***</td></tr>"
#> [7] "<tr><td style=\"padding: 2px 8px; text-align: left;\"></td><td style=\"padding: 2px 8px; text-align: center;\">(0.130)</td><td style=\"padding: 2px 8px; text-align: center;\">(0.233)</td><td style=\"padding: 2px 8px; text-align: center;\">(0.245)</td></tr>"
#> [8] "<tr><th colspan=\"4\" style=\"padding: 6px 8px 2px 8px; text-align: left; font-style: italic;\">Joint and transition (Markov) terms</th></tr>"
#> [9] "<tr style=\"border-bottom: 1px solid #000000;\"><th style=\"padding: 2px 8px;\"></th><th style=\"padding: 2px 8px; text-align: center;\">Main</th><td></td><td></td></tr>"
#> [10] "<tr><td style=\"padding: 2px 8px; text-align: left;\">{alcohol, tobacco}</td><td style=\"padding: 2px 8px; text-align: center;\">2.047***</td><td></td><td></td></tr>"
#> [11] "<tr><td style=\"padding: 2px 8px; text-align: left;\"></td><td style=\"padding: 2px 8px; text-align: center;\">(0.215)</td><td></td><td></td></tr>"
#> [12] "<tr><td colspan=\"4\" style=\"padding: 4px 8px; border-top: 1px solid #000000; font-size: 0.8em;\">N = 1730; AIC = 4343.791; BIC = 4381.983; Log-likelihood = -2164.896<br>*** p < 0.001; ** p < 0.01; * p < 0.05</td></tr>"
#> [13] "</table>"
format(summary_table(ans), type = "markdown")
#> [1] "**Outcome-specific (logit) terms**"
#> [2] ""
#> [3] "| | alcohol | tobacco | mj |"
#> [4] "|:---|---:|---:|---:|"
#> [5] "| (Intercept) | -1.753\\*\\*\\* | -3.722\\*\\*\\* | -3.396\\*\\*\\* |"
#> [6] "| | (0.115) | (0.233) | (0.233) |"
#> [7] "| Hispanic | 1.496\\*\\*\\* | 0.347 | 1.944\\*\\*\\* |"
#> [8] "| | (0.130) | (0.233) | (0.245) |"
#> [9] ""
#> [10] "**Joint and transition (Markov) terms**"
#> [11] ""
#> [12] "| | Main |"
#> [13] "|:---|---:|"
#> [14] "| {alcohol, tobacco} | 2.047\\*\\*\\* |"
#> [15] "| | (0.215) |"
#> [16] ""
#> [17] "N = 1730; AIC = 4343.791; BIC = 4381.983; Log-likelihood = -2164.896 "
#> [18] "\\*\\*\\* p < 0.001; \\*\\* p < 0.01; \\* p < 0.05 "
# The terms one by one
as.data.frame(summary_table(ans))
#> coef se pvalues
#> Logit intercept alcohol -1.7533421 0.1154825 4.600665e-52
#> Logit intercept tobacco -3.7215958 0.2333810 3.016049e-57
#> Logit intercept mj -3.3960550 0.2332426 5.032150e-48
#> Logit intercept alcohol x Hispanic 1.4958678 0.1296152 8.212470e-31
#> Logit intercept tobacco x Hispanic 0.3470626 0.2327840 1.359822e-01
#> Logit intercept mj x Hispanic 1.9438911 0.2451316 2.191660e-15
#> Motif {alcohol+, tobacco+} 2.0470897 0.2148468 1.601293e-21