cooks距离图与R

cooks距离图与R,r,statistics,outliers,R,Statistics,Outliers,有谁知道,如何获取从以下代码中获得的单个cooks距离图: 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", "ma

有谁知道,如何获取从以下代码中获得的单个cooks距离图:

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 ?
因为它在y轴上没有残差,在x轴上没有杠杆


谢谢大家

我不太确定你们有什么问题。您似乎希望在y轴上绘制残差,在x轴上绘制杠杆。这不正是第五个(共6个)生成的绘图吗:

plot(test,which=5)
您可以在?plot.lm上阅读更多关于此的信息

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

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

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]
    }
if(显示[5L]){

ylab5难道你不能只传递你想要的诊断图向量吗?
which=
?你需要绘图(test,which=5,caption=”“),直到你问我才知道。我只是在?plot.lm.仔细阅读?plot.lm.谢谢你!我的英语不是很好,所以我经常看不到这些东西:)再说一遍…对不起!但我绝对不知道如何更改ylab的名称…“?plot.lm”没有回答这个问题!没问题;编辑了我对a的回答解决ylab问题。希望有帮助!再说一遍:D我更改了y轴标签,但不幸的是,似乎不可能去掉平方根符号。因此,当我将轴命名为“hello”时,它显示平方根符号(hello)…(我指的是这个图:'plot(test,它=2)')
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]
    }