% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/test_conditional_indirect_effect.R
\name{test_cond_indirect}
\alias{test_cond_indirect}
\title{Test a Conditional Indirect Effect}
\usage{
test_cond_indirect(
  fit = fit,
  x = NULL,
  m = NULL,
  y = NULL,
  wvalues = NULL,
  mc_ci = TRUE,
  mc_out = NULL,
  boot_ci = FALSE,
  boot_out = NULL,
  check_post_check = TRUE,
  test_method = NULL,
  ...,
  fit_name = "fit",
  get_map_names = FALSE,
  get_test_name = FALSE
)
}
\arguments{
\item{fit}{The fit object, to be
passed to \code{\link[manymome:cond_indirect]{manymome::cond_indirect()}}.}

\item{x}{The name of the \code{x}-variable,
the predictor.}

\item{m}{A character vector of the
name(s) of mediator(s). The path
moves from the first mediator in the
vector to the last mediator in the
vector. Can be \code{NULL} and the path
is a direct path without mediator.}

\item{y}{The name of the \code{y}-variable,
the outcome variable.}

\item{wvalues}{A numeric vector of
named elements. The names are the
variable names of the moderators,
and the values are the values to
which the moderators will be set to.
Default is \code{NULL}.}

\item{mc_ci}{Logical. If \code{TRUE}, the
default, Monte Carlo confidence
intervals will be formed. This argument
and \code{boot_ci} cannot be both \code{TRUE}.}

\item{mc_out}{The pre-generated
Monte Carlo estimates generated by
\link[manymome:do_mc]{manymome::do_mc}, stored in
a \code{power4test} object. Users should
not set this argument and should let
\code{\link[=power4test]{power4test()}} to set it automatically.}

\item{boot_ci}{Logical. If \code{TRUE},
the default, nonparametric bootstrap
confidence intervals will be formed.
This argument
and \code{mc_ci} cannot be both \code{TRUE}.}

\item{boot_out}{The pre-generated
bootstrap estimates generated by
\link[manymome:do_boot]{manymome::do_boot}, stored in
a \code{power4test} object. Users should
not set this argument and should let
\code{\link[=power4test]{power4test()}} to set it automatically.}

\item{check_post_check}{Logical. If
\code{TRUE}, the default, and the model
is fitted by \code{lavaan}, the test
will be conducted only if the model
passes the \code{post.check} conducted
by \code{\link[lavaan:lavInspect]{lavaan::lavInspect()}} (with
\code{what = "post.check"}).}

\item{test_method}{The method to do
the test. If \code{"ci"}, then the
confidence interval (e.g., bootstrap
confidence interval) will be used to
do the test. If
\code{"pvalue"}, then asymmetric \emph{p}-value
by Asparouhov & Muthén (2021) will
be used to do the test, and the
confidence interval will not be
computed. If \code{NULL}, its value will
be set to \code{"pvalue"} if the number of
simulated/bootstrap samples (\code{R}) is
a value that is supported by the
method by Boos and Zhang (2000), and
set to \code{"ci"} otherwise.}

\item{...}{Additional arguments to
be passed to \code{\link[manymome:cond_indirect]{manymome::cond_indirect()}}.}

\item{fit_name}{The name of the
model fit object to be extracted.
Default is \code{"fit"}. Used only when
more than one model is fitted in
each replication. This should be
the name of the model on which the
test is to be conducted.}

\item{get_map_names}{Logical. Used
by \code{\link[=power4test]{power4test()}} to determine how
to extract stored information and
assign them to this function. Users
should not use this argument.}

\item{get_test_name}{Logical. Used
by \code{\link[=power4test]{power4test()}} to get the default
name of this test. Users should not
use this argument.}
}
\value{
In its normal usage, it returns
a named numeric vector with the
following elements:
\itemize{
\item \code{est}: The mean of the estimated
indirect effect across datasets.
\item \code{cilo} and \code{cihi}: The means of the
lower and upper limits of the
confidence interval (95\% by
default), respectively.
\item \code{sig}: Whether a test by confidence
interval is significant (\code{1}) or
not significant (\code{0}).
}
}
\description{
Test a conditional
indirect effect
for a \code{power4test} object.
}
\details{
This function is to be used in
\code{\link[=power4test]{power4test()}} for testing a
conditional
indirect effect, by setting it
to the \code{test_fun} argument.

It uses \code{\link[manymome:cond_indirect]{manymome::cond_indirect()}}
to do the test. It can be used on
models fitted by \code{\link[lavaan:sem]{lavaan::sem()}}
or fitted by a sequence of calls
to \code{\link[stats:lm]{stats::lm()}}, although only
nonparametric bootstrap confidence
interval is supported for models
fitted by regression using
\code{\link[stats:lm]{stats::lm()}}.

It can also be used to test
a conditional effect on a direct path
with no mediator. Just omit \code{m} when
calling the function.
}
\examples{

# Specify the model

model_simple_mod <-
"
m ~ x + w + x:w
y ~ m + x
"

# Specify the population values

model_simple_mod_es <-
"
y ~ m: l
y ~ x: n
m ~ x: m
m ~ w: n
m ~ x:w: l
"

# Simulate the data

sim_only <- power4test(nrep = 5,
                       model = model_simple_mod,
                       pop_es = model_simple_mod_es,
                       n = 100,
                       R = 100,
                       do_the_test = FALSE,
                       iseed = 1234)

# Do the test in each replication

test_ind <- power4test(object = sim_only,
                       test_fun = test_cond_indirect,
                       test_args = list(x = "x",
                                        m = "m",
                                        y = "y",
                                        wvalues = c(w = 1),
                                        mc_ci = TRUE))
print(test_ind,
      test_long = TRUE)

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