pred_with_ci | R Documentation |
Small utility function to append a data.frame
with predictions from a GAM
and include a confidence interval. Various things are customizable.
pred_with_ci(
model,
data,
alpha = 0.05,
label = NULL,
label_label = NULL,
pred_label = "pred",
ci_label = "ci",
ci_types = c("u", "l"),
sep = "_"
)
model |
a fitted GAM |
data |
the data we wish to predict to |
alpha |
the level we want our confidence intervals at |
label |
label for these models (e.g., "model_1") |
label_label |
the column name for the model labels |
pred_label |
the column name for the predictions |
ci_label |
start of the column name for the confidence intervals |
ci_types |
a 2-vector with the suffixes for the confidence intervals (upper then lower) |
sep |
separator between |
By the data
argument (a data.frame
) will be returned with 3 extra
columns, one for the prediction (column name as in pred_label
), then upper
CI (named paste(ci_label, ci_types[1], sep="_")
) and finally the
lower CI (named paste(ci_label, ci_types[2], sep="_")
). If label
and label_label
are non-empty, a column will be added (with name
label_label
) and contents as in label
.
David L Miller
library(mgcvUtils)
# fit something to look at
set.seed(2)
dat <- gamSim(1,n=400,dist="normal",scale=2)
b <- gam(y~s(x0),data=dat)
# adding prediction/ci columns
dat2 <- pred_with_ci(b, dat)
head(dat2)
# add labels, so you can concatenate predictions later for
# plotting with ggplot2
dat3 <- pred_with_ci(b, dat, label="model1", label_label="model_id")
head(dat3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.