Econometrics
Econometrics
0 1 2 3 4 5 6 7
1.000 0.257 0.208 -0.389 -0.093 -0.268 -0.064 -0.151
Interpretation: Varying levels of correlation indicate potential autocorrelation.
0
1
0 1 2
1.000 0.257 0.208
0 1 2 3 4 5 6
1.000 0.257 0.208 -0.389 -0.093 -0.268 -0.064
0 1 2 3 4 5 6 7
1.0 0.257 0.208 -0.389 -0.093 -0.268 -0.064 -0.151
Autocorrelations of series ‘vector1’, by lag
0
1
0 1 2
1.0 0.257 0.208
3) 1st ggplot
2nd ggplot
// head(autocorr1)
# A tibble: 6 × 6
year Y X t diff_Y diff_X
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1960 59.9 48 2 1.40 0.800
2 1961 61.7 49.8 3 1.80 1.80
3 1962 63.9 52.1 4 2.20 2.30
4 1963 65.3 54.1 5 1.40 2
5 1964 67.8 54.6 6 2.5 0.5
6 1965 69.3 58.6 7 1.5 4
//corr_mat
// head(melted_corr_mat)
Var1 Var2 value
1 year year 1.00
2 Y year 0.97
3 X year 1.00
4 t year 1.00
5 diff_Y year -0.30
6 diff_X year 0.02
4)
Autocorrelations of series ‘autocorr1$Y’, by lag
0 1 2 3 4 5 6 7 8 9 10 11 12
1.0 0.900 0.811 0.729 0.649 0.570 0.488 0.407 0.337 0.277 0.219 0.155 0.096
data: y1 ~ x
LM test = 3.4718, df = 1, p-value = 0.06242
// coeftest(bg4)
z test of coefficients:
Durbin-Watson Test
Purpose: To test for the presence of autocorrelation at lag 1 in the residuals.
Null Hypothesis (H0): No first-order autocorrelation.
Alternative Hypothesis (H1): Positive first-order autocorrelation.
Test Statistic: DW = 2.366
P-Value: 0.9744
Interpretation: No evidence of positive first-order autocorrelation.
data: y1 ~ x
DW = 2.366, p-value = 0.9744
alternative hypothesis: true autocorrelation is greater than 0
6)
//head(hetero)
# A tibble: 6 × 6
obs ind sales rd prof group
<dbl> <chr> <dbl> <dbl> <dbl> <chr>
1 1 Containers and Packing 6375. 62.5 185. low
2 2 Nonbank financial 11626. 92.5 1570. low
3 3 Service industries 14655. 178. 277. low
4 4 Metals and mining 21869. 258. 2828. low
5 8 Paper and forest products 40295. 422. 4646. low
6 5 Housing and construction 26408. 495. 226. low
//summay(hetero)
//summary(varfunc)
Call:
lm(formula = hetero_resi ~ rd + prof, data = hetero)
Residuals:
Min 1Q Median 3Q Max
-69529 -13381 -4386 14317 95682
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.121e-12 1.377e+04 0 1
rd -6.062e-17 3.588e+00 0 1
prof 4.324e-17 1.826e+00 0 1
Residual standard error: 38410 on 15 degrees of freedom
Multiple R-squared: 3.343e-34, Adjusted R-squared: -0.1333
F-statistic: 2.507e-33 on 2 and 15 DF, p-value: 1
//bptest(hetero.ols)
[1] 3.841459
data: hetero.ols
BP = 8.2046, df = 2, p-value = 0.01653
//coeftest(hetero.ols)
t test of coefficients:
Interpretation: Significant coefficients are identified (e.g., prof with p < 0.001).
Call:
lm(formula = sales ~ rd + prof, data = hetero, weights = 1/sqrt(wls_varfunc))
// summary(hetero.gls)
Weighted Residuals:
Min 1Q Median 3Q Max
-417.68 -124.83 -30.47 150.93 363.27
# A tibble: 18 × 6
# Groups: group [2]
obs ind sales rd prof group
<dbl> <chr> <dbl> <dbl> <dbl> <chr>
1 1 Containers and Packing 6375. 62.5 185. low
2 2 Nonbank financial 11626. 92.5 1570. low
3 3 Service industries 14655. 178. 277. low
4 4 Metals and mining 21869. 258. 2828. low
5 8 Paper and forest products 40295. 422. 4646. low
6 5 Housing and construction 26408. 495. 226. low
7 9 Food 70762. 509. 5036. low
8 6 General manufacturing 32406. 1083 3752. low
9 12 Consumer products 101314. 1595. 10279. low
10 7 Leisure time industries 35108. 1621. 2884. low
11 17 Fuel 230614. 1704. 22626. low
12 15 Conglomerates 141650. 3164. 9761. high
13 11 Aerospace 95294 3919. 4488. high
14 14 Chemicals 122316. 4454. 16439. high
15 13 Electrical and electronics 116141. 6108. 8787. high
16 10 Health care 80553. 6620. 13870. high
17 18 Automative 293543 9528. 18415. high
18 16 Office equipment and computers 175026. 13211. 19774. high
# A tibble: 1 × 5
mean_sales sum_sales count max_sales min_sales
<dbl> <dbl> <int> <dbl> <dbl>
1 89775. 1615956. 18 293543 6375.
# A tibble: 2 × 2
group mean_sales
<chr> <dbl>
1 high 146360.
2 low 53767.