coefbootstrap: Bootstrap for parameters of models

View source: R/coefbootstrap.R

coefbootstrapR Documentation

Bootstrap for parameters of models

Description

The function does the bootstrap for parameters of models and returns covariance matrix together with the original bootstrapped data.

Usage

coefbootstrap(object, nsim = 1000, size = floor(0.75 * nobs(object)),
  replace = FALSE, prob = NULL, parallel = FALSE, method = c("dsr",
  "cr"), ...)

## S3 method for class 'lm'
coefbootstrap(object, nsim = 1000, size = floor(0.75 *
  nobs(object)), replace = FALSE, prob = NULL, parallel = FALSE,
  method = c("dsr", "cr"), ...)

## S3 method for class 'alm'
coefbootstrap(object, nsim = 1000, size = floor(0.75 *
  nobs(object)), replace = FALSE, prob = NULL, parallel = FALSE,
  method = c("dsr", "cr"), ...)

Arguments

object

The model estimated using either lm, or alm, or glm.

nsim

Number of iterations (simulations) to run.

size

A non-negative integer giving the number of items to choose (the sample size), passed to sample function in R. If not provided and model contains ARIMA components, this value will be selected at random on each iteration. This is only used for method="cr".

replace

Should sampling be with replacement? Also, passed to sample function in R. Only used in method="cr".

prob

A vector of probability weights for obtaining the elements of the vector being sampled. This is passed to the sample as well. Only used with method="cr".

parallel

Either a logical, specifying whether to do the calculations in parallel, or the number, specifying the number of cores to use for the parallel calculation.

method

Which bootstrap method to use. Currently two options are supported: "dsr" - "Data Shape Replication, implemented in dsrboot; "cr" - "Case Resampling", basic bootstrap that assumes that observations are independent (not suitable for models with ARIMA elements).

...

Parameters passed to the dsrboot function.

Details

The function applies the same model as in the provided object on a smaller sample in order to get the estimates of parameters and capture the uncertainty about them. This is a simple implementation of the case resampling, which assumes that the observations are independent.

Value

Class "bootstrap" is returned, which contains:

  • vcov - the covariance matrix of parameters;

  • coefficients - the matrix with the bootstrapped coefficients.

  • nsim - number of runs done;

  • size - the sample size used in the bootstrap;

  • replace - whether the sampling was done with replacement;

  • prob - a vector of probability weights used in the process;

  • parallel - whether the calculations were done in parallel;

  • model - the name of the model used (the name of the function);

  • timeElapsed - the time that was spend on the calculations.

Author(s)

Ivan Svetunkov, ivan@svetunkov.com

See Also

alm

Examples

# An example with ALM
ourModel <- alm(mpg~., mtcars, distribution="dlnorm", loss="HAM")
# A fast example with 10 iterations. Use at least 100 to get better results
coefbootstrap(ourModel, nsim=10)


config-i1/greybox documentation built on Dec. 12, 2024, 1:42 p.m.