Skip to contents

A generic function (and corresponding methods) that produces predicted values or factor scores from modsem models.

Usage

modsem_predict(object, ...)

# S3 method for class 'modsem_da'
modsem_predict(
  object,
  standardized = FALSE,
  H0 = TRUE,
  newdata = NULL,
  center.data = TRUE,
  ...
)

# S3 method for class 'modsem_pi'
modsem_predict(object, ...)

Arguments

object

modsem_da object

...

Further arguments passed to lavaan::predict; currently ignored by the modsem_da method.

standardized

Logical. If TRUE, return standardized factor scores.

H0

Logical. If TRUE (default), use the baseline model to compute factor scores. If FALSE, use the model specified in object. Using H0 = FALSE is not recommended!

newdata

Compute factor scores based on a different dataset, than the one used in the model estimation.

center.data

Should data be centered before computing factor scores? Default is TRUE.

Value

* For modsem_pi: whatever lavaan::predict(), which usually returns a matrix of factor scores. * For modsem_da: a numeric matrix \(n \times p\), where \(n\) is the number of (complete) observations in the dataset, and \(p\) the number of latent variables. Each column contains either raw or standardised factor scores, depending on the standardized argument.

Methods (by class)

  • modsem_predict(modsem_da): Computes (optionally standardised) factor scores via the regression method using the baseline model unless H0 = FALSE.

  • modsem_predict(modsem_pi):

Examples

m1 <- '
# Outer Model
  X =~ x1 + x2 + x3
  Z =~ z1 + z2 + z3
  Y =~ y1 + y2 + y3

# Inner Model
  Y ~ X + Z + X:Z
'

est_dca <- modsem(m1, oneInt, method = "dblcent")
head(modsem_predict(est_dca))
#>               X           Z           Y         XZ
#> [1,]  0.7335391  0.06120326  0.05047257 -0.2208065
#> [2,] -0.6821195  2.18041524 -0.88082672 -1.8387785
#> [3,] -1.7943935  0.51493114 -1.93045740 -1.1061514
#> [4,]  1.3702391  2.15235456  5.01851357  2.8293527
#> [5,]  1.7397838 -0.87027404  0.80814709 -1.6768080
#> [6,] -1.7169401 -0.86698974 -0.34724128  1.3455015

# \dontrun{
est_lms <- modsem(m1, oneInt, method = "lms")
head(modsem_predict(est_lms))
#>            X           Z           Y
#> 1  0.7980664  0.06766337  0.03152707
#> 2 -0.7424647  2.36034558 -0.89907069
#> 3 -1.9141728  0.58633881 -1.95369573
#> 4  1.3947779  2.23652498  5.08213668
#> 5  1.8146304 -0.99632556  0.89884045
#> 6 -1.8390114 -0.92032081 -0.31852536
# }