% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/process_ordinal.R
\name{ordinal_variables}
\alias{ordinal_variables}
\alias{cut_patterns}
\title{Process Data by Creating Ordinal Variables}
\usage{
ordinal_variables(data, cut_patterns = NULL, cuts = NULL)

cut_patterns(which = NULL)
}
\arguments{
\item{data}{A data frame.}

\item{cut_patterns}{A named vector.
The names are the names of the latent
variables for which indicator scores
will be converted. Each value must be
the name of one of the built-in
patterns (call \code{cut_patterns()} to
list the patterns and their names).
Can be used with \code{cuts} but a latent
variable should appear only either
in \code{cut_patterns} or \code{cuts}, not both.}

\item{cuts}{A named list.
The names are the names of the latent
variables for which indicator scores
will be converted.
Each element is a vector of the
thresholds for the conversion. \code{-Inf}
and \code{Inf} will be automatically
included during the conversion.
Can be used with \code{cut_patterns} but a latent
variable should appear only either
in \code{cut_patterns} or \code{cuts}, not both.}

\item{which}{A name of a built-in pattern.}
}
\value{
The function \code{\link[=ordinal_variables]{ordinal_variables()}}
returns a data frame with the
the converted scores.

The function \code{\link[=cut_patterns]{cut_patterns()}}
returns a named list of the built-in
patterns if \code{which = NULL}, and
a numeric vector of the thresholds
of a built-in pattern if \code{which} is
set to one of the names of the built-in
patterns.
}
\description{
For the \code{process_data}
argument. It converts continuous
indicator variable to ordinal variables.
}
\details{
This function is to be used in
the \code{process_data} argument of
\code{\link[=power4test]{power4test()}}.

It is used for converting the
continuous indicator scores generated
to ordinal scores (with values 1, 2, 3, etc.).

For example, if the cut points (thresholds) are
-2 and 2, then sores will be converted
to three categories: (-Inf to -2],
(-2 to 2], and (2 to Inf]. The intervals
are closed on the right. That is,
a score of -2 is in the interval
(-Inf to -2], not in the interval
(-2 to 2).

The conversion is implemented by \code{\link[=cut]{cut()}}.

There are two ways to specify the
conversion. The first one is to use
some built-in thresholds, based on
Savalei and Rhemtulla (2013), Table 1.
Call \code{\link[=cut_patterns]{cut_patterns()}} with no argument
to list all the built-in patterns
and their names.

Alternatively, users can specify the
thresholds directly through the argument
\code{cuts}.

Currently, all indicators of a latent
variable must be converted in the same
way.
}
\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 = "ordinal_variables",
                             args = list(cut_patterns = c(x = "s3"),
                                         cuts = list(m = c(-2, 0, 2)))),
         test_fun = test_parameters,
         test_args = list(op = "~"),
         parallel = FALSE,
         iseed = 1234)

dat <- pool_sim_data(out)
head(dat, 50)

# The built-in patterns

cut_patterns()

}
\references{
Savalei, V., & Rhemtulla, M. (2013).
The performance of robust test
statistics with categorical data.
\emph{British Journal of Mathematical and Statistical Psychology},
\emph{66}(2), 201--223.
\doi{10.1111/j.2044-8317.2012.02049.x}
}
\seealso{
\code{\link[=power4test]{power4test()}}. See also
\code{\link[=cut]{cut()}} for the implementation.
}
