Skip to content

regression

6 messages · Michael Bedward, Jorge Ivan Velez, ufuk beyaztas

#
Hi dear all,

suppose that s is a statistic code;

i have a matrix (x) which has 7 columns (1=x1,2=x23=x3,4=x4,5=x5,6=x6
and7=y)
and has 20 rows. i want to do linear reggression like 
reg<-lm(x[,7]~1+x[,1]+x[,2]+.......+x[,6])
but i want to do delete i th row for nrows times and create regression model
like above and compute each models'   "s" statistics and list them. but i
could not do. i always get only one model and statistic. 
How can i do this

Thanks any idea!
#
Hello Ufuk,

Here is one way to do it...

# make up some data for this example
x <- matrix(runif(7 * 20), ncol=7)

# a data.frame is most convenient for lm
x <- as.data.frame(x)
colnames(x) <- c("x1", "x2", "x3", "x4", "x5", "x6", "y")

# a list to hold lm results
x.lm <- list()

# run regressions
for (i in 1:nrow(x)) {
    x.lm <- c(x.lm, list( lm(y ~ ., data=x[-i, ]) ))
}

Now element i of x.lm will hold the results of the regression with
data row i removed.

Michael
On 23 December 2010 08:57, ufuk beyaztas <ufukbeyaztas at gmail.com> wrote:
#
thank you so much, and i have a question too
if i read some statistic for example cook-weisberg statistic or welsh-kuh
distance and i say 
stat<-welsh.kuh than i put this statistic in your idea, can i get the
statistics each times?