Worm plot residuals graph in ggplot2

808 views Asked by At

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

1

There are 1 answers

4
user2173836 On BEST ANSWER

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