df<- read.csv("StockIndexPrice.csv")
dim(df)
## [1] 24 5
head(df)
## ï..Year Month Iterest_Rate Unemplyment_Rate Stock_Index_Price
## 1 2017 12 2.75 5.3 1464
## 2 2017 11 2.50 5.3 1394
## 3 2017 10 2.50 5.3 1357
## 4 2017 9 2.50 5.3 1293
## 5 2017 8 2.50 5.4 1256
## 6 2017 7 2.50 5.6 1254
names (df)<- c("Year", "Month", "IR", "UR", "SIP")
## Linear regression - single variate
lm1<- lm(df$SIP ~ df$IR)
summary(lm1)
##
## Call:
## lm(formula = df$SIP ~ df$IR)
##
## Residuals:
## Min 1Q Median 3Q Max
## -183.892 -30.181 4.455 56.608 101.057
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -99.46 95.21 -1.045 0.308
## df$IR 564.20 45.32 12.450 1.95e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 75.96 on 22 degrees of freedom
## Multiple R-squared: 0.8757, Adjusted R-squared: 0.8701
## F-statistic: 155 on 1 and 22 DF, p-value: 1.954e-11
plot(df$IR, df$SIP)
abline(lm1, col= "blue")
lm2<- lm(df$SIP ~ df$UR)
summary(lm2)
##
## Call:
## lm(formula = df$SIP ~ df$UR)
##
## Residuals:
## Min 1Q Median 3Q Max
## -159.671 -41.996 2.089 72.381 151.226
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4471.3 304.2 14.7 7.41e-13 ***
## df$UR -589.0 52.6 -11.2 1.49e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 83.25 on 22 degrees of freedom
## Multiple R-squared: 0.8507, Adjusted R-squared: 0.8439
## F-statistic: 125.4 on 1 and 22 DF, p-value: 1.487e-10
plot(df$UR, df$SIP)
abline(lm2, col= "red")
lm3<- lm(formula = df$SIP ~ df$IR + df$UR)
summary(lm3)
##
## Call:
## lm(formula = df$SIP ~ df$IR + df$UR)
##
## Residuals:
## Min 1Q Median 3Q Max
## -158.205 -41.667 -6.248 57.741 118.810
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1798.4 899.2 2.000 0.05861 .
## df$IR 345.5 111.4 3.103 0.00539 **
## df$UR -250.1 117.9 -2.121 0.04601 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 70.56 on 21 degrees of freedom
## Multiple R-squared: 0.8976, Adjusted R-squared: 0.8879
## F-statistic: 92.07 on 2 and 21 DF, p-value: 4.043e-11
###Resources Linear regression http://r-statistics.co/Linear-Regression.html