Built using Zelig version r packageVersion("Zelig")

knitr::opts_knit$set(
    stop_on_error = 2L
)
knitr::opts_chunk$set(
    fig.height = 11,
    fig.width = 7,
    eval = TRUE
)

options(cite = FALSE)

Bootstrapping is often used to obtain a robust estimate of the uncertainty of a parameter due to sampling error.

The normal algorithm that Zelig uses to simulate quantities of interest is a form of the parametric bootstrap. Zelig has an argument, however, to switch to the nonparametric bootstrap. Hereafter, when we say bootstrap, we imply the nonparametric form.

The zelig() bootstrap argument has a default of FALSE, and can be set to TRUE or a numeric value giving the number of bootstrapped datasets to run. If set to TRUE the default is 100 bootstraps. The bootstrap works in combination with other Zelig arguments as follows:

Examples

rm(list=ls(pattern="\\.out"))
suppressWarnings(suppressMessages(library(zeligverse)))
set.seed(1234)

Attach sample data:

data(macro)

Estimate the model, setting the number of bootstrapped datasets to construct:

z.out <- zelig(unem ~ gdp + capmob + trade,
               model = "ls", data = macro, bootstrap = 500)

Summary by default shows the point parameter estimates, with the standard errors generated by the bootstrap.

summary(z.out)

We can instead choose to show the bagging estimator, that is, the average parameter value across all the bootstrapped datasets. Bagging generally trades bias for a reduction in variance that results in lower mean squared error (notably in non-linear models). The bagging estimator can be obtained as:

summary(z.out, bagging = TRUE)

If we want to inspect particular individual results, the subset argument is available:

summary(z.out, subset = 13:15)

If $B$ bootstraps were obtained, the first $B$ results are those models on the bootstrapped data, and the $B+1$ -th result is the model estimated on the original data. The value of $B$ is stored in a field in the Zelig object, named bootstrap.num. In our running example this was 500:

summary(z.out, subset = (z.out$bootstrap.num + 1))


IQSS/Zelig documentation built on Dec. 11, 2023, 1:51 a.m.