# NOT RUN {
## Most of the examples were moved to the semTable vignette
require(lavaan)
tempdir <- tempdir()
## The example from lavaan's docs
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9'
fit1 <- cfa(HS.model, data = HolzingerSwineford1939,
std.lv = TRUE, meanstructure = TRUE)
## Try a LaTeX file first
fit1.t1 <- semTable(fit1, columns = c("estse", "p"),
fits = c("chisq", "rmsea"), file = file.path(tempdir, "fit1.t1"),
varLabels = c("x1" = "hello"), type = "latex", print.results = FALSE)
## If you have a working version of pdflatex in your system path,
if (interactive()) testtable("fit1.t1.tex", tempdir)
model <- "factor =~ .7*y1 + .7*y2 + .7*y3 + .7*y4
y1 | -1*t1 + 1*t2
y2 | -.5*t1 + 1*t2
y3 | -.2*t1 + 1*t2
y4 | -1*t1 + 1*t2"
dat <- simulateData(model, sample.nobs = 300)
testmodel <- "ExampleFactor =~ y1 + y2 + y3 + y4"
fit4 <- cfa(testmodel, data = dat, ordered = colnames(dat),
std.lv = FALSE)
fit4.t1 <- semTable(fit4, paramSets = c("loadings", "thresholds",
"residualvariances"), fits = c("tli", "chisq"),
fitLabels = c(tli = "TLI", chisq = "chisq"), type = "html",
file=file.path(tempdir, "fit4.t1") )
if(interactive()) browseURL(attr(fit4.t1, "file"))
fit4.t2 <- semTable(fit4, fits = c("rmsea", "cfi", "chisq"),
fitLabels = c(rmsea = "Root M.SQ.E.A", cfi = "CompFitIdx", chisq = "chisq"),
type = "latex", file=file.path(tempdir, "fit4.t2"))
if (interactive()) testtable("fit4.t2.tex", tempdir)
# }
Run the code above in your browser using DataLab