Compute the posterior mean and variance of h
at a new predictor values
Source: R/ComputePostmeanHnew.R
ComputePostmeanHnew.Rd
Compute the posterior mean and variance of h
at a new predictor values
Usage
ComputePostmeanHnew(
fit,
y = NULL,
Z = NULL,
X = NULL,
Znew = NULL,
sel = NULL,
method = "approx"
)
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.- Znew
matrix of new predictor values at which to predict new
h
, where each row represents a new observation. If set to NULL then will default to using the observed exposures Z.- sel
selects which iterations of the MCMC sampler to use for inference; see details
- 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
Details
If
method == "approx"
, the argumentsel
defaults to the second half of the MCMC iterations.If
method == "exact"
, the argumentsel
defaults to keeping every 10 iterations after dropping the first 50% of samples, or if this results in fewer than 100 iterations, than 100 iterations are kept
For guided examples and additional information, go to https://jenfb.github.io/bkmr/overview.html
Examples
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.01172 secs elapsed)
#> Iteration: 20 (20% completed; 0.01792 secs elapsed)
#> Iteration: 30 (30% completed; 0.02422 secs elapsed)
#> Iteration: 40 (40% completed; 0.0304 secs elapsed)
#> Iteration: 50 (50% completed; 0.03642 secs elapsed)
#> Iteration: 60 (60% completed; 0.04241 secs elapsed)
#> Iteration: 70 (70% completed; 0.04858 secs elapsed)
#> Iteration: 80 (80% completed; 0.0545 secs elapsed)
#> Iteration: 90 (90% completed; 0.06064 secs elapsed)
#> Iteration: 100 (100% completed; 0.0666 secs elapsed)
med_vals <- apply(Z, 2, median)
Znew <- matrix(med_vals, nrow = 1)
h_true <- dat$HFun(Znew)
h_est1 <- ComputePostmeanHnew(fitkm, Znew = Znew, method = "approx")
h_est2 <- ComputePostmeanHnew(fitkm, Znew = Znew, method = "exact")