% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/simulations.R
\name{insurancePlasmodeSim}
\alias{insurancePlasmodeSim}
\title{Insurance Plasmode Simulation for RESI Evaluation}
\usage{
insurancePlasmodeSim(
  nsim = 1000L,
  n.vec = c(50, 100, 200, 500, 1000, 2000, 5000),
  nboot = 500L,
  alpha = 0.05,
  ci.method = c("boot", "normal", "qf", "cf"),
  output.dir = NULL,
  fixed.knots = FALSE,
  mc.cores.settings = 1L,
  mc.cores.reps = 1L
)
}
\arguments{
\item{nsim}{Integer, number of simulation replicates per (setting, \code{n}) cell.
Default 1000. Use 10 for initial testing.}

\item{n.vec}{Integer vector of sample sizes. Default
\code{c(50, 100, 200, 500, 1000, 2000, 5000)}.}

\item{nboot}{Integer, bootstrap replicates per internal \code{\link{resi}} call.
Default 500. Use 10 for initial testing. Ignored when \code{ci.method != "boot"}.}

\item{alpha}{Numeric, CI significance level. Default 0.05.}

\item{ci.method}{Character, CI method passed to \code{\link{resi}}. One of
\code{"boot"} (bootstrap, default), \code{"normal"} (asymptotic truncated-normal),
or \code{"qf"} (asymptotic quadratic-form / Imhof). When \code{ci.method != "boot"},
\code{nboot} is ignored.}

\item{output.dir}{Character, path to the directory where all results are saved.
Created if it does not exist. Defaults to \code{"resiBootSim"},
\code{"resiAsympNormalSim"}, or \code{"resiAsympQFSim"} based on
\code{ci.method} when \code{NULL}.}

\item{fixed.knots}{Logical. If \code{TRUE}, spline knots are fixed at the
empirical tertiles of \code{age} in the full insurance dataset rather than
re-selected by \code{df = 3} in each bootstrap sample. Default \code{FALSE}.}

\item{mc.cores.settings}{Integer, cores for the outer
\code{mclapply} over (setting \eqn{\times} sample size) combinations. Default 1.}

\item{mc.cores.reps}{Integer, cores for the inner \code{mclapply} over simulation
replicates within each (setting, \code{n}) cell. Default 1.}
}
\value{
Invisibly returns the summary metrics \code{data.frame}. Side effects:
\itemize{
  \item \code{output.dir/sim_raw/<setting>_n<n>.rds}: list of per-replicate
    \code{anova} and \code{coefficients} tables.
  \item \code{output.dir/summary_table.rds}: combined metrics table with columns
    \code{model, vcov, n, n_success, table, term, bias, mse, coverage, width}.
}
}
\description{
Runs a plasmode simulation study using the \code{\link{insurance}} dataset to
evaluate RESI confidence interval performance. In each replicate, \code{n}
observations are resampled with replacement from the full insurance dataset
(\emph{N} = 1338). The RESI point estimates from \code{\link{resi_pe}} applied
to the full dataset are treated as the true parameter values for computing bias,
MSE, CI coverage, and CI width.
}
\details{
Two models are evaluated:
\itemize{
  \item \strong{lm}: \code{log10(charges) ~ ns(age, df=3) * sex + bmi + smoker + region}
  \item \strong{glm}: \code{I(charges > 10000) ~ ns(age, df=3) * sex + bmi + smoker + region}
    with \code{family = binomial()}
}
Each model is evaluated under both parametric (\code{vcovfunc = stats::vcov}) and
robust (\code{vcovfunc = sandwich::vcovHC}) variance settings, yielding four
simulation conditions.

Parallelization is via \code{\link[parallel]{mclapply}}, which uses forking and is
not supported on Windows (falls back to sequential evaluation on Windows).
}
\seealso{
\code{\link{simFigures}}, \code{\link{simCompareMethodsFigures}},
  \code{\link{resi}}, \code{\link{resi_pe}}
}
