#install.packages("lavaan") #install.packages("MIIVsem") #install.packages("tidyverse") library(lavaan) library(MIIVsem) library(tidyverse) 'NOTE: For annotations and notes, see the uploaded Markdown file' #<########################################################################> # Data import---- #<########################################################################> data_study1 <- read_csv("./Study 1 data.csv") #<########################################################################> # CFAs---- #<########################################################################> #Starting model #<########################################################################> cfa1 <- ' VIRUS_WORRY =~ aw01 + aw02 + aw03 WORRY_EMPL =~ ewj01 + ewj02 + ewj03 WORRY_REC = ~ ewe01 + ewe02 + ewe03 ACC =~ acc01 + acc02 + acc03 REJ =~ rej01 + rej02 + rej03 ' fit.cfa1 <- sem(cfa1, data = data_study1, estimator="MLR", missing="FIML") summary(fit.cfa1, fit.measures=TRUE, standardized=TRUE) miive(cfa1, data_study1) resid(fit.cfa1, "standardized") # Re-specified model (without aw02 und rej02) #<########################################################################> cfa2 <- ' VIRUS_WORRY =~ aw01 + aw03 WORRY_EMPL =~ ewj02 + ewj01 + ewj03 WORRY_REC = ~ ewe02 + ewe01 + ewe03 ACC =~ acc01 + acc02 + acc02 REJ =~ rej01 + rej02 ' fit.cfa2 <- sem(cfa2, data = data_study1, estimator="MLR", missing="FIML") summary(fit.cfa2, fit.measures=TRUE, standardized=TRUE) miive(cfa2, data_study1) #<########################################################################> # SEM---- #<########################################################################> # Initial model (based on cfa2) #<########################################################################> sem1 <- ' VIRUS_WORRY =~ aw01 + aw03 WORRY_EMPL =~ ewj02 + ewj01 + ewj03 WORRY_REC = ~ ewe02 + ewe01 + ewe03 ACC =~ acc01 + acc02 + acc03 REJ =~ rej01 + rej02 VIRUS_WORRY ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS WORRY_EMPL ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS WORRY_REC ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS ACC ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS REJ ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS ' fit.sem1 <- sem(sem1, data = data_study1, estimator="MLR", missing="FIML") summary(fit.sem1, fit.measures=TRUE, standardized=TRUE) miive(sem1, data_study1) resid(fit.sem1, "standardized") #Final model: Single indicator aw01 #<########################################################################> data_study1 %>% summarise(var = var(aw01, na.rm=TRUE)) %>% mutate(fixed.error = var*(1-.80)) sem2 <- ' VIRUS_WORRY =~ aw01 WORRY_EMPL =~ ewj02 + ewj01 + ewj03 WORRY_REC = ~ ewe02 + ewe01 + ewe03 ACC =~ acc01 + acc02 + acc03 REJ =~ rej01 + rej02 VIRUS_WORRY ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS WORRY_EMPL ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS WORRY_REC ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS ACC ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS REJ ~ health_anx_XS + worries_trait_XS + reactance_trait_XS + lonely_XS + affected_econ_XS #Error correction aw01~~.635*aw01 ' fit.sem2 <- sem(sem2, data = data_study1, estimator="MLR", missing="FIML") summary(fit.sem2, fit.measures=TRUE, standardized=TRUE) miive(sem2, data_study1) resid(fit.sem2, "standardized")