Obtains posterior samples of E(Y) = h(Znew) + beta*Xnew
or of g^{-1}[E(y)]
Usage
SamplePred(
fit,
Znew = NULL,
Xnew = NULL,
Z = NULL,
X = NULL,
y = NULL,
sel = NULL,
type = c("link", "response"),
...
)
Arguments
- fit
An object containing the results returned by a the
kmbayes
function- Znew
optional matrix of new predictor values at which to predict new
h
, where each row represents a new observation. If not specified, defaults to using observed Z values- Xnew
optional matrix of new covariate values at which to obtain predictions. If not specified, defaults to using observed X values
- 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.- y
a vector of outcome data of length
n
.- sel
A vector selecting which iterations of the BKMR fit should be retained for inference. If not specified, will default 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
- type
whether to make predictions on the scale of the link or of the response; only relevant for the binomial outcome family
- ...
other arguments; not currently used
Details
For guided examples, 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.0048 secs elapsed)
#> Iteration: 20 (20% completed; 0.01003 secs elapsed)
#> Iteration: 30 (30% completed; 0.01548 secs elapsed)
#> Iteration: 40 (40% completed; 0.02063 secs elapsed)
#> Iteration: 50 (50% completed; 0.02591 secs elapsed)
#> Iteration: 60 (60% completed; 0.03113 secs elapsed)
#> Iteration: 70 (70% completed; 0.03625 secs elapsed)
#> Iteration: 80 (80% completed; 0.04167 secs elapsed)
#> Iteration: 90 (90% completed; 0.04699 secs elapsed)
#> Iteration: 100 (100% completed; 0.0523 secs elapsed)
med_vals <- apply(Z, 2, median)
Znew <- matrix(med_vals, nrow = 1)
h_true <- dat$HFun(Znew)
set.seed(111)
samps3 <- SamplePred(fitkm, Znew = Znew, Xnew = cbind(0))
head(samps3)
#> znew1
#> iter51 2.406482
#> iter52 1.934470
#> iter53 2.018921
#> iter54 1.440331
#> iter55 2.047760
#> iter56 1.907901