library(data.table)
library(rstudioapi)
docPath <- rstudioapi::documentPath()
codePath <- dirname(docPath)
projPath <- dirname(codePath)
library(ggplot2)
source("~/Econometrics/Hw1/Data/MaxwellDavidoff_HW1_create_data.R")
dt2 <- as.data.frame(saved_data)
head(dt2)## x1 x2 x3 x4 y
## 1 -4.689827 3.123235 2.226993 11.205968 -0.5972656
## 2 -2.557522 3.739444 2.222386 12.417888 -0.2714289
## 3 1.457067 2.533134 1.825844 8.399975 1.6910782
## 4 8.164156 4.819952 2.042146 13.810266 3.4844145
## 5 -5.966361 1.473426 2.013879 7.002562 -0.4064829
## 6 7.967794 1.156400 1.667470 5.093257 5.6775954
## x1 x2 x3 x4 y
## 995 -7.316605 2.350013 2.184705 9.472963 -1.1584851
## 996 5.536680 4.100113 1.998389 12.193784 2.6431093
## 997 2.718997 1.276281 2.206757 7.422337 4.9300575
## 998 -4.357274 1.963797 1.840175 7.313837 -0.5931730
## 999 -6.174811 1.971207 2.200847 8.786140 -0.4313542
## 1000 -4.689266 2.548452 1.937605 8.851218 -1.2465480
## x1 x2 x3 x4
## Min. :-9.973707 Min. :1.002 Min. :1.349 Min. : 4.423
## 1st Qu.:-4.837427 1st Qu.:1.913 1st Qu.:1.862 1st Qu.: 7.819
## Median :-0.334809 Median :2.924 Median :1.993 Median : 9.965
## Mean :-0.006167 Mean :2.961 Mean :1.997 Mean : 9.953
## 3rd Qu.: 4.938649 3rd Qu.:4.028 3rd Qu.:2.147 3rd Qu.:12.075
## Max. : 9.998612 Max. :4.996 Max. :2.728 Max. :16.327
## y
## Min. :-6.8138
## 1st Qu.:-1.4044
## Median : 0.9719
## Mean : 1.0675
## 3rd Qu.: 3.6435
## Max. : 9.0832
##
## Call:
## lm(formula = dt2$y ~ dt2$x1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.004 -1.019 0.014 1.050 5.217
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.070580 0.044974 23.80 <2e-16 ***
## dt2$x1 0.502159 0.007801 64.37 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.422 on 998 degrees of freedom
## Multiple R-squared: 0.8059, Adjusted R-squared: 0.8057
## F-statistic: 4143 on 1 and 998 DF, p-value: < 2.2e-16
## 2.5 % 97.5 %
## dt2$x1 0.4868502 0.5174682
## `geom_smooth()` using formula = 'y ~ x'
- Scatter plot shows a positive linear relationship between y and
x1.
QQ plot shows a pretty normal distribution in the residuals with most residuals being in the context of the 45 degree line.
Residual plots show randomly scattered residuals for different fitted values. The linear model is valid since residuals are homoscedastic. Point 295 does have a higher residual than other residuals for similar fitted values.
Residuals vs leverage plot shows no points outside of cooks distance line.
However, cooks distance vs number of observation plot and cooksdistance vs leverage plot reveals points that need to be reviewd. Approximately 7-10 points above the .004 cooks distance comparison point (4/1000-2). Point 189, 165, and 960 are high leverage points with high cooks distance and are potenitally bad high leverage points.
##
## Call:
## lm(formula = dt2$y ~ dt2$x2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.6508 -2.4596 -0.1054 2.4963 7.2317
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.13585 0.25411 16.28 <2e-16 ***
## dt2$x2 -1.03619 0.07967 -13.01 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.985 on 998 degrees of freedom
## Multiple R-squared: 0.1449, Adjusted R-squared: 0.1441
## F-statistic: 169.1 on 1 and 998 DF, p-value: < 2.2e-16
## 2.5 % 97.5 %
## dt2$x2 -1.192538 -0.8798505
For every one unit increase in x2 y decreases by 1.03619.
Statistically significant for a two sided hypothesis test where the null hypothesis is the coefficient on x2 is equal to zero as 0 is not in the confidence interval for the coefficient.
Low R squared. Only 14.5% of y variance is explained by x. Model might not be a good fit for the data.
## `geom_smooth()` using formula = 'y ~ x'
- Scatter plot shows a negative linear relationship between y and x2.
Variance a wider comparatively to scatter plot for x1.
QQ plot shows a non normal distribution in the residuals with residuals at the far left and far right of the plot deviating from the 45 degree line. Thinner tails in the residuals distribution than a normal distribution. Under dispersed data possible negative excess kurtosis.
Residual plots show randomly scattered residuals for different fitted values. The linear model is valid since residuals are homoscedastic.
Residuals vs leverage plot shows no points outside of cooks distance line.
However, cooks distance vs number of observation plot and cooks distance vs leverage plot reveals points that need to be reviewed. Approximately 17-20 points above the .004 cooks distance comparison point (4/1000-2). For example points 530, 189, and 281 are high leverage points with high cooks distance and are potentially bad high leverage points.
##
## Call:
## lm(formula = dt2$y ~ dt2$x3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.0796 -2.4682 -0.0848 2.4745 6.8311
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.6362 0.9624 -5.857 6.41e-09 ***
## dt2$x3 3.3573 0.4794 7.004 4.58e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.151 on 998 degrees of freedom
## Multiple R-squared: 0.04685, Adjusted R-squared: 0.04589
## F-statistic: 49.05 on 1 and 998 DF, p-value: 4.581e-12
## 2.5 % 97.5 %
## dt2$x3 2.416612 4.297993
## `geom_smooth()` using formula = 'y ~ x'
##
## Call:
## lm(formula = dt2$y ~ dt2$x4)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.5363 -2.4189 -0.1038 2.3935 7.7938
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.6278 0.3945 11.731 <2e-16 ***
## dt2$x4 -0.3577 0.0384 -9.316 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.096 on 998 degrees of freedom
## Multiple R-squared: 0.08001, Adjusted R-squared: 0.07909
## F-statistic: 86.79 on 1 and 998 DF, p-value: < 2.2e-16
## 2.5 % 97.5 %
## dt2$x4 -0.4330831 -0.2823814
For every one unit increase in x4 y decreases by -.3577.
Statistically significant for a two sided hypothesis test where the null hypothesis is the coefficient on x2 is equal to zero as 0 is not in the confidence interval for the coefficient.
Low R squared. Only 8% of y variance is explained by x. Model might not be a good fit for the data.
## `geom_smooth()` using formula = 'y ~ x'
- Scatter plot shows a negative linear relationship between y and
x4.
QQ plot shows a non normal distribution in the residuals with residuals at the far left and far right of the plot deviating from the 45 degree line. Thinner tails in the residuals distribution than a normal. distribution. Under dispersed data possible negative excess kurtosis.
Residual plots show randomly scattered residuals for different fitted values. The linear model is valid since residuals are homoscedastic.
Residuals vs leverage plot shows no points outside of cooks distance line.
However, cooks distance vs number of observation plot and cooks distance vs leverage plot reveals points that need to be reviewed. Approximately 12-14 points above the .004 cooks distance comparison point (4/1000-2). For example points 882, 841, and 580 are high leverage points with high cooks distance and are potentially bad high leverage points.