简体   繁体   English

绘图错误-半正态图[

[英]plotting error - halfnormal plot [

Hopefully this is a straight-forward question. 希望这是一个简单的问题。 I'm not sure where there error is--it seems like a R is not working here. 我不确定哪里有错误-似乎R在这里不起作用。 I've restarted R and reproduced the error, so I'm not sure what's going on. 我已经重新启动R并重现了该错误,所以我不确定发生了什么。

Problem: I have some data, and am trying to produce a halfnormal plot for the effects. 问题:我有一些数据,并且正在尝试为效果生成一个半正态图。 Ho-hum, everything's going fine... except the most significant effect isn't showing up in my half normal plot: 哼哼,一切都很好...除了最明显的效果没有出现在我的一半正常情节中:

# load data
dat2 <- read.table("http://www.stat.ucla.edu/~hqxu/stat201A/data/solder2.dat")
# required library
library(faraway)
# rename vars
names(dat2) <- tolower(names(dat2))
# create full model
a1.1 <- aov(defects ~ a + b + c + d + e + f + g + h + a:b + a:e + a:f + a:g + a:h +
              b:f + b:g + b:h + c:f + c:g + c:h + d:f + d:g + d:h + e:f + e:g + e:h,data=dat2)
# plot effects
halfnorm(a1.1$coef[-1], nlab= length(a1.1$coef[-1])/3-1, labs= names(a1.1$coef[-1]),
         ylab= "abs|Factor Effects|",
         main= "Half Normal Plot") +  qqline(abs(a1.1$coef[-1]))

在此处输入图片说明

As you can see, my plot is missing effect C. The largest one. 如您所见,我的情节缺少效果C。最大的情节。 Please let me know if you're not able to reproduce this error. 如果您无法重现此错误,请告诉我。 It seems very odd to me. 对我来说似乎很奇怪。

# effects from the model, descending
a1.1$coef[-1][order(abs(a1.1$coef[-1]), decreasing=T)][1:10]
      c       a       e     a:h     b:f     c:f     a:f     c:g     c:h     a:g 
 56.875 -27.500  22.750  13.125 -13.000 -12.750  12.500  12.375   7.375   7.000

EDIT As expected, and noted below, this was simple. 编辑正如预期的那样,并在下面指出,这很简单。 Here's the correct code: 这是正确的代码:

halfnorm(a1.1$coef[-1], nlab= round(length(a1.1$coef[-1])/3,0), labs= names(a1.1$coef[-1]),
         ylab= "abs|Factor Effects|",
         main= "Half Normal Plot") +  qqline(abs(a1.1$coef[-1]))

Your value of nlab doesn't end up being an integer. 您的nlab值最终不会是整数。 Looking at the code this gives the function an issue and in some cases causes the last effect to not get a label. 查看代码会给函数带来问题,在某些情况下会导致最后的效果没有得到标签。 If you round the value or just set it directly to an integer your problem goes away. 如果您舍入该值或将其直接设置为整数,则问题就消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM