1

I'm trying to plot the Worm plot residuals on a model fitted using the gamlss function from the gamlss package. The interest graph looks like the one below: inserir a descrição da imagem aqui

Initially, below is the computational routine referring to the use of the wormplot_gg function from the childsds package, however, the result expressed using the function described above is not looks like the example shown above, which is being applied to a dataset contained within R.

library(ggplot2)
library(gamlss)
library(childsds)

head(Orange)
Dados <- Orange
Model <- gamlss(circumference~age, family=NO,data=Dados); Model
wp(Model)

wormplot_gg(m = Model)

Below are the traditional results via the wp function in the gamlss package.

inserir a descrição da imagem aqui

And finally, we have the results obtained through the wormplot_gg function from the childsds package. However, as already described, this one does not present itself in the way I am interested, that is, with the visual structure of the first figure.

inserir a descrição da imagem aqui

user55546
  • 37
  • 1
  • 15
  • Do you mean that you want the plot to look different? Like the theme and the colors? – TJ Mahr Jun 07 '21 at 18:21
  • I would like to get a graphic with a look and feel of the first image, ie with features from the ````ggplot2```` package. – user55546 Jun 07 '21 at 18:27
  • the source code in childsds::wormplot_gg looks pretty simple (it could be much more complicated). You can remove the theme_minimal() and theme() lines to undo the custom theming and remove the customization in the geom_() lines – TJ Mahr Jun 07 '21 at 19:04
  • So, however, the function doesn't seem to accept some functionality from the ggplot2 package. I saw that you have a site containing the construction of the worm plot in ````ggplot2````, I even tried to reproduce it for my problem but I couldn't. Could you help me build this graph through ggplot2 considering the example in tuning through the ````gamlss```` package?? – user55546 Jun 07 '21 at 19:19

1 Answers1

2

using qqplotr https://aloy.github.io/qqplotr/index.html with the detrend=True option

library(qqplotr)
set.seed(1)
df <- data.frame(z=rnorm(50))

ggplot(df, aes(sample=z)) +
  stat_qq_point(detrend = T) +
  stat_qq_band(detrend = T, color='black', fill=NA, size=0.5)

enter image description here

you can also add geom_hline(yintercept = 0)

edit: In the case of using this with a gamlss model, the first have to extract the randomized residuals out of the model, which for gamlss is done simply with the function residuals, so you can just do e.g., df <- data.frame(z=residuals(Model)) and then just continue with the rest of the code

user2173836
  • 1,461
  • 2
  • 15
  • 19
  • Helo! I would like to know how it would be done through the adjustment considering a gamlss model... could you edit your answer considering the above case? – user55546 Jun 13 '21 at 22:39
  • sorry, i don't know what you mean. what template? – user2173836 Jun 13 '21 at 22:39
  • I would like to perform the wormplot based on the results of the model adjusted via the gamlss function. Sorry! I expressed myself incorrectly. – user55546 Jun 13 '21 at 22:39
  • Note that the wormplot performed above is based on the adjustment of a gamls model.. – user55546 Jun 13 '21 at 22:45