[R] regression

Michael Bedward michael.bedward at gmail.com
Thu Dec 23 01:47:21 CET 2010

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.


On 23 December 2010 08:57, ufuk beyaztas <ufukbeyaztas at gmail.com> wrote:
> 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!
> --
> View this message in context: http://r.789695.n4.nabble.com/regression-tp3161328p3161328.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list