I'm getting this error message when trying to knit. Any suggestions?
Quitting from lines 25-90 [unnamed-chunk-1] (Week-4-Assignment_KK.Rmd)
Error in if (categorical.flag) ...:
! argument is of length zero
Backtrace:
- rmarkdown::render(...)
- knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
- knitr:::process_file(text, output)
- knitr:::process_group.block(group)
- knitr:::call_block(x) ...
- evaluate:::evaluate_call(...)
- knitr (local) value_fun(ev$value, ev$visible)
- knitr (local) fun(x, options = options)
- rmarkdown:::knit_print.data.frame(x, ...)
- lavaan:::print.lavaan.parameterEstimates(x) Execution halted
This is the code in the chunk where it stops:
options(repos = "https://cloud.r-project.org/")
install.packages("psych")
install.packages("semTools")
install.packages("Amelia")
install.packages("lavaan")
library(psych)
library(semTools)
library(Amelia)
library(lavaan)
data(bfi)
edu3 <- bfi[which(bfi$education == 3),] #only include people with edu = 3
bfi_new <- edu3[, 1:25] #removes all the non BFI item
#define model and order ordinal variables
cfa_mod<-'
F1=~E1+E2+E3+E4+E5
F2=~N1+N2+N3+N4+N5
F3=~C1+C2+C3+C4+C5
F4=~O1+O2+O3+O4+O5
F5=~A1+A2+A3+A4+A5
'
#do MI after specify SE to be robust and specify ordinal data
out <- cfa.mi(cfa_mod, data = bfi_new, m = 20, seed = 712, se="robust",
miArgs = list(ordered=c("E1","E2","E3","E4","E5",
"N1","N2","N3","N4","N5",
"O1","O2","O3","O4","O5",
"C1","C2","C3","C4","C5",
"A1","A2","A3","A4","A5")))
#run CFA
summary(out,fit=T, pool = TRUE)
fit <- cfa(cfa_mod, bfi_new)
summary(fit,standardize=T)
#RMSEA 0.076
#this RSMEA indicates good model fit
#Confidence interval - lower 0.073
#upper bound should ideally be <.05 to indicate good fit, this does not indicate good fit
#Confidence interval - upper 0.079
#upper bound should ideally be <.08 to indicate good fit, so this is a good fit
#P-value H_0: RMSEA <= 0.05 0.000
#SRMR 0.076
#Since the value is <.08, the model demonstrates acceptable fit
#Comparative Fit Index (CFI) 0.773
#CFI should ideally be >.9, so this does not indicate strong model fit
#Tucker-Lewis Index (TLI) 0.743
#TLI should ideally be >.9, so this does not indicate strong model fit
#Model test
#Test statistic 2194.264
#Degrees of freedom 265
#P-value 0.000
#Baseline test
#Test statistic 8803.497
#Degrees of freedom 300
#P-value 0.000
#The lower test in the model tests indicates the model is a better fit than the baseline test. P<.001 indicates a statistically significant result in both tests. 35 cases were removed due to missing data.
I tried adding the first line above installing packages, uninstalled and reinstalled the packages, restarted R multiple times. Still getting the same error.
That error is related to 2 new
attributes()thatlavaanadded to its customdata.frameclass for itsparameterEstimates(), which has been incorporated into the development version ofsemTools. You can install that using theremotespackage: