boot.cgaim {cgaim}  R Documentation 
Generates bootstrap replicates of a cgaim
object.
boot.cgaim(object, boot.type = c("residuals", "wild", "pairs"),
bsamples = NULL, B = 100, l = 1, nc = 1)
object 
A 
boot.type 
The type of bootstrap to perform. Currently
available type are 
bsamples 
A numerical matrix of observation indices specifying
bootstrap samples.
Rows indicate observations and columns bootstrap samples.
If 
B 
Number of bootstrap samples to generate when 
l 
Block length for blockbootstrap. Samples are generated by
resampling block of observation of length 
nc 
Positive integer. If 
This function fits the cgaim
on bootstrap samples.
It is called internally by the confint.cgaim
function, but can also be
called directly to generate various statistics.
Three types of bootstrap are currently implemented. "residuals"
(the default) resamples the residuals in object
to then be added to fitted values, creating alternative response vectors. The cgaim
is then fitted on these newly generated y values with the original x. "wild"
is
similar except that residuals are multiplied by random draws from a
standard normal distribution before being added to fitted values.
"pairs"
resamples directly pairs of y and x to create
bootstrap samples.
Bootstrap samples can either be prespecified by the user through
bsamples
or generated internally. In the former case,
the columns of bsamples
indicate the number of replications B
and
the rows should match the original number of observations. Internally
generated bootstrap samples are controlled by the number of replications
B
and block length l
, implementing block bootstrap.
The latter is particularly recommended for time series data.
As fitting a large number of cgaim
models can be computationally
intensive, the function can be run in parallel, using the
doParallel
package. This can be done by setting the
argument nc
to a value greater than 1, controlling the number
of cores used in parallelization.
A boot.cgaim
object with components
boot 
The bootstrap result. A list that includes all

obs 
The original 
samples 
The bootstrap samples. A matrix with indices corresponding to original observations. 
boot.type 
The type of bootstrap performed. 
B 
The number of bootstrap replications. 
l 
The block length for block bootstrap. 
# A simple CGAIM
n < 200
x1 < rnorm(n)
x2 < x1 + rnorm(n)
z < x1 + x2
y < z + rnorm(n)
df1 < data.frame(y, x1, x2)
ans < cgaim(y ~ g(x1, x2, acons = list(monotone = 1)), data = df1)
# Use function to compute confidence intervals (B should be increased)
set.seed(1989)
boot1 < boot.cgaim(ans, B = 10)
ci1 < confint(boot1)
# Produces the same result as
set.seed(1989)
ci2 < confint(ans, type = "boot", B = 10)
# Create sampling beforehand
bsamp < matrix(sample(1:n, n * 10, replace = TRUE), n)
boot2 < boot.cgaim(ans, bsamples = bsamp)
# Parallel computing (two cores)
boot3 < boot.cgaim(ans, nc = 2)