【问题标题】:cooks distance plot with R用 R 烹饪距离图
【发布时间】:2011-09-03 14:00:12
【问题描述】:

有谁知道,如何获取从这段代码中得到的单个厨师距离图:

treatment <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2), labels = c("placebo","treated"))
improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)), levels = c(1, 2,3),labels = c("none", "some", "marked"))
numberofdrugs <- rpois(84, 5)+1
healthvalue <- rpois(84,5)
y <- data.frame(healthvalue, numberofdrugs, treatment, improved)
test <- glm(healthvalue~numberofdrugs+treatment+improved, y, family=poisson)
par(mfrow=c(2,2))
plot(test) # how to grab plot 2.1 ?

我不喜欢的是这个

par(mfrow=c(1, 1))
plot(test, which=c(4))

因为它在 y 轴上没有残差,在 x 轴上没有杠杆!

谢谢大家

【问题讨论】:

  • 你不能把你想要的诊断图向量传递给which=吗?

标签: r statistics outliers


【解决方案1】:

我不太确定您的问题是什么。您似乎想要在 y 轴上带有残差并在 x 轴上利用的绘图。这不只是生成的第 5 个(共 6 个)图吗:

plot(test,which=5)

您可以在 ?plot.lm 阅读更多相关信息

编辑以解决 OP 关于设置 y 轴标签的问题:

通常,只需在 plot() 调用中添加 ylab="My Label" 即可,但这些图表设计为“自动”生成,因此某些图形参数是“硬编码”的。如果你传递你自己的 ylab 值,你会得到一个错误,因为 plot.lm() 将显示两个 ylab 并且不知道使用哪一个。如果您真的不喜欢 y 轴标签,您唯一的选择是获取 plot.lm 代码(只需在控制台输入“plot.lm”并按回车键)复制并粘贴它进入文本文件并查找此部分:

if (show[5L]) {
    ylab5 <- if (isGlm) 
        "Std. Pearson resid."
    else "Standardized residuals"
    r.w <- residuals(x, "pearson")
    if (!is.null(w)) 
        r.w <- r.w[wind]
    rsp <- dropInf(r.w/(s * sqrt(1 - hii)), hii)
    ylim <- range(rsp, na.rm = TRUE)
    if (id.n > 0) {
        ylim <- extendrange(r = ylim, f = 0.08)
        show.rsp <- order(-cook)[iid]
    }

并使用您自己的 y 轴标签对其进行修改。重命名该函数(例如,plotLMCustomY 或其他名称),它应该可以工作。

【讨论】:

  • 你需要 plot(test,which=5,caption=""),直到你问我才知道。我只是在 ?plot.lm 中查找它。仔细阅读 ?plot.lm。
  • 谢谢!我的英语不是很好,所以我经常看不到这些东西:)
  • 再一次......对不起!但我绝对不知道如何更改 ylabs 的名称......“?plot.lm”没有回答这个问题!
  • 没问题;编辑了我的答案以解决 ylab 问题。希望对您有所帮助!
  • 再一次 :D 我更改了 y 轴标签,但不幸的是似乎无法摆脱平方根符号。因此,当我将轴命名为“hello”时,它会显示 squarerootsign(hello)...(我说的是这个图:'plot(test,which=2)')
猜你喜欢
  • 2011-07-03
  • 1970-01-01
  • 2010-11-04
  • 1970-01-01
  • 2017-07-10
  • 2011-09-24
  • 1970-01-01
  • 2021-01-22
  • 1970-01-01
相关资源
最近更新 更多