Questions tagged [r-lavaan]

A free, open-source `R` package for latent variable analysis. `lavaan` includes support for a large variety of multivariate statistical models which contain (or not) latent variables. It allows multilevel analysis, and as estimators that deal with missing values and categorical data. Some of the applications available are confirmatory factor analysis, full structural equation models, latent growth curve models, and path analysis.

A free, open-source R package for latent variable analysis. lavaan includes support for a large variety of multivariate statistical models which contain (or not) latent variables. It allows multilevel analysis, and as estimators that deal with missing values and categorical data. Some of the applications available are confirmatory factor analysis, full structural equation models, latent growth curve models, and path analysis.

Resources

Repositories

Related plotting packages

  • lavaanPlot - Visual analusis of lavaan models.
  • semPlot - visual analysis of various SEM packages' output, including lavaan.
308 questions
1
vote
1 answer

How to repeat several similar named variables in lavaan model syntax easily?

Suppose we have a data frame like the one below. The numbers are irrelevant to my actual query, so I have simply given them the same value. df <- data.frame(ABC_1 = c(1,2,3), ABC_2 = c(1,2,3), ABC_3 = c(1,2,3), …
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
1
vote
1 answer

Overlays with lavaan and graph_sem

I am having trouble generating readable plots from Lavaan in R. I have a fitted model that I try to plot with graph_sem from the tidySEM library. The plots I generate have all of the independent variables overlaid which limits readability (please…
1
vote
1 answer

Clean up list output within RStudio when using lapply() or sapply()

I have a function that I am using with lapply(). lapply(x, function(x)) The output looks like this: [[1]] [1] "att_admire" [[2]] [1] "att_hypocrisy" [[3]] [1] "att_annoyed" [[4]] [1] "" [[5]] [1] "att_respectvalues" When I use sapply(),…
melbez
  • 960
  • 1
  • 13
  • 36
1
vote
1 answer

What is "NA * variable" in lavaan package in R? (factor analysis)

library(lavaan) #model fig2.5.data <- ' 1 .5 1 .1 .1 1 .2 .3 .2 1 ' fig2.5.cor <- getCov(fig2.5.data, names=c(c("X1", "X2", "X3", "X4"))) fig2.5.model <- ' # latent variables F1 =~ NA*X1 + a*X1 + b*X2 F2 =~ NA*X3 + c*X3 + d*X4 #…
No Ru
  • 37
  • 3
1
vote
1 answer

Estimating regression paths in lavaan, df and test statistics

I am trying to compare structural equation models using lavaan in R. I have 4 latent variables, three of which are being estimated by 8 observed variables and one of which is being estimated by 2 observed variables. When I run the measurement model,…
1
vote
1 answer

Monte Carlo with simsem and lavaan: "Error in D3.LRT ... Try the D2 pooling method."

My goal is to generate a list of dataframes from a lavaan model using simsem::sim. Depending on if the dataOnly argument is TRUE or FALSE, simsem::sim will either generate a SimResult object (which includes generated data plus parameter values, fit…
jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
1
vote
1 answer

r in Jupyter Notebook: lavaan summary output not formatted correctly

I use r in Jupyter Notebook. I was re-running old confirmatory factor analysis (CFA) code and recently I have no longer been able to see accurately see the summary() output in it's normal format. Instead it is in the variable "$variable_name"…
Gold
  • 11
  • 2
1
vote
2 answers

Extract full p-value from Lavaan CFA output in R

R-novice here. I am running a CFA using the Lavaan package. It is giving me everything I need, except my p-value is coming up at .000 and I would like to find the exact p-value (i.e. .0000009 or whatever it might be). I have tried to…
1
vote
1 answer

How to extract measurement error in Lavaan (cfa) as a score?

I want to extract the variance that is common in 3 variables from my items. I believe I could perform a CFA and fix the loadings to be equal and then extract the "measurement error," which I expect would be scores per item for every datapoint, such…
1
vote
0 answers

Error message lavaan cfa missing observed variables in dataset: ..constant

I am using lavaan package to run confirmatory analysis and got the following error: Error in lavaan::lavaan(model = m7f, data = dat, std.lv = TRUE, model.type = "cfa", : lavaan ERROR: missing observed variables in dataset: ..constant.. I…
1
vote
1 answer

Is it necessary to fix covariance to zero when the variance of a factor is fixed at zero?

When I conducted sem using lavaan, I found the variance of a factor was negative. So I fixed the variance of this factor to be zero. Should I fix the covariance with this factor also to be zero? I knew that in Mplus, when one constrained the…
1
vote
1 answer

R: How to obtain diagnostic plots for a lavaan mediation model?

I wasn't sure whether this was more appropriate to ask here or CrossValidated as I'm specifically asking about using R / lavaan... I'm not sure if I've completely misunderstood how violations of assumptions are checked. I understand that we can…
1
vote
1 answer

lmer longitudinal analyses in R for variance within subjects and between timepoints

I have the following longitudinal (3 Timepoints) data set: # A tibble: 504 x 6 ID Age Age_group Sex Timepoint outcome 1 33714 15 Young Male bl 0.00103 2 35377 15…
CanyonView
  • 401
  • 3
  • 15
1
vote
0 answers

Extract fit measures from multiple models

I am using the lavaan package to run multiple confirmatory factor analysis models from which I want to extract several fit measures ("chisq", "cfi", "rmsea", "srmr"). I know that I can print out these fit measures from one model at a time like…
cliu
  • 933
  • 6
  • 13
1
vote
0 answers

"Could not compute standard errors" and "The variance-covariance matrix of the estimated parameters does not appear to be positive definite!"

I've been stuck on this assignment for days. Can someone please help me understand what I'm doing wrong? I've included a picture of the path diagram and labels for each step to make my thought process clear. I'm new to SEM and the model would be the…
NCM
  • 11
  • 1