Code:
title: "CFA_PART_OHI"
output: html_document
knitr::opts_chunk$set(echo = TRUE)
#calling the relevant libraries
library(psych) # for describing the data
library(lavaan) #For the confirmatory factor analysis
library(haven) #This allows you to read in SAS and SPSS files
library(tidySEM)
library(ggplot2)
library(dplyr)
#PC Version
setwd("C:/Users/Admin/Desktop/CFA_Stats_Prac")
#### Reading in a SPSS file
cfa = read_sav("OHI_only_data_spss_new_102721.sav")
Head of CFA data and descriptive statistics
head(cfa)
describe(cfa)
CFA 3 factors with OHI
####This fits a Three Factor CFA to the DF Facets
cfa_OHI <- 'DF1 =~ fmdio + fmdicho + stmp2p + mtgd + srm
DF2 =~ NN_00 + NN + soscol
DF3 =~ ucmrt_accuracy + corsi_accuracy'
threefactcfa_1 <- cfa(cfa_OHI, data=cfa, estimator="ML", missing="ml")
#lavTestScore(threefactcfa_1, cumulative = TRUE)
summary(threefactcfa_1,fit.measures=TRUE, standardized=TRUE, modindices=TRUE)
lay <- get_layout("", "", "DF1","","DF2","","DF3","", "",
"fmdio", "fmdicho", "stmp2p", "mtgd", "srm",
"NN_00", "NN", "soscol",
"ucmrt_accuracy", "corsi_accuracy", rows = 2)
graph_sem(model = threefactcfa_1, layout = lay)
Initially I ran my model and it was not giving me modification indices:
Error in modificationIndices(object, standardized = TRUE, cov.std = cov.std) :
lavaan ERROR: could not compute modification indices; information matrix is singular
Calls: ... summary -> summary -> .local -> modificationIndices
Execution halted
I tried removing modification indices results in the model not giving me Chi-square or fit measures, with the error:
Warning in .local(object, ...): lavaan WARNING: fit measures not available if model did not converge
Please help, this is part of my studies!