ron-r
3/9/2014 - 9:44 AM

List of all coefficient regressions

List of all coefficient regressions

I have built a simple regression model using the iris data set. I would like to run the dependent variable (iris$Sepal.Length) with all available variables, each regression with its own variable (each regression should be with . The outcome that I wanted to get is a list of each regression summary. Using the iris data set there should be 4 regressions:

data(iris)
r1<-lm(iris$Sepal.Length ~ Sepal.Width))
r2<-lm(iris$Sepal.Length ~ Petal.Length)
r3<-lm(iris$Sepal.Length ~ Petal.Width)
r4<-lm(iris$Sepal.Length ~ Petal.Species)
and a summary with the coefficients for each one of the regressions. Any Ideas how can I do this?



answare:
sapply(names(iris)[-1], function(x) lm.fit(cbind(1, iris[,x]), iris[,"Sepal.Length"])$coef)
# the names(iris)[-1] means "without the first column"
# in function(x) lm.fit(cbind(1, iris[,x])
the "1" means that the fit will be done upon the first column ?
the iris [,x] means that the all rows will be taken and each time for a different x column.
iris[,"Sepal.Length"])$coef means to show all coefficants for all the rows vs one column: "Sepal.Length".