estfun.RdA function for extracting the empirical estimating functions of a fitted lavaan model. This is the derivative of the objective function with respect to the parameter vector, evaluated at the observed (case-wise) data. In other words, this function returns the case-wise scores, evaluated at the fitted model parameters.
estfun.lavaan(object, scaling = FALSE, ignore.constraints = FALSE,
remove.duplicated = TRUE, remove.empty.cases = TRUE)
lavScores(object, scaling = FALSE, ignore.constraints = FALSE,
remove.duplicated = TRUE, remove.empty.cases = TRUE)An object of class lavaan.
Only used for the ML estimator. If TRUE, the scores are
scaled to reflect the specific objective function used by lavaan. If
FALSE (the default), the objective function is the loglikelihood
function assuming multivariate normality.
Logical. If TRUE, the scores do not reflect
the (equality or inequality) constraints. If FALSE, the scores are
computed by taking the unconstrained scores, and adding the term t(R)
lambda, where lambda are the (case-wise) Lagrange Multipliers, and
R is the Jacobian of the constraint function. Only in the latter case
will the sum of the columns be (almost) equal to zero.
If TRUE, and all the equality constraints have
a simple form (eg. a == b), the unconstrained scores are post-multiplied with a
transformation matrix in order to remove the duplicated parameters.
If TRUE, empty cases with only missing values
will be removed from the output.
A n x k matrix corresponding to n observations and k parameters.
## The famous Holzinger and Swineford (1939) example
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- cfa(HS.model, data = HolzingerSwineford1939)
#> Warning: lavaan->lav_model_vcov():
#> The variance-covariance matrix of the estimated parameters (vcov) does not
#> appear to be positive definite! The smallest eigenvalue (= -1.747972e-02)
#> is smaller than zero. This may be a symptom that the model is not
#> identified.
head(lavScores(fit))
#> visual=~x2 visual=~x3 textual=~x5 textual=~x6 speed=~x8 speed=~x9
#> [1,] -1.6349367 1.0439680 -0.7559437 0.01231985 -0.24080050 -0.10510450
#> [2,] -0.1478177 -0.2041641 0.2097133 -0.39420965 -0.27916454 1.85661185
#> [3,] 0.1697400 -0.3569433 1.8508591 -0.16512556 0.83511228 -0.13331725
#> [4,] 0.4188005 0.0256922 -0.2685750 -0.27424167 -0.31155288 -0.09988040
#> [5,] 0.2963467 0.3333981 -0.2183179 -0.45724951 -0.04314758 -0.09101942
#> [6,] -0.1326010 -0.1951689 -0.6904989 0.07550980 0.15667381 1.49678503
#> x1~~x1 x2~~x2 x3~~x3 x4~~x4 x5~~x5 x6~~x6
#> [1,] 0.4845926 1.32487795 0.6392927 0.3155491 5.3519739 1.31953776
#> [2,] -0.3359388 -0.12281934 -0.4897970 -0.4196637 -0.6640891 -1.02622205
#> [3,] -0.3609866 -0.34662332 -0.4853924 -0.8187993 -0.1341131 -1.02985157
#> [4,] -0.5360655 0.38102758 -0.3699997 -0.3297013 -0.7298769 -0.83087344
#> [5,] -0.3738746 0.06320399 0.2980138 -0.6794320 -0.6733551 -0.05038345
#> [6,] -0.3044733 0.05725583 -0.5078862 0.9918918 -0.7293423 -0.99499067
#> x7~~x7 x8~~x8 x9~~x9 visual~~visual textual~~textual
#> [1,] 0.03199316 -0.66346922 0.6344862 0.6017976 -0.4810562
#> [2,] 0.28666692 -0.71050689 4.7450307 -0.5235315 0.5412305
#> [3,] -0.53588768 0.13730901 -0.6836219 -0.3775340 1.1511125
#> [4,] 0.11298604 -0.69277182 -0.6120697 0.0164095 -0.5099791
#> [5,] -0.17477971 -0.08973652 -0.5149316 -0.1247173 -0.5243551
#> [6,] -0.30741660 -0.53842277 2.1949154 -0.5177562 1.2283596
#> speed~~speed visual~~textual visual~~speed textual~~speed
#> [1,] -0.4884885 -0.12443011 -1.1767352 0.4927875
#> [2,] 1.4706996 0.22016944 0.5632879 -3.0962135
#> [3,] 0.4639680 -0.67315818 -0.5435737 3.3554485
#> [4,] -0.1455539 0.13952581 -0.9918440 0.4166081
#> [5,] -0.4428133 0.27600814 -0.5778793 0.2381162
#> [6,] 2.3536972 0.08299499 0.7390862 -4.7025395