ggplot2中的蠕虫图残差

ggplot2中的蠕虫图残差

本文介绍了ggplot2中的蠕虫图残差图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在使用 gamlss 包中的 gamlss 函数拟合的模型上绘制蠕虫图残差.兴趣图如下所示:

最初,下面是参考使用 childsds 包中的 wormplot_gg 函数的计算例程,但是,使用上述函数表达的结果并不是看起来就像上面显示的例子一样,它被应用于包含在 R 中的数据集.

库(ggplot2)图书馆(无游戏)图书馆(childsds)头(橙色)Dados <- 橙色模型 <- gamlss(circumference~age, family=NO,data=Dados);模型wp(型号)wormplot_gg(m = 模型)

以下是通过 gamlss 包中的 wp 函数得到的传统结果.

最后,我们通过 childsds 包中的 wormplot_gg 函数获得了结果.然而,正如已经描述的那样,这幅画并没有以我感兴趣的方式呈现,即第一个图的视觉结构.

解决方案

using qqplotr

你也可以添加geom_hline(yintercept = 0)

在将它与 gamlss 模型一起使用的情况下,首先必须从模型中提取随机残差,对于 gamlss 只需使用函数 residuals 即可完成,因此您可以执行例如 df <- data.frame(z=residuals(Model)) 然后继续剩下的代码

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:

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.

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.

解决方案

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)

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

这篇关于ggplot2中的蠕虫图残差图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:29