Learn R Programming

hopit (version 0.9.0)

boot_hopit: Bootstrapping hopit model

Description

boot_hopit performs the bootstrap of a function dependent on a fitted model. In each of the bootstrap repetitions, a set of new model coefficients is drawn from the multivariate normal distribution, assuming the originally estimated model coefficients (see coef.hopit) as a mean and using the model variance-covariance matrix (see vcov.hopit). The drawn coefficients are then used to calculate the measure of interest using a function delivered by the func parameter.

Usage

boot_hopit(model, data, func, nboot = 500, unlist = TRUE,
  boot.only.latent = TRUE, robust.vcov = TRUE, ...)

Arguments

model

a fitted hopit model.

data

data used to fit the model.

func

a function to be bootstrapped of the form func(model, data, ...).

nboot

a number of bootstrap replicates.

unlist

a logical indicating whether to unlist the boot object.

boot.only.latent

a logical indicating whether to perform the bootstrap on latent variables only.

robust.vcov
...

other parameters passed to the func.

Value

a list with bootstrapped elements.

See Also

percentile_CI, getLevels, getCutPoints, latentIndex, standardiseCoef, hopit.

Examples

Run this code
# NOT RUN {
# DATA
data(healthsurvey)

# the order of response levels decreases from the best health to
# the worst health; hence the hopit() parameter decreasing.levels
# is set to TRUE
levels(healthsurvey$health)

# fit a model
model1 <- hopit(latent.formula = health ~ hypertension + high_cholesterol +
                heart_attack_or_stroke + poor_mobility + very_poor_grip +
                depression + respiratory_problems +
                IADL_problems + obese + diabetes + other_diseases,
              thresh.formula = ~ sex + ageclass + country,
              decreasing.levels = TRUE,
              control = list(trace = FALSE),
              data = healthsurvey)

# Example 1 ---------------------
# bootstrapping cut-points

# a function to be bootstrapped
cutpoints <-  function(model, data) getCutPoints(model, plotf = FALSE)$cutpoints
B <- boot_hopit(model = model1, data = healthsurvey,
                func = cutpoints, nboot = 100)

# calculate lower and upper bounds using the percentile method
cutpoints.CI <- percentile_CI(B)

# print estimated cutpoints and their confidence intervals
cutpoints(model1, healthsurvey)
cutpoints.CI

# Example 2 ---------------------
# bootstrapping differences in health levels

# a function to be bootstrapped
diff_BadHealth <- function(model, data) {
  hl <- getLevels(model = model, formula=~ sex + ageclass, data = data,
                  sep=' ', plotf=FALSE)
  hl$original[,1] + hl$original[,2] - hl$adjusted[,1]- hl$adjusted[,2]
}

# estimate the difference
est.org <- diff_BadHealth(model = model1, data = healthsurvey)

# perform the bootstrap
B <- boot_hopit(model = model1, data = healthsurvey,
                func = diff_BadHealth, nboot = 100)

# calculate lower and upper bounds using the percentile method
est.CI <- percentile_CI(B)

# plot the difference and its (asymmetrical) confidence intervals
pmar <- par('mar'); par(mar = c(9.5,pmar[2:4]))
m <- max(abs(est.CI))
pos <- barplot(est.org, names.arg = names(est.org), las = 3, ylab = 'Original - Adjusted',
               ylim=c(-m, m), density = 20, angle = c(45, -45), col = c('blue', 'orange'))
for (k in seq_along(pos)) lines(c(pos[k,1],pos[k,1]), est.CI[,k], lwd = 2, col = 2)
abline(h = 0); box(); par(mar = pmar)
# }

Run the code above in your browser using DataLab