How to do linear regression in R. First, you should read the help files on the commands lm and step: help(lm) help(step) Suppose you have three vectors y, x1 and x2 and you want to fit y = b0 + b1 x1 + b2 x2 + error. The following commands are useful. mydata <- data.frame(y=y,x1=x1,x2=x2) out <- lm(y ~ x1 + x2,data = mydata) names(out) extractAIC(out) s <- summary(out) print(s) names(s) par(mfrow=c(2,2)) plot(out,ask=F) Another way to do regression is as follows: X <- cbind(x1,x2) temp <- lsfit(X,y) ls.print(temp) names(temp) Stepwise regression: out <- lm(y ~ x1 + x2,data = mydata) forward <- step(out,direction="forward") backward <- step(out,direction="backward") summary(forward) summary(backward)