PredictorResponseBivarLevels function

Plot cross-sections of the bivariate predictor-response function

Plot cross-sections of the bivariate predictor-response function

Function to plot the h function of a particular variable at different levels (quantiles) of a second variable

PredictorResponseBivarLevels( pred.resp.df, Z = NULL, qs = c(0.25, 0.5, 0.75), both_pairs = TRUE, z.names = NULL )

Arguments

  • pred.resp.df: object obtained from running the function PredictorResponseBivar
  • Z: an n-by-M matrix of predictor variables to be included in the h function. Each row represents an observation and each column represents an predictor.
  • qs: vector of quantiles at which to fix the second variable
  • both_pairs: flag indicating whether, if h(z1) is being plotted for z2 fixed at different levels, that they should be plotted in the reverse order as well (for h(z2) at different levels of z1)
  • z.names: optional vector of names for the columns of z

Returns

a long data frame with the name of the first predictor, the name of the second predictor, the value of the first predictor, the quantile at which the second predictor is fixed, the posterior mean estimate, and the posterior standard deviation of the estimated exposure response function

Details

For guided examples, go to https://jenfb.github.io/bkmr/overview.html

Examples

## First generate dataset set.seed(111) dat <- SimData(n = 50, M = 4) y <- dat$y Z <- dat$Z X <- dat$X ## Fit model with component-wise variable selection ## Using only 100 iterations to make example run quickly ## Typically should use a large number of iterations for inference set.seed(111) fitkm <- kmbayes(y = y, Z = Z, X = X, iter = 100, verbose = FALSE, varsel = TRUE) ## Obtain predicted value on new grid of points for each pair of predictors ## Using only a 10-by-10 point grid to make example run quickly pred.resp.bivar <- PredictorResponseBivar(fit = fitkm, min.plot.dist = 1, ngrid = 10) pred.resp.bivar.levels <- PredictorResponseBivarLevels(pred.resp.df = pred.resp.bivar, Z = Z, qs = c(0.1, 0.5, 0.9))
  • Maintainer: Jennifer F. Bobb
  • License: GPL-2
  • Last published: 2022-03-28