outputParamTab: A Function That Exports Tables based on dySEM models

View source: R/outputParamTab.R

outputParamTabR Documentation

A Function That Exports Tables based on dySEM models

Description

This function takes the model from fitted dySEM scripts and creates tables of expected output and/or exports them as .rtfs.

Usage

outputParamTab(
  dvn,
  model = NULL,
  fit,
  tabletype = NULL,
  gtTab = FALSE,
  writeTo = NULL,
  fileName = NULL
)

Arguments

dvn

Input dvn list from scrapeVarCross()

model

A character input specifying type of model to output: "cfa", "bidyc", "apim", "mim", "cfm", or "bidys".

fit

input object from fitted lavaan model.

tabletype

A character input of what type of table(s) is(are) desired. Options are "measurement" (i.e., loadings, intercepts, etc.), "structural" (i.e., latent slopes, such as actor/partner effects, k parameters), or "both" (i.e., both measurement and structural tables).

gtTab

A logical input indicating whether to generate the table(s) in gt::gt() table object format (TRUE). By default (FALSE), the table(s) are generated in tibble::tibble() format. Users can also apply the writeTo argument if they wish to export the gt:gt() table object(s).

writeTo

A character string specifying a directory path to where the gt::gt() table object(s) should be saved. If set to ".", the file(s) will be written to the current working directory. The default is NULL, and examples use a temporary directory created by tempdir(). writeTo is only relevant if gtTab = TRUE.

fileName

A character string specifying a desired base name for the output gt::gt() file(s). If a fileName is not provided (i.e., fileName = NULL), then defaults will be used (e.g., "dySEM_table", "dySEM_table_measurement", or "dySEM_table_structural) based on the tabletype argument. The resulting base name will automatically be appended with a .rtf file extension. fileName is only relevant if gtTab = TRUE and writeTo is specified.

Details

  • If gtTab = TRUE and writeTo is specified, then output will simultaneously be saved as a .rtf file to the user's specified directory.

  • If output file(s) is(are) successfully saved, a confirmation message will be printed to the console.

  • If a file with the same name already exists in the user's chosen directory, it will be overwritten.

Value

A list. More specifically, a tibble() if gtTab = FALSE (default), or gt::gt() object if gtTab = TRUE.

Examples

dvnx <- scrapeVarCross(dat = commitmentQ, x_order = "spi", x_stem = "sat.g", x_delim1 = ".",
x_delim2="_", distinguish_1="1", distinguish_2="2")

sat.config.script <- scriptCFA(dvnx, lvname = "Sat", constr_dy_meas = "none",
constr_dy_struct = "none")

sat.config.mod <- lavaan::cfa(sat.config.script, data = commitmentQ, std.lv = FALSE,
auto.fix.first= FALSE, meanstructure = TRUE)

outputParamTab(dvnx, model = "cfa", sat.config.mod, tabletype = "measurement",
writeTo = tempdir(), fileName = "dCFA_configural")
 
dvnxy <- scrapeVarCross(dat = commitmentQ, x_order = "spi", x_stem = "sat.g", x_delim1 = ".",
x_delim2="_", distinguish_1="1", distinguish_2="2",
y_order="spi", y_stem="com", y_delim1 = ".", y_delim2="_")

apim.indist.script <-  scriptAPIM(dvnxy, lvxname = "Sat", lvyname = "Com", est_k = TRUE)

apim.indist.mod <- lavaan::cfa(apim.indist.script, data = commitmentQ, std.lv = FALSE,
auto.fix.first= FALSE, meanstructure = TRUE)

outputParamTab(dvnxy, model = "cfa", sat.config.mod, tabletype = "measurement",
writeTo = tempdir(), fileName = "APIM_indist")

jsakaluk/dySEM documentation built on Sept. 23, 2024, 2:06 p.m.