1. Data

str(dat)
## 'data.frame':    167 obs. of  4 variables:
##  $ Y : num  13 33.8 15.4 20 17.8 14.4 14.9 9.2 17.1 22.4 ...
##  $ X1: num  60.8 94.8 70.8 55.9 54.1 63.1 53.6 67.1 53.6 74.5 ...
##  $ X2: num  171 171 179 147 156 ...
##  $ X3: Factor w/ 2 levels "A","B": 1 2 1 2 2 1 1 1 1 1 ...

2. Regression

reg=lm(Y~X1+X2+X3,data=dat)
anova(aov(reg))
## Analysis of Variance Table
## 
## Response: Y
##            Df  Sum Sq Mean Sq  F value Pr(>F)    
## X1          1 1298.26 1298.26 119.5367 <2e-16 ***
## X2          1 2628.53 2628.53 242.0203 <2e-16 ***
## X3          1    1.17    1.17   0.1082 0.7426    
## Residuals 163 1770.31   10.86                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(reg)
## 
## Call:
## lm(formula = Y ~ X1 + X2 + X3, data = dat)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.5707 -1.9978 -0.2649  2.3706  9.6292 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 83.91802    5.83522  14.381   <2e-16 ***
## X1           0.57512    0.03126  18.398   <2e-16 ***
## X2          -0.62490    0.04214 -14.831   <2e-16 ***
## X3B          0.18834    0.57263   0.329    0.743    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.296 on 163 degrees of freedom
## Multiple R-squared:  0.6893, Adjusted R-squared:  0.6836 
## F-statistic: 120.6 on 3 and 163 DF,  p-value: < 2.2e-16

3. Regression on dplyr

library(dplyr)
library(broom)
doReg=dat %>% do(reg=lm(Y~X1+X2+X3,data=.))
library(devtools)
ANOVAreg=doReg%>% rowwise %>% do(anova(.$reg))             #ANOVA result
ANOVAreg=as.data.frame(ANOVAreg)
ANOVAreg
##    Df      Sum Sq     Mean Sq     F value       Pr(>F)
## 1   1 1298.260687 1298.260687 119.5367346 3.229474e-21
## 2   1 2628.526315 2628.526315 242.0203088 4.888414e-34
## 3   1    1.174955    1.174955   0.1081834 7.426441e-01
## 4 163 1770.305109   10.860768          NA           NA
tidy(doReg,reg)              #Coef result 
##          term   estimate  std.error   statistic      p.value
## 1 (Intercept) 83.9180160 5.83522093  14.3812920 8.341635e-31
## 2          X1  0.5751169 0.03125992  18.3979025 1.263870e-41
## 3          X2 -0.6249004 0.04213520 -14.8308407 4.791974e-32
## 4         X3B  0.1883442 0.57262717   0.3289124 7.426441e-01

(Ref: http://stackoverflow.com/questions/22713325/fitting-several-regression-models-with-dplyr)

glance(doReg,reg)
##   r.squared adj.r.squared    sigma statistic     p.value df   logLik
## 1 0.6893257     0.6836078 3.295568  120.5551 3.57521e-41  4 -434.099
##       AIC     BIC deviance df.residual
## 1 878.198 893.788 1770.305         163

4. Regression for series of column on dplyr

4.1 Using loop
dat_x=dat [,c(2:4)]
dat_y=dat [,1]
main=list(); int=list()
for(i in names(dat_x)){ 
    x <- dat_x[[i]]                                             
    main[[i]] = summary(lm(dat_y~x)) $"coefficients"[2,c(1,4)] 
}
result=data.frame(main); result_t=t(result); result_t
##      Estimate     Pr(>|t|)
## X1  0.2445783 6.941231e-11
## X2 -0.1084365 3.661148e-02
## X3  2.1427011 2.738169e-02
5. Using tidy
library(purrr)
Estimate <- map(dat_x, function(x) tidy(lm(dat_y~x))[2,c(2)])
p_value <- map(dat_x, function(x) tidy(lm(dat_y~x))[2,c(5)])
main=rbind(Estimate,p_value); t(main)
##    Estimate   p_value     
## X1 0.2445783  6.941231e-11
## X2 -0.1084365 0.03661148  
## X3 2.142701   0.02738169