semTable: Creates Structural Equation Modeling Tables

Description Usage Arguments Details Value Author(s) Examples

View source: R/semTable.R

Description

Creates LaTeX markup for structural equation modeling output tables in the style of the American Psychological Association(APA). Input objects should be created by the "lavaan" package.

Usage

1
2
3
4
5
6
7
semTable(object, file = NULL, paramSets = "all", paramSetLabels,
  columns = c(est = "Estimate", se = "SE", z = "z", p = "p"),
  columnLabels, fits = c("chisq", "cfi", "tli", "rmsea"),
  fitLabels = toupper(fits), varLabels = NULL, groups = NULL,
  type = "latex", table.float = FALSE, caption = NULL,
  label = NULL, longtable = FALSE, print.results = TRUE,
  centering = "siunitx", alpha = c(0.05, 0.01, 0.001))

Arguments

object

A lavaan object (e.g., returned by cfa() or sem()), or a named list of lavaan objects, e.g., list("Model A" = obj1, "Model B" = obj2). Results will be displayed side by side.

file

Base name for output file. This function will insert suffix, either "tex", "html" and "csv".

paramSets

Parameter sets to be included for each fitted object. Valid values of the vector are "all" or a any of the following: c("composites", "loadings", "slopes", "intercepts", "residualvariances", "residualcovariances", "latentmeans", "latentvariances", "latentcovariances", "thresholds", "constructed", "fits"). Default is "all", any of the estimates present in the fitted model that are listed in the previous sentence will be included in the output. For the sake of simplicity, we now allow one vector here, which applies to all models in the object list.

paramSetLabels

Named vector, used to supply alternative pretty printing labels for parameter sets. The default values are c("composites" = "Composites", "loadings"= "Factor Loadings", "slopes" = "Regression Slopes", "intercepts" = "Intercepts", "means"= "Means", "residualvariances" = "Residual Variances", "residualcovariances" = "Residual Covariances", "variances" = "Variances", "latentvariances" = "Latent Variances", "latentcovariances" = "Latent Covariances", "latentmeans" = "Latent Intercepts", "thresholds" = "Thresholds", "constructed" = "Constructed", "fits" = "Fit Indices"). The paramSetLabels argument must be a named vector that overrides some or all of the default names.

columns

A vector naming estimates to appear for each model. The allowed columns are "est", "se", "z", "p", "rsquare", "estse", "eststars", "estsestars". The first 5 have the usual meanings, while "estse" (can also be written "est(se)") displays as, for example "1.21(0.23)", and the last 2 are to include "significance stars". "eststars" shows as "1.21***" and "estsestars" (or "est(se)stars") displays as "1.21(0.23)**". See parameter alpha. One may request different columns for each model by providing a named list of vectors. Use model names in the list, list("Model A" = c("est", "se"), "Model B" = c("estse", "p")).

columnLabels

A named vector of "pretty labels" for the headings in the table. The default labels are c("est" = "Estimate", se = "Std. Err.", z = "z", p = "p", rsquare = "R Square", estse = "Estimate(Std.Err."), eststars = "Estimate", estsestars = "Estimate(Std.Err.)").

fits

Summary indicators to be included. May be a list, one for each model provided, otherwise the same fit indicators will be presented for each model. Any of the fit indicators provided by lavaan::fitMeasures(object) are allowed: c("npar", "fmin", "chisq", "df", "pvalue", "baseline.chisq", "baseline.df", "baseline.pvalue", "cfi", "tli", "nnfi", "rfi", "nfi", "pnfi", "ifi", "rni", "logl", "unrestricted.logl", "aic", "bic", "ntotal", "bic2", "rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "rmsea.pvalue", "rmr", "rmr_nomean", "srmr", "srmr_bentler", "srmr_bentler_nomean", "srmr_bollen", "srmr_bollen_nomean", "srmr_mplus", "srmr_mplus_nomean", "cn_05", "cn_01", "gfi", "agfi", "pgfi", "mfi", "ecvi"). The return for "chisq" will include markup for degrees of freedom and p value. If user specifies NULL, or if "fits" is excluded from paramSets, all fit indicators are omitted.

fitLabels

Labels for some or all of the fit measures requested by the fits parameter, e.g. c(rmsea = "Root Mean Square Error of Approximation", cli = "CLI"). The default labels are the upper-case fits names (except for "chisq", where a Greek letter is supplied when possible).

varLabels

Named vector of labels to replace variable names in column 1 of SEM table.

groups

All groups will be printed, unless a subset is requested here. Estimates for all groups will be displayed side by side. If ONLY SOME groups should be included, then specify groups as either names of fit objects or as integers for elements of the groups vector.

type

Choose "latex", "html", or "csv"

table.float

If TRUE, create a LaTeX floating table object in which the tabular created here will reside. Default is FALSE.

caption

Caption for table (if table.float=TRUE) or longtable output. Ignored otherwise.

label

LaTeX label for this object (for cross-references). Only used if table.float = TRUE or longtable = TRUE.

longtable

If TRUE, use longtable for LaTeX documents. Default is FALSE. If true, table.float argument is ignored.

print.results

If TRUE, marked up result will be displayed within the session. Otherwise, result is returned silently and user can use cat to dislay it. Don't use print because it inserts unwanted decorations.

centering

Default "siunitx". For method used in previous editions, replace with "none".

alpha

Thresholds for p-values that determine number of stars. Defaults as c(0.05, 0.01, 0.001) for c("*", "**", "***").

Details

The argument paramSets determines the inclusion of estimate sections. One can specify "all", which means that all types of parameters that we can find in the fitted model are presented. Otherwise, a subset of parameter sets can be chosen by the user.

The columns parameter is used to specify different columns, while columnLabels will alter the displayed labels for them.

Value

Markup for SEM table. Includes an attribute "markedResults", which can be converted to other markup formats by the function markupConvert.

Author(s)

Ben Kite <bakite@ku.edu> Paul Johnson <pauljohn@ku.edu>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Most of the examples were moved to the semTable vignette
require(lavaan)

tempdir <- tempdir()
## The example from lavaan's docs
 HS.model <- ' visual  =~ x1 + x2 + x3
               textual =~ x4 + x5 + x6
               speed   =~ x7 + x8 + x9'
 fit1 <- cfa(HS.model, data = HolzingerSwineford1939,
             std.lv = TRUE, meanstructure = TRUE)
 ## Try a LaTeX file first
 fit1.t1 <- semTable(fit1, columns = c("estse", "p"),
                     fits = c("chisq", "rmsea"), file = file.path(tempdir, "fit1.t1"),
                     varLabels = c("x1" = "hello"), type = "latex", print.results = FALSE)
 ## If you have a working version of pdflatex in your system path, 
 if (interactive()) testtable("fit1.t1.tex", tempdir)
 
 model <- "factor =~ .7*y1 + .7*y2 + .7*y3 + .7*y4
                  y1 | -1*t1 + 1*t2
                  y2 | -.5*t1 + 1*t2
                  y3 | -.2*t1 + 1*t2
                  y4 | -1*t1 + 1*t2"
 dat <- simulateData(model, sample.nobs = 300)
 
 testmodel <- "ExampleFactor =~ y1 + y2 + y3 + y4"
 
 fit4 <- cfa(testmodel, data = dat, ordered = colnames(dat),
             std.lv = FALSE)
 
 fit4.t1 <- semTable(fit4, paramSets = c("loadings", "thresholds",
     "residualvariances"), fits = c("tli", "chisq"),
     fitLabels = c(tli = "TLI", chisq = "chisq"), type = "html",
     file=file.path(tempdir, "fit4.t1") )
 if(interactive()) browseURL(attr(fit4.t1, "file"))
 fit4.t2 <- semTable(fit4, fits = c("rmsea", "cfi", "chisq"),
               fitLabels = c(rmsea = "Root M.SQ.E.A", cfi = "CompFitIdx", chisq = "chisq"),
               type = "latex", file=file.path(tempdir, "fit4.t2"))
 if (interactive()) testtable("fit4.t2.tex", tempdir)

Example output

Loading required package: lavaan
This is lavaan 0.6-7
lavaan is BETA software! Please report any bugs.

<table style="padding-right:20px;padding-left:20px;">
<tr><td></td><td colspan = '4'; align = 'center'>Model</td></tr> 
<tr><td></td><td colspan = '1'; align = 'center'>Estimate</td><td colspan = '1'; align = 'center'>Std. Err.</td><td colspan = '1'; align = 'center'>z</td><td colspan = '1'; align = 'center'>p</td></tr>
<tr><td></td><td colspan = '4'; align = 'center'><span style="text-decoration: underline;">Factor Loadings</span></td></tr> <tr><td colspan = '1'; align = 'left'><span style="text-decoration: underline;">ExampleFactor</span></td></tr>
<tr><td>y1</td><td>1.00<sup>+</sup></td><td></td><td></td><td></td></tr>
<tr><td>y2</td><td>0.83</td><td>0.12</td><td>6.96</td><td>.000</td></tr>
<tr><td>y3</td><td>1.02</td><td>0.11</td><td>9.53</td><td>.000</td></tr>
<tr><td>y4</td><td>1.00</td><td>0.12</td><td>8.58</td><td>.000</td></tr>
<tr><td></td><td colspan = '4'; align = 'center'><span style="text-decoration: underline;">Residual Variances</span></td></tr>
<tr><td>y1</td><td>0.50<sup>+</sup></td><td></td><td></td><td></td></tr>
<tr><td>y2</td><td>0.66<sup>+</sup></td><td></td><td></td><td></td></tr>
<tr><td>y3</td><td>0.48<sup>+</sup></td><td></td><td></td><td></td></tr>
<tr><td>y4</td><td>0.50<sup>+</sup></td><td></td><td></td><td></td></tr>
<tr><td></td><td colspan = '4'; align = 'center'><span style="text-decoration: underline;">Thresholds</span></td></tr>
<tr><td>y1(1)</td><td>-0.94</td><td>0.09</td><td>-11.01</td><td>.000</td></tr>
<tr><td>y1(2)</td><td>1.04</td><td>0.09</td><td>11.70</td><td>.000</td></tr>
<tr><td>y2(1)</td><td>-0.51</td><td>0.08</td><td>-6.77</td><td>.000</td></tr>
<tr><td>y2(2)</td><td>1.04</td><td>0.09</td><td>11.70</td><td>.000</td></tr>
<tr><td>y3(1)</td><td>-0.25</td><td>0.07</td><td>-3.45</td><td>.001</td></tr>
<tr><td>y3(2)</td><td>1.05</td><td>0.09</td><td>11.80</td><td>.000</td></tr>
<tr><td>y4(1)</td><td>-0.99</td><td>0.09</td><td>-11.41</td><td>.000</td></tr>
<tr><td>y4(2)</td><td>1.07</td><td>0.09</td><td>11.89</td><td>.000</td></tr>
<tr><td></td><td colspan = '4'; align = 'center'><span style="text-decoration: underline;">Fit Indices</span></td></tr>
<tr><td>TLI</td><td>1.02</td><td></td><td></td><td></td></tr>
<tr><td>chisq</td><td>0.03</td><td></td><td></td><td></td></tr>
<tr><td>Scaled &chi;<sup>2</sup></td><td>0.07(2)</td><td></td><td></td><td>.966</td></tr>
<tr><td colspan = '5'; align = 'left'><sup>+</sup>Fixed parameter</td></tr>
</table><br>
 
\begin{tabular}{@{}r*{4}{S[
                         input-symbols = ( ) +,
                         group-digits = false,
                         table-number-alignment = center,
                         %table-space-text-pre = (,
                         table-align-text-pre = false,
                         table-align-text-post = false,
                         table-space-text-post = {***},
                         parse-units = false]}@{}}
& \multicolumn{4}{c}{Model}\tabularnewline \hline
& \multicolumn{1}{c}{Estimate}& \multicolumn{1}{c}{Std. Err.}& \multicolumn{1}{c}{z}& \multicolumn{1}{c}{p}\tabularnewline\hline
& \multicolumn{4}{c}{\underline{Factor Loadings}}\tabularnewline \multicolumn{1}{l}{\underline{ExampleFactor}}\tabularnewline
y1& 1.00$^+$& & & \tabularnewline
y2& 0.83& 0.12& 6.96& .000\tabularnewline
y3& 1.02& 0.11& 9.53& .000\tabularnewline
y4& 1.00& 0.12& 8.58& .000\tabularnewline
& \multicolumn{4}{c}{\underline{Intercepts}}\tabularnewline
y1& 0.00$^+$& & & \tabularnewline
y2& 0.00$^+$& & & \tabularnewline
y3& 0.00$^+$& & & \tabularnewline
y4& 0.00$^+$& & & \tabularnewline
& \multicolumn{4}{c}{\underline{Residual Variances}}\tabularnewline
y1& 0.50$^+$& & & \tabularnewline
y2& 0.66$^+$& & & \tabularnewline
y3& 0.48$^+$& & & \tabularnewline
y4& 0.50$^+$& & & \tabularnewline
& \multicolumn{4}{c}{\underline{Latent Intercepts}}\tabularnewline
ExampleFactor& 0.00$^+$& & & \tabularnewline
& \multicolumn{4}{c}{\underline{Latent Variances}}\tabularnewline
ExampleFactor& 0.50& 0.08& 6.19& .000\tabularnewline
& \multicolumn{4}{c}{\underline{Thresholds}}\tabularnewline
y1(1)& -0.94& 0.09& -11.01& .000\tabularnewline
y1(2)& 1.04& 0.09& 11.70& .000\tabularnewline
y2(1)& -0.51& 0.08& -6.77& .000\tabularnewline
y2(2)& 1.04& 0.09& 11.70& .000\tabularnewline
y3(1)& -0.25& 0.07& -3.45& .001\tabularnewline
y3(2)& 1.05& 0.09& 11.80& .000\tabularnewline
y4(1)& -0.99& 0.09& -11.41& .000\tabularnewline
y4(2)& 1.07& 0.09& 11.89& .000\tabularnewline
& \multicolumn{4}{c}{\underline{Fit Indices}}\tabularnewline
Root M.SQ.E.A& 0.00& & & \tabularnewline
CompFitIdx& 1.00& & & \tabularnewline
chisq& 0.03& & & \tabularnewline
Scaled $\chi^{2}(\mathrm{df})$& 0.07(2)& & & .966\tabularnewline
\hline\multicolumn{5}{l}{$^+$Fixed parameter}\tabularnewline
\end{tabular}

 

semTable documentation built on April 30, 2020, 1:05 a.m.