0

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. For example, fitting a model with betareg in r, the following chunk of code gives me the following plots

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 = "")

enter image description here.

But when I run the regression (model named fit3) using wbm() and I run the code to get the diagnostics plots

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 enter image description here

EDIT Below is a MWE based on data from the package:

#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()?

Thank you.

Lomnewton
  • 35
  • 6
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 03 '21 at 08:45

1 Answers1

0

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))
DaveArmstrong
  • 18,377
  • 2
  • 13
  • 25