library(readxl)
library(ggplot2)
Apple_Intel_Safeway <- read_excel("~/Github/Business_Statistics_41000/Lecture/Section3/Apple_Intel_Safeway.xls")
View(Apple_Intel_Safeway)
summary(lm(Apple ~ SP500, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Apple ~ SP500, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -21.2455  -3.8059   0.5018   4.0369  16.3789 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.8967     0.8306   2.284   0.0257 *  
## SP500         0.9660     0.1857   5.203 2.15e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.392 on 65 degrees of freedom
## Multiple R-squared:  0.294,  Adjusted R-squared:  0.2831 
## F-statistic: 27.07 on 1 and 65 DF,  p-value: 2.145e-06
summary(lm(Intel ~ SP500, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Intel ~ SP500, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.5574  -3.5786  -0.3077   2.8054  11.5925 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.5706     0.6996   0.816    0.418    
## SP500         0.8767     0.1564   5.605 4.56e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.384 on 65 degrees of freedom
## Multiple R-squared:  0.3259, Adjusted R-squared:  0.3155 
## F-statistic: 31.42 on 1 and 65 DF,  p-value: 4.559e-07
summary(lm(Safeway ~ SP500, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Safeway ~ SP500, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.2856  -4.5893   0.3642   3.8669  22.7144 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.1164     0.9749   0.119 0.905297    
## SP500         0.8619     0.2179   3.955 0.000192 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.503 on 65 degrees of freedom
## Multiple R-squared:  0.194,  Adjusted R-squared:  0.1816 
## F-statistic: 15.64 on 1 and 65 DF,  p-value: 0.0001918
ggplot(Apple_Intel_Safeway, aes(x=SP500, y=Apple)) +
    geom_point(shape=1) +    # Use hollow circles
    geom_smooth(method=lm) 

portfolio = 1/3*Apple_Intel_Safeway$Apple + 1/3*Apple_Intel_Safeway$Safeway + 1/3*Apple_Intel_Safeway$Intel
Apple_Intel_Safeway$portfolio = portfolio

summary(lm(portfolio ~ SP500, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = portfolio ~ SP500, data = Apple_Intel_Safeway)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.4617 -2.4305 -0.3744  2.6003  6.7056 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.86122    0.42649   2.019   0.0476 *  
## SP500        0.90151    0.09534   9.456 7.85e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.282 on 65 degrees of freedom
## Multiple R-squared:  0.5791, Adjusted R-squared:  0.5726 
## F-statistic: 89.42 on 1 and 65 DF,  p-value: 7.851e-14
summary(lm(Apple ~ Safeway, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Apple ~ Safeway, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -17.7738  -4.5205  -0.4959   4.5256  16.3523 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 3.369e+00  9.433e-01   3.572 0.000674 ***
## Safeway     3.522e-05  1.129e-01   0.000 0.999752    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.607 on 65 degrees of freedom
## Multiple R-squared:  1.497e-09,  Adjusted R-squared:  -0.01538 
## F-statistic: 9.732e-08 on 1 and 65 DF,  p-value: 0.9998
summary(lm(Apple ~ Safeway + SP500, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Apple ~ Safeway + SP500, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.7325  -3.6009  -0.3459   4.3495  13.1202 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.9281     0.7941   2.428  0.01800 *  
## Safeway      -0.2696     0.1010  -2.669  0.00962 ** 
## SP500         1.1984     0.1977   6.062 7.95e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.11 on 64 degrees of freedom
## Multiple R-squared:  0.3647, Adjusted R-squared:  0.3449 
## F-statistic: 18.37 on 2 and 64 DF,  p-value: 4.953e-07
summary(lm(Apple ~ Intel, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Apple ~ Intel, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -17.8232  -4.1694   0.0334   4.7173  15.1552 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)   2.4996     0.8910   2.805  0.00662 **
## Intel         0.4560     0.1323   3.447  0.00100 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.995 on 65 degrees of freedom
## Multiple R-squared:  0.1545, Adjusted R-squared:  0.1415 
## F-statistic: 11.88 on 1 and 65 DF,  p-value: 0.001
summary(lm(Apple ~ Intel + SP500, data = Apple_Intel_Safeway))
## 
## Call:
## lm(formula = Apple ~ Intel + SP500, data = Apple_Intel_Safeway)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -20.8081  -3.8464   0.6512   3.8519  16.0994 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   1.8146     0.8351   2.173 0.033495 *  
## Intel         0.1438     0.1473   0.976 0.332701    
## SP500         0.8399     0.2262   3.713 0.000432 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6.394 on 64 degrees of freedom
## Multiple R-squared:  0.3044, Adjusted R-squared:  0.2826 
## F-statistic:    14 on 2 and 64 DF,  p-value: 9.046e-06