add_composite_scores: For each latent variable in a structural model, add a...

Description Usage Arguments Value Examples

View source: R/main.R

Description

For each latent variable in a structural model, add a composite score to observed data.

Usage

1
2
3
4
5
6
7
8
9
add_composite_scores(
  d,
  m,
  mu = 0,
  sigma = 1,
  names_suffix = "_Composite",
  keep_observed_scores = TRUE,
  ...
)

Arguments

d

A data.frame with observed data in standardized form (i.e, z-scores)

m

A character string with lavaan model

mu

Score means. Composite scores will also have this mean. Defaults to 0.

sigma

Score standard deviations. Composite scores will also have this standard deviation. Defaults to 1.

names_suffix

A character string added to each composite score name

keep_observed_scores

The observed scores are returned along with the composite scores.

...

parameters passed to simstandardized_matrices

Value

data.frame with observed data and estimated factor scores

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(simstandard)
# lavaan model
m = "
X =~ 0.9 * X1 + 0.8 * X2 + 0.7 * X3
"

# Make data.frame for two cases
d <- data.frame(
  X1 = c(1.2, -1.2),
  X2 = c(1.5, -1.8),
  X3 = c(1.8, -1.1))

# Compute composite scores for two cases
add_composite_scores(d, m)

simstandard documentation built on May 8, 2021, 1:06 a.m.