File: bootstrap_model.Rd

package info (click to toggle)
r-cran-parameters 0.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,852 kB
  • sloc: sh: 16; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 3,103 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bootstrap_model.R
\name{bootstrap_model}
\alias{bootstrap_model}
\alias{bootstrap_model.default}
\title{Model bootstrapping}
\usage{
bootstrap_model(model, iterations = 1000, ...)

\method{bootstrap_model}{default}(
  model,
  iterations = 1000,
  type = "ordinary",
  parallel = "no",
  n_cpus = 1,
  cluster = NULL,
  verbose = FALSE,
  ...
)
}
\arguments{
\item{model}{Statistical model.}

\item{iterations}{The number of draws to simulate/bootstrap.}

\item{...}{Arguments passed to or from other methods.}

\item{type}{Character string specifying the type of bootstrap. For mixed models
of class \code{merMod} or \code{glmmTMB}, may be \code{"parametric"} (default) or
\code{"semiparametric"} (see \code{?lme4::bootMer} for details). For all
other models, see argument \code{sim} in \code{?boot::boot} (defaults to
\code{"ordinary"}).}

\item{parallel}{The type of parallel operation to be used (if any).}

\item{n_cpus}{Number of processes to be used in parallel operation.}

\item{cluster}{Optional cluster when \code{parallel = "snow"}. See \code{?lme4::bootMer}
for details.}

\item{verbose}{Toggle warnings and messages.}
}
\value{
A data frame of bootstrapped estimates.
}
\description{
Bootstrap a statistical model n times to return a data frame of estimates.
}
\details{
By default, \code{boot::boot()} is used to generate bootstraps from
the model data, which are then used to \code{update()} the model, i.e. refit
the model with the bootstrapped samples. For \code{merMod} objects (\strong{lme4})
or models from \strong{glmmTMB}, the \code{lme4::bootMer()} function is used to
obtain bootstrapped samples. \code{bootstrap_parameters()} summarizes the
bootstrapped model estimates.
}
\section{Using with \strong{emmeans}}{

The output can be passed directly to the various functions from the
\strong{emmeans} package, to obtain bootstrapped estimates, contrasts, simple
slopes, etc. and their confidence intervals. These can then be passed to
\code{model_parameter()} to obtain standard errors, p-values, etc. (see
example).

Note that that p-values returned here are estimated under the assumption of
\emph{translation equivariance}: that shape of the sampling distribution is
unaffected by the null being true or not. If this assumption does not hold,
p-values can be biased, and it is suggested to use proper permutation tests
to obtain non-parametric p-values.
}

\examples{
\dontshow{if (require("boot", quietly = TRUE) && require("emmeans", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
\donttest{
model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
b <- bootstrap_model(model)
print(head(b))

est <- emmeans::emmeans(b, consec ~ cyl)
print(model_parameters(est))
}
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link[=bootstrap_parameters]{bootstrap_parameters()}}, \code{\link[=simulate_model]{simulate_model()}}, \code{\link[=simulate_parameters]{simulate_parameters()}}
}