Plot cross-sections of the bivariate predictor-response function
Source:R/PredictorResponseFunctions.R
PredictorResponseBivarLevels.Rd
Function to plot the h
function of a particular variable at different levels (quantiles) of a second variable
Usage
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 theh
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 (forh(z2)
at different levels of z1)- z.names
optional vector of names for the columns of
z
Value
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)
#> Iteration: 10 (10% completed; 0.00565 secs elapsed)
#> Iteration: 20 (20% completed; 0.01103 secs elapsed)
#> Iteration: 30 (30% completed; 0.01647 secs elapsed)
#> Iteration: 40 (40% completed; 0.02196 secs elapsed)
#> Iteration: 50 (50% completed; 0.02706 secs elapsed)
#> Iteration: 60 (60% completed; 0.03219 secs elapsed)
#> Iteration: 70 (70% completed; 0.03762 secs elapsed)
#> Iteration: 80 (80% completed; 0.0428 secs elapsed)
#> Iteration: 90 (90% completed; 0.04808 secs elapsed)
#> Iteration: 100 (100% completed; 0.05349 secs elapsed)
## 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)
#> Pair 1 out of 6
#> Pair 2 out of 6
#> Pair 3 out of 6
#> Pair 4 out of 6
#> Pair 5 out of 6
#> Pair 6 out of 6
pred.resp.bivar.levels <- PredictorResponseBivarLevels(pred.resp.df = pred.resp.bivar,
Z = Z, qs = c(0.1, 0.5, 0.9))