Predict plot for adjusted Gamlss model

Asked

Viewed 106 times

0

How do I make and plot the predict for this model Gamlss adjusted?

My model is presented below.

mod<- gamlss(cbind(nfr, nv-nfr)~tt+tr1+d2+d3+random(as.factor(p ))+random(as.factor(id))+random(as.factor(no)), 
        data=ta, family = "BI")

1 answer

2


Following the example of book "Flexible Regression and Smoothing Using GAMLSS in R", the Plot of the predicted values, adjusted, can be done by following the example below.

library(gamlss)
library(dplyr)
library(ggplot2)
data(film90)

# plot das observacoes
plot(lborev1~lboopen, data = film90, col = "lightblue")

inserir a descrição da imagem aqui

model <- gamlss(lborev1~pb(lboopen), data = film90, family = NO)

# plot das observacoes + valores ajustados
plot(lborev1~lboopen, col = "lightgreen", data = film90)
lines(fitted(model)[order(film90$lboopen)]~
        film90$lboopen[order(film90$lboopen)], col = "red", lwd = 2)

inserir a descrição da imagem aqui

film90 <- film90 %>% 
  dplyr::mutate(lb2 = lboopen^2,
                lb3 = lboopen^3)
model2 <- gamlss(lborev1~lboopen + lb2 + lb3, data=film90, family=NO)

plot(lborev1~lboopen, col = "lightgreen", data = film90)
lines(fitted(model2)[order(film90$lboopen)]~
        film90$lboopen[order(film90$lboopen)], col = "grey10", lwd = 2)

inserir a descrição da imagem aqui

{
  plot(lborev1~lboopen, col = "lightgreen", data = film90)
  lines(fitted(model)[order(film90$lboopen)]~
          film90$lboopen[order(film90$lboopen)], col = "red", lwd = 2)
  lines(fitted(model2)[order(film90$lboopen)]~
          film90$lboopen[order(film90$lboopen)], col = "grey10", lwd = 2)
}

inserir a descrição da imagem aqui

It is also possible to plot using the ggplot2.

ggplot2::ggplot(film90) +
  geom_point(aes(x = lboopen, y = lborev1), col = "lightgreen", alpha = 0.5) +
  geom_line(aes(x = film90$lboopen[order(film90$lboopen)],
                y = fitted(model)[order(film90$lboopen)]), col = "red") +
  geom_line(aes(x = film90$lboopen[order(film90$lboopen)],
                y = fitted(model2)[order(film90$lboopen)]), col = "black") +
  scale_y_continuous(limits = c(4, 20),
                     expand = c(0, 0)) +
  theme_minimal()

inserir a descrição da imagem aqui

As your example is not fully reproducible, I adapted a little this book. But I believe you will not have problems to adapt to your case.

term.plot(model2, pages = 1, partial = T)

inserir a descrição da imagem aqui

Further examples of employment of term.plot() can be found here or here..

  • It is up to you. It can depend on the number of models you have and the "dataviz", so your chart does not get polluted.

  • De nd! I will edit and put more graphic elements. If you can accept the answer, thank you.

  • I put too much information

Browser other questions tagged

You are not signed in. Login or sign up in order to post.