【问题标题】:How to generate a plot of residuals versus predictor variable for a mixed model? [closed]如何为混合模型生成残差与预测变量的关系图? [关闭]
【发布时间】:2013-03-08 20:22:59
【问题描述】:

我的混合模型如下:

model <- lme(Cost~1+Units, random=~1+Units|Factory, method="ML", data=A)

有人告诉我应用下面的代码来绘制残差与拟合值的关系图,它奏效了:

plot(fitted(model), resid(model))

但是,当我尝试绘制残差与预测变量单位的关系时,它显示了一条错误消息。

> plot(Units(model), resid(model))
Error: could not find function "Units"
Error in plot(Units(model), resid(model)) : 
error in evaluating the argument 'x' in selecting a method for function 'plot'

我应该怎么做才能解决这个问题?谢谢。

【问题讨论】:

    标签: r statistics hierarchical-clustering mixed-models


    【解决方案1】:

    我将扩展@Didzis 的评论(这当然是真的),所以你会真正了解发生了什么。 Units 是您数据中的一个变量,而不是像 residualsfitted values 这样的某种变量的特定名称(尽管一般单位确实具有这种含义......),所以没有任何现成的功能这给了你那些。在构建模型时,您已经在第一行代码中使用了 Units:您使用了参数 data 和值 A,它告诉 lme 函数,您在建模中使用的变量位于名为 @987654327 的数据框内@。

    您可以使用美元符号$ 和要提取的变量名称访问数据框中的变量(您可以使用函数names(A) 检查名称)。因此,您可以使用命令 A$Units 获取 Units 变量,因此您可以使用命令绘制 Units 变量与残差的关系

    plot(A$Units,resid(model))
    

    【讨论】:

    • 感谢您的详细解释。
    猜你喜欢
    • 2020-10-22
    • 1970-01-01
    • 2011-03-22
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 2016-06-16
    • 1970-01-01
    相关资源
    最近更新 更多