Learn R Programming

itsadug (version 2.0)

get_predictions: Get model predictions for specific conditions.

Description

Get model predictions for specific conditions.

Usage

get_predictions(model, cond = NULL, se = TRUE, f = 1.96,
  rm.ranef = NULL, print.summary = getOption("itsadug_print"))

Arguments

model
A gam object, produced by gam or bam.
cond
A named list of the values to use for the predictor terms. Variables omitted from this list will have the closest observed value to the median for continuous variables, or the reference level for factors.
se
Logical: whether or not to return the confidence interval or standard error around the estimates.
f
A number to scale the standard error. Defaults to 1.96, resulting in 95% confidence intervals. For 99% confidence intervals use a value of 2.58.
rm.ranef
Logical: whether or not to remove random effects. Default is FALSE. Alternatively a vector with numbers (modelterms) of the random effect(s) to remove.
print.summary
Logical: whether or not to print a summary of the values selected for each predictor. Default set to the print info messages option (see infoMessages).

Value

  • A data frame with estimates and optionally errors.

See Also

Other Model predictions: get_coefs, get_difference, get_fitted, get_modelterm, get_random

Examples

Run this code
data(simdat)

m1 <- bam(Y ~ Group + s(Time, by=Group), data=simdat)

# Time value is automatically set:
pp <- get_predictions(m1, cond=list(Group="Adults"))
head(pp)

# Range of time values:
pp <- get_predictions(m1, 
    cond=list(Group="Adults", Time=seq(0,500,length=100)))
# plot:
emptyPlot(500, range(pp$fit), h=0)
plot_error(pp$Time, pp$fit, pp$CI, shade=TRUE, xpd=TRUE)

# Warning: also unrealistical values are possible
range(simdat$Time)
pp <- get_predictions(m1, 
    cond=list(Group="Adults", Time=seq(-500,0,length=100)))
# plot of predictions that are not supported by data:
emptyPlot(c(-500,0), range(pp$fit), h=0)
plot_error(pp$Time, pp$fit, pp$CI, shade=TRUE, xpd=TRUE)

Run the code above in your browser using DataLab