[R] selection statistics from function

ufuk beyaztas ufukbeyaztas at gmail.com
Mon Jan 17 22:45:01 CET 2011


Hi,
My code:

e <- rnorm(n=50, mean=0, sd=sqrt(0.5625))
x0 <- c(rep(1,50))
x1 <- rnorm(n=50,mean=2,sd=1)
x2 <- rnorm(n=50,mean=2,sd=1)
x3 <- rnorm(n=50,mean=2,sd=1)
x4 <- rnorm(n=50,mean=2,sd=1)
y <- 1+ 2*x1+4*x2+3*x3+2*x4+e
x2[1] = 10     #influential observarion
y[1] = 10      #influential observarion
data.x <- matrix(c(x0,x1,x2,x3,x4),ncol=5)
data.y <- matrix(y,ncol=1)
data.k <- cbind(data.x,data.y)

result <- list()

for( i in 1: 3100) {
data <- data.k[sample(50,50,replace=TRUE),]
dataX <- data[,1:5]
dataY <- data[,6]
B.cap <- solve(crossprod(dataX)) %*% crossprod(dataX,dataY)
P <- dataX %*% solve(crossprod(dataX)) %*% t(dataX)
Y.cap <- P %*% dataY
e <- dataY - Y.cap
dX <- nrow(dataX) - ncol(dataX)
var.cap <- crossprod(e) / (dX)
ei <- as.vector(dataY - dataX %*% B.cap)
pi <- diag(P)
var.cap.i <- (((dX) * var.cap) / (dX - 1)) - (ei^2 / ((dX-1) * (1 - pi)))
ti <- ei / sqrt(var.cap * (1 - pi))
Ci <- (ti^2 / (ncol(dataX))) * (pi / (1 - pi))
result <- c(result,list(mean(Ci)))}

table<-do.call(rbind.data.frame,result)
names(table)=c("Cook's Distance")
table

I want to find data's statistics (mean(Ci)) which do not contain influential
observation. That is do not contain the value of 10. Can someone help me?
Thanks for advices !
-- 
View this message in context: http://r.789695.n4.nabble.com/selection-statistics-from-function-tp3221267p3221267.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list