在ggplot2的QQ情节中识别点?

时间:2014-12-27 22:48:19

标签: r ggplot2 statistics

我正在处理一个残差向量,试图验证正态分布是否是错误项的适当假设。

stres<-c(-1.8901289914,0.4204280426,-0.0145373478,-0.9589928480,0.2979275041,-0.0739727698,-0.2855008329, 0.7230079969, -0.2914220542, -1.4806560234,  0.1745061707, -1.0128947866, 0.2164536856, -1.1546273403, -0.1542422829,  0.4053103868, -0.5823112019,  0.4563220212, -0.2041307378, -0.6045740758, -0.3423926064,  0.5056780975, -0.3331478887, -0.7572435490,-0.2779393059, -0.6849294132,  0.1311372820, -0.3030318977,  1.2808663783,  0.1563968894,0.6010948547, -0.3774192022,  1.0438147373,  1.6050759999, -0.9890854956, -0.1287947910, 0.7271980085, -0.9227865867,  0.4821372580,  0.3399080091, -0.2351548189,  0.6355239393, 2.1741928350, -0.2974405677, -1.0528047470, -0.2669435284,  5.0818621788, -0.0088001872, 0.3437940065, -0.4497556191,  0.3016467357, -0.5614212196, -0.8108463584,  0.8338203257, -0.0004854171,  0.8685702440, -1.4909115265, -1.0530867343,  0.9150175493,  1.0730349160, 0.8118376993,  0.1817804928, -1.9965218063,  0.2532144991, -1.1466778177, -0.0578508361, 0.3446155055, -0.5806560664, -0.1169654345, -0.5275995111, -1.0649636054, -0.3887896268, -0.4160932861, -0.0934359868,  0.3515817484, -1.5149224114,  0.5314789991, -0.2125920264, -0.7261382754, -0.2765816110,  1.5836098693, -0.5722100502, -1.7568426345, -0.5378891714, -0.1135252088, -0.2024199659, -0.8113893763,  0.1124588319, -0.4545775998,  0.6401511326, 0.4593905713,  0.6382493988,  1.3572090694, -1.2216154767,  0.0863635754, -0.1183901577, -0.4117695427,  1.3132905003, -0.1426298933, -0.6680755381,  1.1076746801,  0.6213041292, -0.8735205521,  0.9021532905, -0.1517989978,  1.0997109361,  0.0038767275, 0.0967747416, 0.5100796248, -0.2174347692, -1.7604201415,  4.2759584670,  0.3281834312)
qplot(sample=stres)+labs(title="QQ Plot/Studentized Residuals")+theme_bw()

enter image description here

如您所见,大多数残差都落在或接近该线。唯一的例外是右上角的那两个。我想确定它们,以便能够更好地研究这些特定的观察结果。你能告诉我怎么做吗?

谢谢。

1 个答案:

答案 0 :(得分:4)

> order(stres, decreasing = TRUE)[1:2]
[1]  47 112

> stres[order(stres, decreasing = TRUE)[1:2]]
[1] 5.081862 4.275958

如果您想访问qplot次使用的值,可以执行以下操作:

plt <- print(qplot(sample=stres)+labs(title="QQ Plot/Studentized Residuals")+theme_bw())
plt[["data"]][[1]]

你得到的结果相同:

> sort(plt[["data"]][[1]]$sample, decreasing = TRUE)[1:2]
[1] 5.081862 4.275958