summa: Print Summary Output

View source: R/summa.R

summaR Documentation

Print Summary Output

Description

This function prints a summary of the result object returned by the function "lm" for estimating linear regression models and for the result object returned by the function "lmer" from the lme4 or lmerTest package, or by the function "rlmer" from the robustlmm package to estimate two- or three-level (robust) multilevel and linear mixed-effects models. By default, the function prints the function call, model summary, and the regression coefficient table.

Usage

summa(model, print = c("all", "default", "call", "descript", "cormat", "modsum",
                       "coef", "confint", "stdcoef", "vif"),
      robust = FALSE, ddf = c("Satterthwaite", "Kenward-Roger", "lme4"),
      conf.level = 0.95, method = c("profile", "wald", "boot"), R = 1000,
      boot = c("perc", "basic", "norm"), seed = NULL, digits = 2, p.digits = 3,
      write = NULL, append = TRUE, check = TRUE, output = TRUE)

Arguments

model

a fitted model of class "lm", "lmerMod", "rlmerMod", or "lmerModLmerTest"

print

a character vector indicating which results to print, i.e. "all", for all results, "call" for the function call, "descript" for descriptive statistics, cormat for the Pearson product-moment correlation matrix for models estimated by "lm" (see cor.matrix function) or within- and between-group correlation matrix for models estimated by "lmer" (see multilevel.cor function), modsum for the multiple correlation, r-squared, and F-test for models estimated by "lm" or model summary, marginal, and conditional R-squared for models estimated by "lmer" (see multilevel.r2 function), coef for the unstandardized coefficients for models estimated by "lm" or random effects and fixed effects for models estimated by "lmer", confint for the confidence interval for unstandardized coefficients, stdcoef for the standardized coefficients (see coeff.std function), and vif for the variance inflation factor (see check.collin function). The default setting is print = c("call", "modsum", "coef"). Note that when a fitted model of class "rlmerMod" is specified for the argument model, the argument print is always c("call", "coef"), i.e., "descript", "cormat", "modsum", "confint", "stdcoef", and "vif" are not available for an "rlmerMod" object.

robust

logical: if TRUE, heteroscedasticity-consistent standard errors, confidence intervals, and heteroscedasticity-robust F-test using the HC4 estimator are computed for linear models estimated by using the lm() function or cluster-robust standard errors using the CR2 estimator is computed for multilevel and linear mixed-effects models estimated by using the lmer() function (see coeff.robust function).

ddf

a character string for specifying the method for computing the degrees of freedom when using the lmerTest package to obtain p-values for fixed effects in multilevel and linear mixed-effects models, i.e., "Satterthwaite" (default) for Satterthwaite's method, "Kenward-Roger" for the Kenward-Roger's method, and "lme4" for the lme4-summary without degrees of freedom and significance values (see Kuznetsova et al., 2017). Note that when a fitted model of class "rlmerMod" is specified for the argument model, Satterthwaite or Kenward-Roger degrees of freedom are computed only if the R package lmerTest is loaded.

conf.level

a numeric value between 0 and 1 indicating the confidence level of the interval.

method

a character string for specifying the method for computing confidence intervals (CI), i.e., "profile" (default) for computing a likelihood profile and finding the appropriate cutoffs based on the likelihood ratio test, "Wald" for approximating the CIs based on the estimated local curvature of the likelihood surface, and "boot" for performing bootstrapping with CIs computed from the bootstrap distribution according to the argument boot.

R

a numeric value indicating the number of bootstrap replicates (default is 1000).

boot

a character string for specifying the type of bootstrap confidence intervals (CI), i.e., i.e., "perc" (default), for the percentile bootstrap CI, "basic" for the basic bootstrap CI, and "norm" for the normal approximation bootstrap CI.

seed

a numeric value specifying seeds of the pseudo-random numbers used in the bootstrap algorithm when conducting bootstrapping.

digits

an integer value indicating the number of decimal places to be used.

p.digits

an integer value indicating the number of decimal places to be used for displaying multiple R, R-squared and p-value.

write

a character string naming a file for writing the output into either a text file with file extension ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console.

Details

Robust Estimation of Multilevel and Linear Mixed-Effects Models

The function rlmer from the robustlmm package does not provide any degrees of freedom or significance values. This function re-estimates the model without using robust estimation to obtain the Satterthwaite or Kenward-Roger degrees of freedom depending on the argument ddf before computing significance values for the regression coefficients based on parameter estimates and standard error of the robust multilevel mixed-effects (see Sleegers et al. (2021).

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

model

model specified in model

args

specification of function arguments

result

list with results, i.e., call for the the function call, descript for descriptive statistics, cormat for the correlation matrix, modsum for the model summary, randeff for the variance and correlation components,coef for the model coefficients, weights for the robustness weights and converg for the convergence check, i.e., 1 = model converged, 0 = model singular, and -1 model not converged.

Author(s)

Takuya Yanagida

References

Kuznetsova, A, Brockhoff, P. B., & Christensen, R. H. B. (2017). lmerTest Package: Tests in linear mixed effects models. Journal of Statistical Software, 82 13, 1-26. https://doi.org/10.18637/jss.v082.i13

Sleegers, W. W. A., Proulx, T., & van Beest, I. (2021). Pupillometry and hindsight bias: Physiological arousal predicts compensatory behavior. Social Psychological and Personality Science, 12(7), 1146–1154. https://doi.org/10.1177/1948550620966153

See Also

descript, cor.matrix, coeff.std, coeff.robust, check.collin

Examples

#----------------------------------------------------------------------------
# Linear Model

# Estimate linear model
mod.lm <- lm(mpg ~ cyl + disp, data = mtcars)

# Example 1a: Default setting
summa(mod.lm)

# Example 1b: Heteroscedasticity-consistent standard errors
summa(mod.lm, robust = TRUE)

# Example 1c: Print all available results
summa(mod.lm, print = "all")

# Example 1d: Print default results plus standardized coefficient
summa(mod.lm, print = c("default", "stdcoef"))

## Not run: 
#----------------------------------------------------------------------------
# Multilevel and Linear Mixed-Effects Model

# Load lme4 and misty package
misty::libraries(lme4, misty)

# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")

#------------------
## Two-Level Data

# Cluster-mean centering, center() from the misty package
Demo.twolevel <- center(Demo.twolevel, x2, type = "CWC", cluster = "cluster")

# Grand-mean centering, center() from the misty package
Demo.twolevel <- center(Demo.twolevel, w1, type = "CGM", cluster = "cluster")

# Estimate two-level mixed-effects model
mod.lmer2 <- lmer(y1 ~ x2.c + w1.c + x2.c:w1.c + (1 + x2.c | cluster),
                  data = Demo.twolevel)

# Example 2a: Default setting
summa(mod.lmer2)

# Example 2b: Print all available results
summa(mod.lmer2, print = "all")

# Example 2c: Print default results plus standardized coefficient
summa(mod.lmer2, print = c("default", "stdcoef"))

# Load lmerTest package
library(lmerTest)

# Re-estimate two-level model using the lme4 and lmerTest package
mod.lmer2 <- lmer(y1 ~ x2.c + w1.c + x2.c:w1.c + (1 + x2.c | cluster), data = Demo.twolevel)

# Example 2d: Default setting, Satterthwaite's method
summa(mod.lmer2)

# Example 2e: Kenward-Roger's method
summa(mod.lmer2, ddf = "Kenward-Roger")

# Example 2f: Cluster-robust standard errors
summa(mod.lmer2, robust = TRUE)

#------------------
## Robust Estimation using the R package robustlmm

# Estimate two-level mixed-effects model
mod.lmer2r <- robustlmm::rlmer(y1 ~ x2.c + w1.c + x2.c:w1.c + (1 + x2.c | cluster),
                               data = Demo.twolevel)

# Example 2f: Default setting
summa(mod.lmer2r)

#------------------
## Three-Level Data

# Create arbitrary three-level data
Demo.threelevel <- data.frame(Demo.twolevel, cluster2 = Demo.twolevel$cluster,
                                             cluster3 = rep(1:10, each = 250))

# Cluster-mean centering, center() from the misty package
Demo.threelevel <- center(Demo.threelevel, x1, type = "CWC", cluster = c("cluster3", "cluster2"))

# Cluster-mean centering, center() from the misty package
Demo.threelevel <- center(Demo.threelevel, w1, type = "CWC", cluster = c("cluster3", "cluster2"))

# Estimate three-level model using the lme4 package
mod.lmer3 <- lmer(y1 ~ x1.c + w1.c + (1 | cluster3/cluster2), data = Demo.threelevel)

# Example 3a: Default setting
summa(mod.lmer3)

# Example 3b: Print all available results
summa(mod.lmer3, print = "all")

#------------------
## Robust Estimation using the R package robustlmm

# Estimate three-level model using the lme4 package
mod.lmer3r <- robustlmm::rlmer(y1 ~ x1.c + w1.c + (1 | cluster3/cluster2),
                               data = Demo.threelevel)

# Example 3c: Default setting
summa(mod.lmer3r)

#----------------------------------------------------------------------------
# Write Results

# Example 4a: Write Results into a text file
summa(mod.lm, print = "all", write = "Linear_Model.txt")

# Example 4b: Write Results into a Excel file
summa(mod.lm, print = "all", write = "Linear_Model.xlsx")

## End(Not run)

misty documentation built on Sept. 9, 2025, 5:23 p.m.

Related to summa in misty...