Predict the exposure-response function at a new grid of points
Source:R/PredictorResponseFunctions.R
PredictorResponseBivar.Rd
Predict the exposure-response function at a new grid of points
Usage
PredictorResponseBivar(
fit,
y = NULL,
Z = NULL,
X = NULL,
z.pairs = NULL,
method = "approx",
ngrid = 50,
q.fixed = 0.5,
sel = NULL,
min.plot.dist = 0.5,
center = TRUE,
z.names = colnames(Z),
verbose = TRUE,
...
)
Arguments
- fit
An object containing the results returned by a the
kmbayes
function- y
a vector of outcome data of length
n
.- 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.- X
an
n
-by-K
matrix of covariate data where each row represents an observation and each column represents a covariate. Should not contain an intercept column.- z.pairs
data frame showing which pairs of predictors to plot
- method
method for obtaining posterior summaries at a vector of new points. Options are "approx" and "exact"; defaults to "approx", which is faster particularly for large datasets; see details
- ngrid
number of grid points in each dimension
- q.fixed
vector of quantiles at which to fix the remaining predictors in
Z
- sel
logical expression indicating samples to keep; defaults to keeping the second half of all samples
- min.plot.dist
specifies a minimum distance that a new grid point needs to be from an observed data point in order to compute the prediction; points further than this will not be computed
- center
flag for whether to scale the exposure-response function to have mean zero
- z.names
optional vector of names for the columns of
z
- verbose
TRUE or FALSE: flag of whether to print intermediate output to the screen
- ...
other arguments to pass on to the prediction function
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 value of the second predictor, 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.00502 secs elapsed)
#> Iteration: 20 (20% completed; 0.01044 secs elapsed)
#> Iteration: 30 (30% completed; 0.01566 secs elapsed)
#> Iteration: 40 (40% completed; 0.02103 secs elapsed)
#> Iteration: 50 (50% completed; 0.02629 secs elapsed)
#> Iteration: 60 (60% completed; 0.03166 secs elapsed)
#> Iteration: 70 (70% completed; 0.03695 secs elapsed)
#> Iteration: 80 (80% completed; 0.04223 secs elapsed)
#> Iteration: 90 (90% completed; 0.04742 secs elapsed)
#> Iteration: 100 (100% completed; 0.06095 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