制作残差 QQ 图时的错误消息 (lmer)

Error message when making QQ plots of residuals (lmer)

有谁知道在尝试制作残差、数据和以下代码的 QQ 图时如何解决此错误;

head(final_data)
              Country             Continent Life_Expectancy 
1         Afghanistan Eastern Mediterranean        62.68935                         
2             Albania                Europe        76.37373                         
3             Algeria                Africa        76.36365                      
4              Angola                Africa        62.63262                       
5 Antigua and Barbuda              Americas        74.99754                       
6           Argentina              Americas        76.94621                        

mod6 = lmer(Life_Expectancy ~ Concentration_of_PM2.5 + 
            (1|Continent),
     data=final_data)

res5 = data.frame(Residuals=resid(mod5),
              Continent=final_data$Continent,
              Fitted=fitted(mod5))

qq_plot6 = ggplot(final_data, aes(sample = mod6$residuals)) + 
  geom_qq() +
  geom_qq_line(col = 'red') +
  xlab('Theoretical residuals') +
  ylab('Sample residuals') +
  ggtitle('QQ plot for residual mod6') +
  theme(plot.title = element_text(hjust = 0.5))

我这里做QQ图的时候出现这个错误:

Error in mod6$residuals : $ operator not defined for this S4 class

merMod 对象(lmer 拟合的结果)不是列表(它们是 S4 对象)并且没有 $residuals 元素。尝试 residuals(mod6) 代替;无论如何,使用访问器方法(不依赖于模型对象的内部结构)总是更好的做法。

另请参阅:broom.mixed::augment()lattice::qqmath(mod6)performance::check_model(mod6)