% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/process_data_scale_scores.R
\name{scale_scores}
\alias{scale_scores}
\title{Process Data by Computing Scale Scores}
\usage{
scale_scores(data, method = c("mean", "sum"))
}
\arguments{
\item{data}{A data frame with the
indicator scores. It must has an
attribute \code{number_of_indicators}.
The same argument used by
\code{\link[=power4test]{power4test()}}. This attribute is
used to identify the factor names
and their indicators.}

\item{method}{The method to be used
to compute the scale scores. Can
be \code{"mean"} or \code{"sum"}. The default
\code{na.rm = FALSE} will be used.
Therefore, \code{data} must not have
missing data.}
}
\value{
It returns a data frame with the
scale scores computed.
}
\description{
For the \code{process_data}
argument. To compute scale scores
from indicators and replace the
indicators scores by computed
scale scores.
}
\details{
This function is to be used in
the \code{process_data} argument of
\code{\link[=power4test]{power4test()}}.

It retrieves the attribute
\code{"number_of_indicators"},
stored by \code{\link[=power4test]{power4test()}}, to identify
factors with indicators, computes
the scale scores based on \code{method},
and replace the indicators by the
scale scores.

All subsequent steps, such as the
test functions, will see only the
scale scores, or original scores if
a variable has no indicator. The
model will also be fitted on the
scale scores, not on the indicators.

It can be used to estimate power
for analyzing the scale scores,
taking into account the measurement
error due to imperfect reliability.
}
\examples{

# Specify the model

mod <-
"
m ~ x
y ~ m + x
"

# Specify the population values

mod_es <-
"
y ~ m: l
m ~ x: m
y ~ x: n
"

# Specify the numbers of indicators and reliability coefficients

k <- c(y = 3,
       m = 4,
       x = 5)
rel <- c(y = .70,
         m = .70,
         x = .70)

# Simulate the data

out <- power4test(
         nrep = 2,
         model = mod,
         pop_es = mod_es,
         n = 200,
         number_of_indicators = k,
         reliability = rel,
         process_data = list(fun = "scale_scores"),
         test_fun = test_parameters,
         test_args = list(op = "~"),
         parallel = FALSE,
         iseed = 1234)

dat <- pool_sim_data(out)
head(dat)

}
\seealso{
\code{\link[=power4test]{power4test()}}
}
