This function performs Monte Carlo sampling of a GAM/GAMM outbreak model.
For each sampled curve, it calls outcomess to calculate scalar outcomes
It then calculates and returns the confidence interval of each scalar outcome
pspline.estimate.scalars(
model,
predictors,
outcomes,
samples = 100,
level = 0.95
)data.frame of predictor values at which the model will be evaluated
function returning calculated scalar outcomes, as described above
number of samples of outcomes to draw
confidence level for estimates
data frame of estimates, as described above
The outcomes function must accept (model, params, predictors) and return a one-row data frame
in which each column lists the value of a single scalar outcome calculated from the model
estimates.
A typical implementation of the outcomes function would call predict on
model and predictors to obtain model variable estimates at predictor values, then
calculate the scalar outcomes of interest and return them in a data frame.
For example, to calculate the time of outbreak peak, you might use this function for outcomes:
calc_peak = function(model, params, time) {
incidence = predict(model, data.frame(time=time), type="response")
data.frame(peak=time[which.max(incidence)])
}
The data frame returned by pspline.estimate.scalars contains three columns for each
outcome calculated by outcomes: for outcome x returned by outcomes,
pspline.estimate.scalars returns columns x.lower, x.median, and x.upper, corresponding
to lower confidence limit, median, and upper confidence limit of x.