predict.mcdraws {mcmcsae} | R Documentation |
Generate draws from the predictive distribution
Description
Generate draws from the predictive distribution
Usage
## S3 method for class 'mcdraws'
predict(
object,
newdata = NULL,
X. = if (is.null(newdata)) "in-sample" else NULL,
type = c("data", "link", "response", "data_cat"),
var = NULL,
ny = NULL,
ry = NULL,
fun. = identity,
labels = NULL,
ppcheck = FALSE,
iters = NULL,
to.file = FALSE,
filename,
write.single.prec = FALSE,
show.progress = TRUE,
verbose = TRUE,
n.cores = 1L,
cl = NULL,
seed = NULL,
export = NULL,
...
)
Arguments
object |
an object of class |
newdata |
data frame with auxiliary information to be used for prediction. |
X. |
a list of design matrices; alternatively, |
type |
the type of predictions. The default is |
var |
variance(s) used for out-of-sample prediction. By default 1. |
ny |
number of trials used for out-of-sample prediction in case of a binomial model. By default 1. |
ry |
fixed part of the (reciprocal) dispersion parameter in case of a negative binomial model. |
fun. |
function applied to the vector of posterior predictions to compute one or multiple summaries or test statistics. The function can have one or two arguments. The first argument is always the vector of posterior predictions. The optional second argument represents a list of model parameters, needed only when a test statistic depends on them. The function must return an integer or numeric vector. |
labels |
optional names for the output object. Must be a vector of the same length as the result of |
ppcheck |
if |
iters |
iterations in |
to.file |
if |
filename |
name of the file to write predictions to in case |
write.single.prec |
Whether to write to file in single precision. Default is |
show.progress |
whether to show a progress bar. |
verbose |
whether to show informative messages. |
n.cores |
the number of cpu cores to use. Default is one, i.e. no parallel computation.
If an existing cluster |
cl |
an existing cluster can be passed for parallel computation. If |
seed |
a random seed (integer). For parallel computation it is used to independently seed RNG streams for all workers. |
export |
a character vector with names of objects to export to the workers. This may
be needed for parallel execution if expressions in |
... |
currently not used. |
Value
An object of class dc
, containing draws from the posterior (or prior) predictive distribution.
If ppcheck=TRUE
posterior predictive p-values are returned as an additional attribute.
In case to.file=TRUE
the file name used is returned.
Examples
n <- 250
dat <- data.frame(x=runif(n))
dat$y <- 1 + dat$x + rnorm(n)
sampler <- create_sampler(y ~ x, data=dat)
sim <- MCMCsim(sampler)
summary(sim)
# in-sample prediction
pred <- predict(sim, ppcheck=TRUE)
hist(attr(pred, "ppp"))
# out-of-sample prediction
pred <- predict(sim, newdata=data.frame(x=seq(0, 1, by=0.1)))
summary(pred)