% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/psychometrics.R
\name{cfa_syntax}
\alias{cfa_syntax}
\title{Generate lavaan CFA syntax from an instrument object}
\usage{
cfa_syntax(instrument, scales = NULL, std_lv = TRUE)
}
\arguments{
\item{instrument}{An \code{sframe} object.}

\item{scales}{Character vector or NULL. A subset of scale IDs to include.
When NULL, all scales are included.}

\item{std_lv}{Logical. Whether to include the \code{std.lv = TRUE} argument note
in the output comment header. Defaults to \code{TRUE}.}
}
\value{
A character string of \code{lavaan} CFA model syntax.
}
\description{
Produces a character string of \code{lavaan} model syntax derived from the
scale structure in the instrument. The syntax can be passed directly to
\code{lavaan::cfa()}. Reverse-coded items are noted in a comment but are not
transformed in the syntax; recoding should be applied to the data before
fitting the model.
}
\examples{
cs    <- sf_choices("ag5", 1:5,
           c("Strongly disagree", "Disagree", "Neutral",
             "Agree", "Strongly agree"))
i1    <- sf_item("sat_1", "Item 1", type = "likert",
                 choice_set = "ag5", scale_id = "sat")
i2    <- sf_item("sat_2", "Item 2", type = "likert",
                 choice_set = "ag5", scale_id = "sat")
i3    <- sf_item("sat_3", "Item 3 (reverse)", type = "likert",
                 choice_set = "ag5", scale_id = "sat", reverse = TRUE)
scale <- sf_scale("sat", "Satisfaction",
                  items = c("sat_1", "sat_2", "sat_3"))
instr <- sf_instrument("Demo Survey", components = list(cs, i1, i2, i3, scale))

syntax <- cfa_syntax(instr)
cat(syntax)

\dontrun{
# lavaan is not installed by default; install it before fitting.
demo   <- sframe_demo_data()
scored <- score_scales(demo$responses, demo$instrument)
fit    <- lavaan::cfa(syntax, data = scored, std.lv = TRUE)
summary(fit, fit.measures = TRUE)
}
}
\seealso{
\code{\link[=efa_report]{efa_report()}}, \code{\link[=reliability_report]{reliability_report()}}
}
