[R] Residual plotting
wildscop
appstat at hotpop.com
Thu Jun 26 06:10:52 CEST 2003
Dear all,
So far i could do (in an informal way) to draw a Standardized Resisual plot
in the following way-
---------------------
>x <- c(104.1, 106.6, 105.5, 107.5, 109.6, 113.3, 115.5, 117.7, 119.9,
122.1, 124.3, 126.5, 128.2)
>y <- c(53732, 52912, 57005, 61354, 67682, 71602, 71961, 75309, 82931,
93310, 102161, 103068, 108927)
> beta1<-(n*sum(x*y)-sum(x)*sum(y))/(n*sum(x^2)-sum(x)^2)
> beta0<-sum(y)/n-beta1*sum(x)/n
> yhat<-beta0 + beta1*x
> error<-(y-yhat)
> se <- sqrt((sum(y^2)-beta0*sum(y)-beta1*sum(x*y))/(n-2))
> SE<-sqrt(sum(error^2)/(n-2)) # just another way
> plot(x,error)
> plot(x,error/se)
---------------------
Or, in the formal way (using s-plus functions), in the following way, but i
get stuck in the Resisual plot stage, don't know how to draw the
"Standardized Resisual plot" in this way :
---------------------
>x <- c(104.1, 106.6, 105.5, 107.5, 109.6, 113.3, 115.5, 117.7, 119.9,
122.1, 124.3, 126.5, 128.2)
>y <- c(53732, 52912, 57005, 61354, 67682, 71602, 71961, 75309, 82931,
93310, 102161, 103068, 108927)
> cripop<-rbind(x,y)
> dimnames(cripop)<-NULL
> columns <- c("1987", "1988", "1989", "1990", "1991", "1992", "1993",
"1994", "1995", "1996", "1997", "1998", "1999" )
> rows<-c("Population","Crimes")
> dimnames(cripop)<-list(rows,columns)
> bd<-t(cripop)
> bd.frame<-data.frame(bd)
> attach(bd.frame)
> regressions<-lm(Crimes~Population,data=bd.frame)
> plot(Population,resid(regressions))
> ...?...
---------------------
Can any one help me by telling me how can i draw "Standardized Resisual
plot" from here ?
Also, is there any way i can construct 95% Confidence interval or
Prediction interval for any value in R ?
_______________________
Mohammad Ehsanul Karim <appstat at HotPOP.com>
Institute of Statistical Research and Training
University of Dhaka, Dhaka- 1000, Bangladesh
_______________________
_______________________
Mohammad Ehsanul Karim <appstat at HotPOP.com>
Institute of Statistical Research and Training
University of Dhaka, Dhaka- 1000, Bangladesh
More information about the R-help
mailing list