JointAI (version 0.5.1)

predict.JointAI: Predict values from an object of class JointAI

Description

Calculates the expected outcome value for a given set of covariate values and an object of class 'JointAI', and corresponding 2.5% and 97.5% (or other quantiles) credible intervals.

Usage

# S3 method for JointAI
predict(object, newdata, quantiles = c(0.025, 0.975),
  start = NULL, end = NULL, thin = NULL, mess = TRUE, ...)

Arguments

object

object inheriting from class 'JointAI'

newdata

new dataset for prediction

quantiles

quantiles of the predicted distribution of the outcome

start

the first iteration of interest (see window.mcmc)

end

the last iteration of interest (see window.mcmc)

thin

thinning interval (see window.mcmc)

mess

logical; should messages be given? Default is TRUE. Note: this applies only to messages given directly by JointAI.

...

currently not used

Value

A list with entries "fit" and "quantiles", where "fit" contains the column means of \(X\beta\) (see details) and "quantiles" contain the specified quantiles (by default 2.5% and 97.5%) of each column of \(X\beta\).

Details

A model.matrix \(X\) is created from the model formula (fixed effects only) and newdata. \(X\beta\) is then calculated for each iteration of the MCMC sample in object, i.e., \(X\beta\) has n.iter rows and nrow(newdata) columns. A subset of the MCMC sample can be selected using start, end and thin.

See Also

predDF.JointAI, lme_imp, glm_imp, lm_imp

Examples

Run this code
# NOT RUN {
# fit model
mod <- lm_imp(y ~ C1 + C2 + I(C2^2), data = wideDF, n.iter = 100)

# create dataset for prediction
newDF <- predDF(mod, var = "C2")

# obtain predicted values
pred <- predict(mod, newdata = newDF)

# plot predicted values and 95% confidence band
plot(newDF$C2, pred$fit, type = "l", ylim = range(pred$quantiles),
     xlab = "C2", ylab = "predicted values")
matplot(newDF$C2, t(pred$quantiles), lty = 2, add = TRUE, type = "l", col = 1)

# }

Run the code above in your browser using DataLab