Learn R Programming

nlraa (version 1.2)

predict_nls: Average predictions from several (non)linear models based on IC weights

Description

Computes weights based on AIC, AICc, or BIC and it generates weighted predictions by the relative value of the IC values

predict function for objects of class gam

Usage

predict_nls(
  ...,
  criteria = c("AIC", "AICc", "BIC"),
  interval = c("none", "confidence", "prediction"),
  level = 0.95,
  nsim = 1000,
  resid.type = c("none", "resample", "normal", "wild"),
  newdata = NULL
)

predict2_gam( ..., criteria = c("AIC", "AICc", "BIC"), interval = c("none", "confidence", "prediction"), level = 0.95, nsim = 1000, resid.type = c("none", "resample", "normal", "wild"), newdata = NULL )

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’

Arguments

...

‘nls’ or ‘lm’ objects (‘glm’ and ‘gam’ objects inherit ‘lm’).

criteria

either ‘AIC’, ‘AICc’ or ‘BIC’.

interval

either ‘none’, ‘confidence’ or ‘prediction’.

level

probability level for the interval (default 0.95)

nsim

number of simulations to perform for intervals. Default 1000.

resid.type

either ‘none’, “resample”, “normal” or “wild”.

newdata

new data frame for predictions

See Also

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

Examples

Run this code
# \donttest{
## Example
require(ggplot2)
require(mgcv)
data(barley, package = "nlraa")

fm.L <- lm(yield ~ NF, data = barley)
fm.Q <- lm(yield ~ NF + I(NF^2), data = barley)
fm.A <- nls(yield ~ SSasymp(NF, Asym, R0, lrc), data = barley)
fm.LP <- nls(yield ~ SSlinp(NF, a, b, xs), data = barley)
fm.QP <- nls(yield ~ SSquadp3(NF, a, b, c), data = barley)
fm.BL <- nls(yield ~ SSblin(NF, a, b, xs, c), data = barley)
fm.G <- gam(yield ~ s(NF, k = 6), data = barley)

## Print the table with weights
IC_tab(fm.L, fm.Q, fm.A, fm.LP, fm.QP, fm.BL, fm.G)

## Each model prediction is weighted according to their AIC values
prd <- predict_nls(fm.L, fm.Q, fm.A, fm.LP, fm.QP, fm.BL, fm.G)

ggplot(data = barley, aes(x = NF, y = yield)) + 
  geom_point() + 
  geom_line(aes(y = fitted(fm.L), color = "Linear")) +
  geom_line(aes(y = fitted(fm.Q), color = "Quadratic")) +
  geom_line(aes(y = fitted(fm.A), color = "Asymptotic")) +  
  geom_line(aes(y = fitted(fm.LP), color = "Linear-plateau")) + 
  geom_line(aes(y = fitted(fm.QP), color = "Quadratic-plateau")) + 
  geom_line(aes(y = fitted(fm.BL), color = "Bi-linear")) + 
  geom_line(aes(y = fitted(fm.G), color = "GAM")) + 
  geom_line(aes(y = prd, color = "Avg. Model"), size = 1.2)
# }

Run the code above in your browser using DataLab