\name{lavaan-class}
\docType{class}
\alias{lavaan-class}
\alias{coef,lavaan-method}
\alias{vcov,lavaan-method}
\alias{anova,lavaan-method}
\alias{predict,lavaan-method}
\alias{resid,lavaan-method}
\alias{residuals,lavaan-method}
\alias{fitted,lavaan-method}
\alias{fitted.values,lavaan-method}    %% NOTE: no white space here!
\alias{nobs} %% not imported in < 2.13
\alias{nobs,lavaan-method}
\alias{logLik,lavaan-method}
\alias{update,lavaan-method}
\alias{show,lavaan-method}
\alias{summary,lavaan-method}

\title{Class For Representing A (Fitted) Latent Variable Model}
\description{The \code{lavaan} class represents a (fitted) latent variable
  model. It contains a description of the model as specified by the user,
  a summary of the data, an internal matrix representation, and if the model
  was fitted, the fitting results.}
\section{Objects from the Class}{
Objects can be created via the
  \code{\link{cfa}}, \code{\link{sem}}, \code{\link{growth}} or
  \code{\link{lavaan}} functions.
}
\section{Slots}{
  \describe{
    \item{\code{version}:}{The lavaan package version used to create this object}
    \item{\code{call}:}{The function call as returned by \code{match.call()}.}
    \item{\code{timing}:}{The elapsed time (user+system) for various parts of
      the program as a list, including the total time.}
    \item{\code{Options}:}{Named list of options that were provided by
      the user, or filled-in automatically.}
    \item{\code{ParTable}:}{Named list describing the model parameters. Can be coerced to a data.frame. In the documentation, this is called the `parameter table'.}
    \item{\code{pta}:}{Named list containing parameter table attributes.}
    \item{\code{Data}:}{Object of internal class \code{"Data"}: information
about the data.}
    \item{\code{SampleStats}:}{Object of internal class \code{"SampleStats"}: sample
      statistics}
    \item{\code{Model}:}{Object of internal class \code{"Model"}: the
      internal (matrix) representation of the model}
    \item{\code{Cache}:}{List of objects that are computed only once and reused many times.}
    \item{\code{Fit}:}{Object of internal class \code{"Fit"}: the
      results of fitting the model. No longer used.}
    \item{\code{boot}:}{List. Results and information about the bootstrap.}
    \item{\code{optim}:}{List. Information about the optimization.}
    \item{\code{loglik}:}{List. Information about the loglikelihood of the model (if maximum likelihood was used).}
    \item{\code{implied}:}{List. Model implied statistics.}
    \item{\code{vcov}:}{List. Information about the variance matrix (vcov) of the model parameters.}
    \item{\code{test}:}{List. Different test statistics.}
    \item{\code{h1}:}{List. Information about the unrestricted h1 model (if available).}
    \item{\code{baseline}:}{List. Information about a baseline model (often
the independence model) (if available).}
    \item{\code{internal}:}{List. For internal use only.}
    \item{\code{external}:}{List. Empty slot to be used by add-on packages.}
  }
}
\section{Methods}{
  \describe{
    \item{coef}{\code{signature(object = "lavaan", type = "free")}: Returns
      the estimates of the parameters in the model as a named numeric vector.
      If \code{type="free"}, only the free parameters are returned.
      If \code{type="user"}, all parameters listed in the parameter table
      are returned, including constrained and fixed parameters.}
    \item{fitted.values}{\code{signature(object = "lavaan")}: Returns the
      implied moments of the model as a list with two elements (per group):
      \code{cov} for the implied covariance matrix,
      and \code{mean} for the implied mean
      vector. If only the covariance matrix was analyzed, the implied mean
      vector will be zero.}
    \item{fitted}{\code{signature(object = "lavaan")}: an alias for
        \code{fitted.values}.}
    \item{residuals}{\code{signature(object = "lavaan", type="raw")}:
	  If \code{type = "raw"}, this function returns the raw (= unscaled)
      difference between the observed and the expected (model-implied) summary
      statistics.
	  If \code{type = "cor"}, or \code{type = "cor.bollen"}, the observed and
      model implied covariance matrices are first transformed to a correlation
      matrix (using \code{cov2cor()}), before the residuals are computed.
	  If \code{type = "cor.bentler"}, both the observed and model implied
      covariance matrices are rescaled by dividing the elements by the square
      roots of the corresponding variances of the observed covariance matrix.
      If \code{type="normalized"}, the residuals are divided by the square
      root of the asymptotic variance of the corresponding summary statistic
      (the variance estimate depends on the choice for the \code{se} argument).
      Unfortunately, these normalized residuals are not entirely
      correct, and this option is retained only for historical interest.
      If \code{type="standardized"}, the residuals are divided by the square
      root of the asymptotic variance of these residuals. The resulting
      standardized residuals can be interpreted as z-scores.
      If \code{type="standardized.mplus"}, the residuals are divided by the
      square root of the asymptotic variance of these residuals. However, a
      simplified formula is used (see the Mplus reference below) which often
      results in negative estimates for the variances, resulting in many
      \code{NA} values for the standardized residuals.}
    \item{resid}{\code{signature(object = "lavaan")}: an alias
      for \code{residuals}}
    \item{vcov}{\code{signature(object = "lavaan", type = "free")}: returns
      the covariance matrix of the estimated parameters. If
      \code{type = "free"} (the default), only the free parameters are
      included. If \code{type = "user"} (or \code{"joint"}), the joint
      covariance matrix of the free and the user-defined (\code{:=})
      parameters is returned; the parameter names are the same as those
      used by \code{coef()}.}
    \item{predict}{\code{signature(object = "lavaan")}: compute
      factor scores for all cases that are provided in the data frame. For
      complete data only.}
    \item{anova}{\code{signature(object = "lavaan")}: returns
      model comparison statistics. This method is just a wrapper around
      the function \code{\link{lavTestLRT}}.
      If only a single argument (a fitted
      model) is provided, this model is compared to the unrestricted
      model. If two or more arguments (fitted models) are provided, the models
      are compared in a sequential order. Test statistics are based on the
      likelihood ratio test. For more details and
      further options, see the \code{\link{lavTestLRT}} page.}
    \item{update}{\code{signature(object = "lavaan", model, add, ...,
        evaluate = TRUE)}: update a fitted lavaan object and evaluate it
        (unless \code{evaluate = FALSE}). Note that we use the environment
        that is stored within the lavaan object, which is not necessarily
        the parent frame. The \code{add} argument is analogous to the one
        described in the \code{\link{lavTestScore}} page, and can be used to
        add parameters to the specified model rather than passing an entirely
        new \code{model} argument.}
    \item{nobs}{\code{signature(object = "lavaan")}: returns the effective
      number of observations used when fitting the model. In a multiple group
      analysis, this is the sum of all observations per group.}
    \item{logLik}{\code{signature(object = "lavaan")}:
      returns the log-likelihood of the fitted model, if maximum likelihood estimation
      was used. The \code{\link[stats]{AIC}} and \code{\link[stats]{BIC}}
      methods automatically work via \code{logLik()}.}
    \item{show}{\code{signature(object = "lavaan")}: Print a short summary
      of the model fit}
    \item{summary}{\code{signature(object = "lavaan", header = TRUE,
     fit_measures = FALSE, residuals = FALSE,
     estimates = TRUE, ci = FALSE, fmi = FALSE,
     standardized = FALSE, std = standardized, std_nox = FALSE,
     remove_system_eq = TRUE, remove_eq = TRUE, remove_ineq = TRUE,
     remove_def = FALSE, remove_nonfree = FALSE, remove_step1 = TRUE,
     remove_unused = TRUE, plabel = FALSE,
     cov_std = TRUE, rsquare = FALSE,
     baseline_model = NULL, h1_model = NULL,
     fm_args = list(standard.test = "default", scaled.test = "default",
     rmsea.ci.level = 0.90, rmsea.h0.closefit = 0.05,
     rmsea.h0.notclosefit = 0.08, robust = TRUE, cat.nonpd = "na"),
     modindices = FALSE, srmr_close_h0 = NULL,
     nd = 3L, cutoff = 0.3, dot_cutoff = 0.1)}:
      Print a nice summary of the model estimates.
      If \code{header = TRUE}, the header section (including fit measures) is
      printed.
      If \code{fit.measures = TRUE}, additional fit measures are added to the
      header section. \code{fit.measures} can also be a list, which allows one to set options
      related to the fit measures. See \code{\link{fitMeasures}}
      for more details.
      If \code{residuals = TRUE}, a residuals section is added (the largest
      residuals and the residual summary, printed as by
      \code{\link{lavResiduals}} with \code{output = "text"}); the underlying
      \code{lavResiduals(object, output = "list")} result is stored as the
      \code{residuals} element of the summary object. \code{residuals} can also
      be a list of arguments passed on to \code{\link{lavResiduals}} (for
      example \code{residuals = list(type = "raw", n.largest = 10)}).
      If both \code{fit.measures = TRUE} and \code{residuals = TRUE} and the
      residual summary is the SRMR (the default), the SRMR is removed from the
      fit measures section to avoid printing it twice.
      If \code{estimates = TRUE}, print the parameter estimates section.
      If \code{ci = TRUE}, add confidence intervals to the parameter estimates
      section.
      If \code{fmi = TRUE}, add the fmi (fraction of missing information)
      column, if it is available.
      If \code{standardized = TRUE} or a character vector, the standardized
      solution is also printed (see \code{\link{lavParameterEstimates}}).
      Note that \emph{SE}s and
      tests are still based on unstandardized estimates. Use
      \code{\link{standardizedSolution}} to obtain \emph{SE}s and test
      statistics for standardized estimates.
      The \code{std.nox} argument is deprecated; the \code{standardized}
      argument allows \code{"std.nox"} solution to be specifically requested.
      The \code{standardized} argument may also be a character vector of
      (observed) variable names (for example \code{c("x1", "x2")}); only the
      parameters involving these variables are then standardized, and the
      result is shown in a \code{Std.usr} column. This generalizes
      \code{"std.nox"}, where the exogenous \code{x} variables are the ones
      left unstandardized.
      If \code{remove_system_eq = TRUE}, the system-generated equality
      constraints (using plabels) are not shown.
      If \code{remove_eq = TRUE} or \code{remove_ineq = TRUE},
      the user-specified (in)equality constraints are not shown.
      If \code{remove_def = TRUE}, the user-specified parameter definitions are
      not shown.
      If \code{remove_nonfree = TRUE}, the nonfree parameters are not shown.
      If \code{remove_step1 = TRUE}, the parameters of the measurement part
      are not shown (only used when using \code{sam()}.)
      If \code{remove_unused = TRUE}, automatically added parameters that are
      fixed to their default (0 or 1) values are removed.
      If \code{rsquare = TRUE}, the R-Square values for the dependent variables
      in the model are printed.
      The \code{fm.args} list allows one to set options related to the fit
      measures (see \code{\link{fitMeasures}}).
      \code{baseline.model} and \code{h1.model} allow one to specify user-defined
      baseline and/or h1 models for the fit measures.
      If the model is an exploratory factor analysis (EFA) model, EFA related
      information is printed automatically. The \code{cutoff} and
      \code{dot.cutoff} arguments control how the factor loadings are displayed:
      loadings whose absolute value is at or above \code{cutoff} are shown as
      numbers; loadings whose absolute value falls between \code{dot.cutoff}
      and \code{cutoff} are replaced by a dot; loadings whose absolute value is
      below \code{dot.cutoff} are left blank.
      If \code{modindices = TRUE} or \code{modindices} is a list,
      modification indices are printed for all fixed parameters.
      The argument \code{nd} determines the number of digits after the
      decimal point to be printed (currently only in the parameter estimates
      section.) Historically, nothing was returned, but since 0.6-12, a
      list is returned of class \code{lavaan.summary} for which a print
      function is available.}
  }
}
\references{
Yves Rosseel (2012). lavaan: An R Package for Structural Equation
Modeling. Journal of Statistical Software, 48(2), 1-36.
\doi{10.18637/jss.v048.i02}

Standardized Residuals in Mplus. Document retrieved from URL
https://www.statmodel.com/download/StandardizedResiduals.pdf
}
\seealso{
\code{\link{cfa}}, \code{\link{sem}},
\code{\link{fitMeasures}}, \code{\link{standardizedSolution}},
\code{\link{lavParameterEstimates}}, \code{\link{lavInspect}},
\code{\link{modindices}}
}
\examples{
HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '

fit <- cfa(HS.model, data = HolzingerSwineford1939)

summary(fit, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
fitted(fit)
coef(fit)
resid(fit, type = "normalized")
}
