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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
\name{mxBootstrap}
\alias{mxBootstrap}
\title{Repeatedly estimate model using resampling with replacement}
\description{
Bootstrapping is used to quantify the variability of parameter estimates.
A new sample is drawn from the model data (uniformly sampling the
original data with replacement). The model is re-fitted to this new
sample. This process is repeated many times. This yields a series of estimates
from these replications which can be used to assess the variability of the parameters.
\emph{note}: \code{mxBootstrap} only bootstraps free model parameters:
To bootstrap algebras, see \code{\link{mxBootstrapEval}}
To report bootstrapped standardized paths in RAM models, \code{mxBootstrap} the model,
and then run through \code{\link{mxBootstrapStdizeRAMpaths}}
}
\usage{
mxBootstrap(model, replications=200, ...,
data=NULL, plan=NULL, verbose=0L,
parallel=TRUE, only=as.integer(NA),
OK=mxOption(model, "Status OK"), checkHess=FALSE, unsafe=FALSE)
}
\arguments{
\item{model}{The MxModel to be run.}
\item{replications}{The number of resampling replications. If
available, replications from prior mxBootstrap invocations will be reused.}
\item{...}{Not used. Forces remaining arguments to be specified by name.}
\item{data}{A character vector of data or model names}
\item{plan}{Deprecated}
\item{verbose}{For levels greater than 0, enables runtime diagnostics}
\item{parallel}{Whether to process the replications in parallel (not yet implemented!)}
\item{only}{When provided, only the given replication from a prior
run of \code{mxBootstrap} will be performed. See details.}
\item{OK}{The set of status code that are considered successful}
\item{checkHess}{Whether to approximate the Hessian in each replication}
\item{unsafe}{A boolean indicating whether to ignore errors.}
}
\details{
By default, all datasets in the given model are resampled
independently. If resampling is desired from only some of
the datasets then the models containing them can be listed in the
\sQuote{data} parameter.
The \code{frequency} column in the \code{\link{mxData}} object is used
represent a resampled dataset. When resampling, the original row
proportions, as given by the original \code{frequency} column, are
respected.
When the model has a default compute plan and \sQuote{checkHess} is
kept at FALSE then the Hessian will not be approximated or checked.
On the other hand, \sQuote{checkHess} is TRUE then the Hessian will be
approximated by finite differences. This procedure is of some value
because it can be informative to check whether the Hessian is positive
definite (see \code{\link{mxComputeHessianQuality}}). However,
approximating the Hessian is often costly in terms of CPU time. For
bootstrapping, the parameter estimates derived from the resampled data
are typically of primary interest.
On occasion, replications will fail. Sometimes it can be helpful to
exactly reproduce a failed replication to attempt to pinpoint the
cause of failure. The \sQuote{only} option facilitates this kind of
investigation. In normal operation, mxBootstrap uses the regular R
random number generator to generate a seed for each replication. This
seed is used to seed an internal pseudorandom number generator
(currently the Mersenne Twister algorithm). These
per-replication seeds are stored as part of the bootstrap output. When
\sQuote{only} is specified, the associated stored seed is used to seed the
internal random number generator so that identical weights can be
regenerated.
\code{mxBootstrap} does not currently offer special support for nested,
multilevel, or other dependent data structures. \emph{\code{mxBootstrap}
assumes rows of data are independent.} Multilevel models and state space
models violate the independence assumption employed by \code{mxBootstrap}.
By default the \code{unsafe} argument prevents multilevel and state space
models from using \code{mxBootstrap}; however, setting \code{unsafe=TRUE}
allows multilevel and state space models to use bootstrapping under the --
perhaps foolish -- assumption that the user is sufficiently knowledgeable to
interpret the results.
}
\value{
The given model is returned with
the compute plan modified to consist of
\code{mxComputeBootstrap}. Results of the bootstrap replications are
stored inside the compute plan. \code{\link{mxSummary}} can be used to
obtain per-parameter quantiles and standard errors.
}
\seealso{
\code{\link{mxBootstrapEval}}, \code{\link{mxComputeBootstrap}},
\code{\link{mxSummary}}, \code{\link{mxBootstrapStdizeRAMpaths}},
\code{\link{as.statusCode}}
}
\examples{
library(OpenMx)
data(multiData1)
manifests <- c("x1", "x2", "y")
biRegModelRaw <- mxModel(
"Regression of y on x1 and x2",
type="RAM",
manifestVars=manifests,
mxPath(from=c("x1","x2"), to="y",
arrows=1,
free=TRUE, values=.2, labels=c("b1", "b2")),
mxPath(from=manifests,
arrows=2,
free=TRUE, values=.8,
labels=c("VarX1", "VarX2", "VarE")),
mxPath(from="x1", to="x2",
arrows=2,
free=TRUE, values=.2,
labels=c("CovX1X2")),
mxPath(from="one", to=manifests,
arrows=1, free=TRUE, values=.1,
labels=c("MeanX1", "MeanX2", "MeanY")),
mxData(observed=multiData1, type="raw"))
biRegModelRawOut <- mxRun(biRegModelRaw)
boot <- mxBootstrap(biRegModelRawOut, 10) # start with 10
summary(boot)
# Looks good, now do the rest
\donttest{boot <- mxBootstrap(boot)}
summary(boot)
# examine replication 3
boot3 <- mxBootstrap(boot, only=3)
print(coef(boot3))
print(boot$compute$output$raw[3,names(coef(boot3))])
}
|