# \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