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: r.789695.n4.nabble.com/regression-tp3161328p3161328.html Sent from the R help mailing list archive at Nabble.com.
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:> > 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: 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 > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Hi Ufuk, Using Michael's data, here is one more way of doing it: allmodels <- lapply(1:nrow(x), function(row) with(x, lm(y ~ ., data x[-row,]))) allmodels To access the information contained in the model when the first row is removed, you can do summary(allmodels[[1]]) And, if you want to have all coefficients, then do.call(rbind, lapply(allmodels, coefficients)) is what you need. HTH, Jorge On Wed, Dec 22, 2010 at 4:57 PM, ufuk beyaztas <> 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: > r.789695.n4.nabble.com/regression-tp3161328p3161328.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Thank you so much i did with your idea.. thank you :) -- View this message in context: r.789695.n4.nabble.com/regression-tp3161328p3161524.html Sent from the R help mailing list archive at Nabble.com.
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? -- View this message in context: r.789695.n4.nabble.com/regression-tp3161328p3161549.html Sent from the R help mailing list archive at Nabble.com.
sorry not read i want to say "write" -- View this message in context: r.789695.n4.nabble.com/regression-tp3161328p3161551.html Sent from the R help mailing list archive at Nabble.com.