get_fs: Get Factor Scores and the Corresponding Standard Error of...

View source: R/get_fscore.R

get_fsR Documentation

Get Factor Scores and the Corresponding Standard Error of Measurement

Description

Get Factor Scores and the Corresponding Standard Error of Measurement

Usage

get_fs(
  data,
  model = NULL,
  group = NULL,
  method = c("regression", "Bartlett"),
  corrected_fsT = FALSE,
  vfsLT = FALSE,
  reliability = FALSE,
  ...
)

Arguments

data

A data frame containing indicators.

model

An optional string specifying the measurement model in lavaan syntax. See model.syntax for more information.

group

Character. Name of the grouping variable for multiple group analysis, which is passed to cfa.

method

Character. Method for computing factor scores (options are "regression" or "Bartlett"). Currently, the default is "regression" to be consistent with lavPredict, but the Bartlett scores have more desirable properties and may be preferred for 2S-PA.

corrected_fsT

Logical. Whether to correct for the sampling error in the factor score weights when computing the error variance estimates of factor scores.

vfsLT

Logical. Whether to return the covariance matrix of fsT and fsL, which can be used as input for vcov_corrected() to obtain corrected covariances and standard errors for tspa() results. This is currently ignored.

reliability

Logical. Whether to return the reliability of factor scores.

...

additional arguments passed to cfa. See lavOptions for a complete list.

Value

A data frame containing the factor scores (with prefix "fs_"), the standard errors (with suffix "_se"), the implied loadings of factor "_by_" factor scores, and the error variance-covariance of the factor scores (with prefix "evfs_"). The following are also returned as attributes: * fsT: error covariance of factor scores * fsL: loading matrix of factor scores * fsb: intercepts of factor scores * scoring_matrix: weights for computing factor scores from items

Examples

library(lavaan)
get_fs(PoliticalDemocracy[c("x1", "x2", "x3")])

# Multiple factors
get_fs(PoliticalDemocracy[c("x1", "x2", "x3", "y1", "y2", "y3", "y4")],
       model = " ind60 =~ x1 + x2 + x3
                 dem60 =~ y1 + y2 + y3 + y4 ")

# Multiple-group
hs_model <- ' visual  =~ x1 + x2 + x3 '
fit <- cfa(hs_model,
           data = HolzingerSwineford1939,
           group = "school")
get_fs(HolzingerSwineford1939, hs_model, group = "school")
# Or without the model
get_fs(HolzingerSwineford1939[c("school", "x4", "x5", "x6")],
       group = "school")

Gengrui-Zhang/R2spa documentation built on Sept. 6, 2024, 5:01 p.m.