Chapter 8 Module VI

En este modulo solo se repasa el cómo hacer una regresión y sus outputs.

Regresión lineal simple

model <- lm(hp ~ mpg, data=datos) 

Regresión lineal multiple

model_mult <- lm(hp ~ mpg+cyl, data=datos) 

8.1 Output

coef(model)
## (Intercept)         mpg 
##      324.08       -8.83
msummary(model)
##             Estimate Std. Error t value         Pr(>|t|)    
## (Intercept)   324.08      27.43   11.81 0.00000000000082 ***
## mpg            -8.83       1.31   -6.74 0.00000017878353 ***
## 
## Residual standard error: 43.9 on 30 degrees of freedom
## Multiple R-squared:  0.602,  Adjusted R-squared:  0.589 
## F-statistic: 45.5 on 1 and 30 DF,  p-value: 0.000000179
confint(model)
##             2.5 % 97.5 %
## (Intercept) 268.1 380.11
## mpg         -11.5  -6.16
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
stargazer(model, type="text")
## 
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                 hp             
## -----------------------------------------------
## mpg                          -8.830***         
##                               (1.310)          
##                                                
## Constant                    324.000***         
##                              (27.400)          
##                                                
## -----------------------------------------------
## Observations                    32             
## R2                             0.602           
## Adjusted R2                    0.589           
## Residual Std. Error      43.900 (df = 30)      
## F Statistic           45.500*** (df = 1; 30)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
summary(model)
## 
## Call:
## lm(formula = hp ~ mpg, data = datos)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -59.3  -28.9  -13.4   25.6  143.4 
## 
## Coefficients:
##             Estimate Std. Error t value         Pr(>|t|)    
## (Intercept)   324.08      27.43   11.81 0.00000000000082 ***
## mpg            -8.83       1.31   -6.74 0.00000017878353 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 43.9 on 30 degrees of freedom
## Multiple R-squared:  0.602,  Adjusted R-squared:  0.589 
## F-statistic: 45.5 on 1 and 30 DF,  p-value: 0.000000179