简体   繁体   English

Residual(model) Diagnostics for within-between regression model using wbm() function of panelr package in R

[英]Residual(model) Diagnostics for within-between regression model using wbm() function of panelr package in R

I am using the wbm() from the panelr package by Prof Long ( https://panelr.jacob-long.com/articles/wbm.html ) to fit a within-between (mixed-effects) model. I am using the wbm() from the panelr package by Prof Long ( https://panelr.jacob-long.com/articles/wbm.html ) to fit a within-between (mixed-effects) model.

I wanted to find out how to do residual or model diagnostics.我想了解如何进行残差或 model 诊断。 For example, fitting a model with betareg in r , the following chunk of code gives me the following plots例如,在 r 中安装带有betaregr ,下面的代码块给了我下面的图

par(mfrow=c(3,2))
plot(fit1, which = 1:4, type = "pearson")
plot(fit1, which = 5, type = "deviance", sub.caption = "")
plot(fit1, which = 1, type = "deviance", sub.caption = "")

在此处输入图像描述 . .

But when I run the regression (model named fit3) using wbm() and I run the code to get the diagnostics plots但是当我使用wbm()运行回归(名为 fit3 的模型)并运行代码以获取诊断图时

par(mfrow=c(3,2))
plot(fit3, which = 1:4, type = "pearson")
plot(fit3, which = 5, type = "deviance", sub.caption = "")
plot(fit3, which = 1, type = "deviance", sub.caption = "")

I got the following image我得到了以下图像在此处输入图像描述

EDIT Below is a MWE based on data from the package:编辑以下是基于 package 数据的 MWE:

#Load Package
library(panelr)

#Load teen_poverty data from package
data("WageData")
head(WageData)


#Declare data as panel
Wages <- panel_data(WageData, id = id, wave = t)
Wages

#Run a "contextual" model

fit3 <- wbm(lwage ~ wks + union + ms + occ | blk + fem, data = Wages, model = "contextual")
summary(fit3)

#Model/Residual Diagnostics
par(mfrow=c(3,2))
plot(fit3, which = 1:4, type = "pearson")
plot(fit3, which = 5, type = "deviance", sub.caption = "")
plot(fit3, which = 1, type = "deviance", sub.caption = "")

I would be grateful if someone could help direct me as to how I can get the appropriate plots when I run a model using wbm() ?如果有人可以帮助指导我在使用wbm()运行 model 时如何获得适当的绘图,我将不胜感激?

Thank you.谢谢你。

Here is how you could make each of the plots:以下是制作每个图的方法:

## Residuals vs index: 
plot(residuals(fit3))

## Cook's Distance
plot(cooks.distance(fit3), type="n")
cdist <- cooks.distance(fit3)
segments(1:length(cdist), 0, 1:length(cdist), cdist)

## leverage vs fitted
plot(fitted(fit3), hatvalues(fit3))

## residuals vs linear predictor
plot(fitted(fit3), residuals(fit3))

## normal quantiles
qqnorm(residuals(fit3))
## or 
car::qqPlot(residuals(fit3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM