#reg-leverage.r #Figure 2 dev.off() #x is the absolute value of z=(x-mu_x)/sd_x, with mu_x and sd_x being robust estimate; x=c( 0.1039211, 1.8050155, 2.2116516, 0.9233243, 0.9738637, 0.0179033, 0.9965386, 0.2395215, 0.7409176, 0.4815837, 0.2564837, 0.6747881, 1.2017722, 0.624243, 0.7723846); #y is the standardized residual following robust regression; y=c( 2.9665221, 0.629598, -2.672544, -0.302395, -0.813451, 0.603379, -0.952705, 0.454144, -0.080149, 0.1886351, 0.7953704, -0.678748, -0.234016, 0.5771241, -0.186778); n=15 plot(x, y, type="p", lty=1, xlab="Robust M-distance of x", ylab="Residual of robust regression", main="", col=1) v_x2=qchisq(.95, 1, ncp=0, lower.tail = TRUE, log.p = FALSE);#quantile v_x=sqrt(v_x2); h_y=qnorm(.975, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) #quantile; abline(v=v_x) abline(h=h_y) abline(h=-h_y) text(1.0,2.5,"A1") text(1.0,-2.4,"A2") text(2.12,2.5,"A3") text(2.12,0,"A4") text(2.12,-2.35,"A5") text(1.0,h_y-.15, "a") text(1.0, -h_y+.15, "b") text(v_x-.05, 0, "c") text(.02,2.95,"A") text(1.74,.67,"B") text(2.15,-2.63,"C") #========================================; #Figure 3; #res_s=ordered y in Figure 2; res_s=c( -2.672544, -0.952705, -0.813451, -0.678748, -0.302395, -0.234016, -0.186778, -0.080149, 0.1886351, 0.454144, 0.5771241, 0.603379, 0.629598, 0.7953704, 2.9665221); N=15; library(plotrix) x=matrix(0,N,1); for (i in 1:N){ p_i=i/(N+1); x[i]=qchisq(p_i, 1, ncp=0, lower.tail = TRUE, log.p = FALSE) #qnorm(p_i, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) #quantile } q_chi1=sqrt(x); y=sort(abs(res_s)); plot(q_chi1,y,pch=16,cex=.5,cex.lab=1.3, xlab="Quantile of chi-distribution (df=1)",ylab="Absolute residual of robust regression"); text(1.81,2.95,"A") text(1.48,2.65,"C") draw.ellipse(x=1.65, y=2.8, a=.32, b=.1, border=1, angle=c(43), lty=1, lwd=.2)