predict_gam {nlraa} | R Documentation |
Modified prediciton function based on predict.gam
Description
Largely based on predict.gam, but with some minor modifications to make it compatible
with predict_nls
Usage
predict_gam(
object,
newdata = NULL,
type = "link",
se.fit = TRUE,
terms = NULL,
exclude = NULL,
block.size = NULL,
newdata.guaranteed = FALSE,
na.action = na.pass,
unconditional = FALSE,
iterms.type = NULL,
interval = c("none", "confidence", "prediction"),
level = 0.95,
tvalue = NULL,
...
)
Arguments
object |
object of class ‘gam’ or as returned by function ‘gamm’ |
newdata |
see |
type |
see |
se.fit |
see |
terms |
see |
exclude |
see |
block.size |
see |
newdata.guaranteed |
see |
na.action |
see |
unconditional |
see |
iterms.type |
see |
interval |
either ‘none’, ‘confidence’ or ‘prediction’. |
level |
probability level for the interval (default 0.95) |
tvalue |
t-value statistic used for constructing the intervals |
... |
additional arguments to be passed to |
Value
numeric vector of the same length as the fitted object when interval is equal to ‘none’. Otherwise, a data.frame with columns named (for a 0.95 level) ‘Estimate’, ‘Est.Error’, ‘Q2.5’ and ‘Q97.5’
Note
this is a very simple wrapper for predict.gam
.
See Also
predict.lm
, predict.nls
, predict.gam
, simulate_nls
, simulate_gam
Examples
require(ggplot2)
require(mgcv)
data(barley)
fm.G <- gam(yield ~ s(NF, k = 6), data = barley)
## confidence and prediction intervals
cis <- predict_gam(fm.G, interval = "conf")
pis <- predict_gam(fm.G, interval = "pred")
barleyA.ci <- cbind(barley, cis)
barleyA.pi <- cbind(barley, pis)
ggplot() +
geom_point(data = barleyA.ci, aes(x = NF, y = yield)) +
geom_line(data = barleyA.ci, aes(x = NF, y = Estimate)) +
geom_ribbon(data = barleyA.ci, aes(x = NF, ymin = Q2.5, ymax = Q97.5),
color = "red", alpha = 0.3) +
geom_ribbon(data = barleyA.pi, aes(x = NF, ymin = Q2.5, ymax = Q97.5),
color = "blue", alpha = 0.3) +
ggtitle("95% confidence and prediction bands")