factorComposite {pscore} | R Documentation |
Score Data Using a Factor Model
Description
Create a composite using a Factor Model
Usage
factorComposite(
object,
type = c("onefactor", "secondorderfactor", "bifactor"),
factors = list(NA_character_)
)
Arguments
object |
An object of class |
type |
A character string indicating the type of factor model to use |
factors |
A named list where names are the factor names and each element is a character string of the indicator names. |
Value
An S4 object of class FactorScores
.
See Also
Other composite:
mahalanobisComposite()
,
sumComposite()
Examples
# this example creates distances for the built in mtcars data
# see ?mtcars for more details
# The distances are calculated from the "best" in the dataset
# First we create an appropriate CompositeData class object
# higher mpg & hp are better and lower wt & qsec are better
d <- CompositeData(mtcars[, c("mpg", "hp", "wt", "qsec")],
thresholds = list(one = with(mtcars, c(
mpg = max(mpg),
hp = max(hp),
wt = min(wt),
qsec = min(qsec)))
),
higherisbetter = c(TRUE, TRUE, FALSE, FALSE))
# create the distance scores
# and the composite
# covariance matrix will be calculated from the data
# and data will be standardized to unit variance by default
dres <- prepareComposite(d)
# see a density plot of the distance scores
dres@distanceDensity
# regular summary of distance scores
summary(dres@distances)
# examine covariance matrix
round(dres@covmat,2)
# now we can create the composite based on summing the (standardized)
# distances from our defined thresholds
# by default, distances are squared, then summed, and then square rooted
# to be back on the original scale
fcomp <- factorComposite(dres, type = "onefactor")
# view a histogram of the composite scores
fcomp@scoreHistogram
# summarize the composite scores
summary(fcomp@scores)
## Not run:
# we can also fit a second-order factor model
# there are not enough indicators to identify the factor
# and so lavaan gives us warning messages
fcomp2 <- factorComposite(dres, type = "secondorderfactor",
factors = list(speed = c("hp", "qsec")))
# view a histogram of the composite scores
fcomp2@scoreHistogram
# summarize the composite scores
summary(fcomp2@scores)
# compare one and second-order factor model scores
plot(fcomp@scores, fcomp2@scores)
# cleanup
rm(d, dres, fcomp, fcomp2)
## End(Not run)
[Package pscore version 0.4.0 Index]