predict_gam: Modified prediciton function based on predict.gam

View source: R/predict_nls.R

predict_gamR 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 predict.gam

type

see predict.gam

se.fit

see predict.gam. Notice that the default is changed to TRUE.

terms

see predict.gam

exclude

see predict.gam

block.size

see predict.gam

newdata.guaranteed

see predict.gam

na.action

see predict.gam

unconditional

see predict.gam

iterms.type

see predict.gam

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 predict.gam.

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")
  


nlraa documentation built on May 29, 2024, 2:01 a.m.