Last updated: r format(Sys.Date(), "%B %d %Y")
See Package References{target="_blank"} for help documentation on semoutput
functions
Required Packages
knitr::opts_chunk$set(error = TRUE, message = FALSE, warning = TRUE) library(readr) library(here) library(dplyr) library(lavaan) library(psych) library(semoutput) library(semPlot) library(sjPlot)
Import Data
## Import Data data <- read_csv(here("relative file path", "file name"))
# Prints basic descriptive statistics sem_descriptives(data)
# Uses sjPlot to print a nice looking correlation table tab_corr(data, na.deletion = "pairwise", digits = 2, triangle = "lower")
efa_data <- data ## Determine the number of factors to extract VSS.scree(efa_data) fa.parallel(efa_data, fa = "fa") VSS(efa_data, n = 4, rotate = "varimax") ## Conduct EFA analysis with nfactors determined from methods above efa_fit <- fa(efa_data, fm = "pa", nfactors = 3, rotate = "varimax")
efa_method(efa_fit) efa_var(efa_fit) efa_loadings(efa_fit) efa_rotmatrix(efa_fit)
fa.diagram(efa_fit)
efa_fit
See the lavaan Tutorial{target="_blank"} for model syntax
# specify the model model <- ' # latent factors # correlated errors # constraints ' # fit the model fit <- cfa(model = model, data = data, mimic = "lavaan", estimator = "ML", missing = "ML", std.lv = TRUE, std.ov = FALSE, test = "standard", se = "standard", bootstrap = 1000)
sem_tables(fit)
factors <- fit@pta$vnames$lv[[1]] size <- .65 semPaths(fit, latents = factors, whatLabels = "std", layout = "tree2", rotation = 2, style = "lisrel", optimizeLatRes = TRUE, structural = FALSE, layoutSplit = FALSE, intercepts = FALSE, residuals = FALSE, curve = 1, curvature = 3, nCharNodes = 8, sizeLat = 11 * size, sizeMan = 11 * size, sizeMan2 = 4 * size, edge.label.cex = 1.2 * size, edge.color = "#000000", edge.label.position = .40)
sem_residuals(fit)
summary(fit, fit.measures = TRUE, standardized = TRUE)
standardizedSolution(fit)
modificationIndices(fit, sort. = TRUE, minimum.value = 3)
See the lavaan Tutorial{target="_blank"} for model syntax
# specify the model model <- ' # latent factors # variances # covariances # regressions ' # fit the model fit <- sem(model = model, data = data, mimic = "lavaan", estimator = "ML", missing = "ML", std.lv = FALSE, std.ov = FALSE, test = "standard", se = "standard", bootstrap = 1000)
sem_tables(fit)
factors <- fit@pta$vnames$lv[[1]] size <- .65 semPaths(fit, latents = factors, whatLabels = "std", layout = "tree2", rotation = 2, style = "lisrel", optimizeLatRes = TRUE, structural = FALSE, layoutSplit = TRUE, intercepts = FALSE, residuals = FALSE, curve = 1, curvature = 3, nCharNodes = 8, sizeLat = 11 * size, sizeMan = 11 * size, sizeMan2 = 4 * size, edge.label.cex = 1.2 * size, edge.color = "#000000", edge.label.position = .40)
sem_residuals(fit)
summary(fit, fit.measures = TRUE, standardized = TRUE)
standardizedSolution(fit)
modificationIndices(fit, sort. = TRUE, minimum.value = 3)
citation("lavaan") citation() sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.