I have fitted a few models to the same data. And have plotted the predction lines for all models in a single plot.
Now I'd like to highlight (in bold, thicker line) the prediction line of the model with the lowest AIC. Can't seem to find resources on this, so I'm a bit stuck.
library(ggplot2)
set.seed(101)
x <- rnorm(100)
y <- rweibull(100,1)
d <- data.frame(x,y)
model1 <- lm(y~1, data = d)
model2 <- lm(y~x, data = d)
model3 <- lm(y~abs(x), data = d)
newvalsforx <- function(x) {
xrng <- seq(min(x), max(x), length.out=100)
function(m) data.frame(x=xrng, y=predict(m, data.frame(x=xrng)))
}
pred <- newvalsforx(d$x)
ggplot(d, aes(x,y)) +
geom_point() +
geom_line(data=pred(model1), color="red") +
geom_line(data=pred(model2), color="blue") +
geom_line(data=pred(model3), color="green")
AIC1 <- AIC(model1
AIC2 <- AIC(model2)
AIC3 <- AIC(model3)
UPDATE
this is the full list of models I work with
abs.x <- abs(x)
ipos <- (x>0)
models <- list("model1" = lm(y~1, data = d),
"model2" = lm(y~x, data = d),
"model3" = lm(y~abs(x), data = d),
"model4" = lm(y~abs.x + ipos, data = d),
"model5" = lm(y~abs.x : ipos, data = d),
"model6" = lm(y~abs.x * ipos, data = d),
"model7" = mgcv::gam(y ~ abs.x + ipos, data = d)
)