Learn R Programming

nlraa (version 0.98)

predict_gam: 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
type
se.fit

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

terms
exclude
block.size
newdata.guaranteed
na.action
unconditional
iterms.type
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’

See Also

predict.lm, predict.nls, predict.gam, simulate_nls, simulate_gam

Examples

Run this code
# NOT RUN {
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")
  
# }

Run the code above in your browser using DataLab