library(simsem)
NSFdata <-read.csv("NSFdata.csv")
hs.model <- ' SL =~ ASL+ PSL+ DPSL+ TTSL
WL =~ TWL + PWL + DPWL + TTWL
spokenPSTM =~ letSpan + NWRec + Nwspan
signedPSTM =~ NSPT + proSign + signCon
WMC =~ Ospan + SymSpan + RoSpan + numSeries + letSets + ravens + slat
Gc=~ Info + Vocab + Gram + Reading
Gf=~numSeries + letSets + ravens + slat
Gf~~ 0*WMC
TTWL~~TTSL
letSets~~numSeries '
fit <- cfa(hs.model, data=NSFdata)
datamodel.nomis<-model.lavaan(fit, std=FALSE)
output.nomis <- sim(1000, n=nrow(NSFdata), datamodel.nomis)
loading <- matrix(0, 25, 7)
loading[1:4, 1]<-NA
loading[5:8, 2]<-NA
loading[9:11, 3]<-NA
loading[12:14, 4]<-NA
loading[15:17, 5]<-NA
loading[18:21, 6]<-NA
loading[22:25, 7]<-NA
loading.mis <- matrix("runif(1, -0.2, 0.2)", 25, 7) #will need to account for split loadings
loading.mis[
is.na(loading)] <- 0
datamodel.mis <- model.lavaan(fit, std=FALSE, LY=loading.mis)
output.mis <- sim(1000, n=nrow(NSFdata), datamodel.mis)
plotCutoff(output.mis, 0.05)
getCutoff(output.mis, .05)
pValue(fit, output.mis))