predict_nlme: Average predictions from several (non)linear models based on...

View source: R/predict_nlme.R

predict_nlmeR Documentation

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 lme

predict function for objects of class gnls

predict function for objects of class gls

Usage

predict_nlme(
  ...,
  criteria = c("AIC", "AICc", "BIC"),
  interval = c("none", "confidence", "prediction", "new-prediction"),
  level = 0.95,
  nsim = 1000,
  plevel = 0,
  newdata = NULL,
  weights
)

predict_lme(
  ...,
  criteria = c("AIC", "AICc", "BIC"),
  interval = c("none", "confidence", "prediction", "new-prediction"),
  level = 0.95,
  nsim = 1000,
  plevel = 0,
  newdata = NULL,
  weights
)

predict_gnls(
  ...,
  criteria = c("AIC", "AICc", "BIC"),
  interval = c("none", "confidence", "prediction", "new-prediction"),
  level = 0.95,
  nsim = 1000,
  plevel = 0,
  newdata = NULL,
  weights
)

predict_gls(
  ...,
  criteria = c("AIC", "AICc", "BIC"),
  interval = c("none", "confidence", "prediction", "new-prediction"),
  level = 0.95,
  nsim = 1000,
  plevel = 0,
  newdata = NULL,
  weights
)

Arguments

...

nlme, lme, gls or gnls objects.

criteria

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

interval

either ‘none’, ‘confidence’ or ‘prediction’. It is also possible to choose ‘new-prediction’, which is a prediction that resamples the random effects (only relevant for ‘lme’ or ‘nlme’ objects.)

level

probability level for the interval (default 0.95)

nsim

number of simulations to perform for intervals. Default 1000.

plevel

parameter level prediction to be passed to prediciton functions.

newdata

new data frame for predictions

weights

vector of weights of the same length as the number of models. It should sum up to one and it will override the information-criteria based weights. The weights should match the order of the models.

Value

numeric vector of the same length as the fitted object.

Note

all the objects should be fitted to the same data. The weights are based on the IC value.

See Also

predict.nlme predict.lme predict.gnls

Examples


## Example
require(ggplot2)
require(nlme)
data(Orange)

## All models should be fitted using Maximum Likelihood
fm.L <- nlme(circumference ~ SSlogis(age, Asym, xmid, scal), 
                random = pdDiag(Asym + xmid + scal ~ 1), 
                method = "ML", data = Orange)
fm.G <- nlme(circumference ~ SSgompertz(age, Asym, b2, b3), 
                random = pdDiag(Asym + b2 + b3 ~ 1), 
                method = "ML", data = Orange)
fm.F <- nlme(circumference ~ SSfpl(age, A, B, xmid, scal), 
                random = pdDiag(A + B + xmid + scal ~ 1), 
                method = "ML", data = Orange)
fm.B <- nlme(circumference ~ SSbg4rp(age, w.max, lt.e, ldtm, ldtb), 
                random = pdDiag(w.max + lt.e + ldtm + ldtb ~ 1), 
                method = "ML", data = Orange)

## Print the table with weights
IC_tab(fm.L, fm.G, fm.F, fm.B)

## Each model prediction is weighted according to their AIC values
prd <- predict_nlme(fm.L, fm.G, fm.F, fm.B)

ggplot(data = Orange, aes(x = age, y = circumference)) + 
  geom_point() + 
  geom_line(aes(y = predict(fm.L, level = 0), color = "Logistic")) +
  geom_line(aes(y = predict(fm.G, level = 0), color = "Gompertz")) +
  geom_line(aes(y = predict(fm.F, level = 0), color = "4P-Logistic")) +  
  geom_line(aes(y = predict(fm.B, level = 0), color = "Beta")) +
  geom_line(aes(y = prd, color = "Avg. Model"), size = 1.2)


nlraa documentation built on July 9, 2023, 6:08 p.m.