The R library required to perform Durbin-Watson, Breusch-Godfrey, Breusch-Pagan, and Goldfeld-Quandt tests:
> library(lmtest)
The R library required to perform Durbin-Watson, Breusch-Godfrey, Breusch-Pagan, and Goldfeld-Quandt tests:
> library(lmtest)
Ordinary Least Squares (OLS) Regression Coefficients
MyMdl = lm(formula = GDP2018 ~ T, data = MM_DTA_01)
summary(MyMdl)
Will produce the following output:
Call:
lm(formula = GDP2018 ~ T, data = MM_DTA_01)
Residuals:
Min 1Q Median 3Q Max
-2684399 -2025650 -592330 1430009 6473734
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2427989 513893 -4.725 1.03e-05 ***
T 218026 11303 19.290 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2248000 on 76 degrees of freedom
Multiple R-squared: 0.8304, Adjusted R-squared: 0.8282
F-statistic: 372.1 on 1 and 76 DF, p-value: < 2.2e-16
Multiple Regression
MyMdl = lm(formula = GDP2018 ~ T + EX2018 + IM2018, data = MM_DTA_01)
Durbin-Watson Statistic for Serial Correlation (Autocorrelation)
DurbinWatsonTest(MyMdl)
Will produce the following output:
Durbin-Watson test
data: MyMdl
DW = 0.035978, p-value < 2.2e-16
alternative hypothesis: true autocorrelation is greater than 0
Breusch-Godfrey Statistic for Serial Correlation (Autocorrelation)
bgtest(MyMdl)
Will produce the following output:
Breusch-Godfrey test for serial correlation of order up to 1
data: MyMdl
LM test = 74.301, df = 1, p-value < 2.2e-16
Breusch-Pagan Statistic for Heteroscedasticity
bptest(MyMdl)
Will produce the following output:
Studentized Breusch-Pagan test
data: MyMdl
BP = 19.317, df = 1, p-value = 1.107e-05
Goldfeld-Quandt Statistic for Heteroscedasticity
gqtest(MyMdl)
Will produce the following output:
Goldfeld-Quandt test
data: MyMdl
BP = 29.613, df1 = 37, df2 = 37, p-value = 2.2e-16
alternative hypothesis: Variance increase from segment 1 to 2
Correlation Coefficient
head(DataNo2)
Will produce the following output:
# A tibble: 6 × 7
YR T GDP GDPPI2018 GDP2018 EX2018 IM2018
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2008 1 8050201. 0.784 10270878. 1647293 2216258
2 2009 2 8390421. 0.805 10419633. 1481405 2192637
3 2010 3 9399451. 0.840 11183861. 1769189 2668470
4 2011 4 10144661. 0.873 11615360. 1697601 2716794
5 2012 5 11060589. 0.891 12416466. 1901720 2867464
6 2013 6 12050592. 0.909 13254644. 1817413 3037079
cor_matrix = cor(DataNo2)
print(cor_matrix)
Will produce the following output:
YR T GDP GDPPI2018 GDP2018 EX2018 IM2018
YR 1.0000000 1.0000000 0.9884230 0.9872057 0.9791493 0.9599731 0.9465083
T 1.0000000 1.0000000 0.9884230 0.9872057 0.9791493 0.9599731 0.9465083
GDP 0.9884230 0.9884230 1.0000000 0.9788880 0.9943552 0.9807268 0.9764256
GDPPI2018 0.9872057 0.9872057 0.9788880 1.0000000 0.9595876 0.9402991 0.9210839
GDP2018 0.9791493 0.9791493 0.9943552 0.9595876 1.0000000 0.9769194 0.9851542
EX2018 0.9599731 0.9599731 0.9807268 0.9402991 0.9769194 1.0000000 0.9859029
IM2018 0.9465083 0.9465083 0.9764256 0.9210839 0.9851542 0.9859029 1.0000000cor_matrix = round(cor(DataNo2), 2)print(cor_matrix)Will produce the following rounded to 2 decimal digits correlation matrix output: YR T GDP GDPPI2018 GDP2018 EX2018 IM2018
YR 1.00 1.00 0.99 0.99 0.98 0.96 0.95
T 1.00 1.00 0.99 0.99 0.98 0.96 0.95
GDP 0.99 0.99 1.00 0.98 0.99 0.98 0.98
GDPPI2018 0.99 0.99 0.98 1.00 0.96 0.94 0.92
GDP2018 0.98 0.98 0.99 0.96 1.00 0.98 0.99
EX2018 0.96 0.96 0.98 0.94 0.98 1.00 0.99
IM2018 0.95 0.95 0.98 0.92 0.99 0.99 1.00 Graphing with R
plot(MyMdl)
Will produce the following graphs:
The formula for the correlation coefficient is:
Generally, a correlation coefficient of 0.90 and above, regardless of the sign, is considered high correlation. A correlation coefficient of 0.50 and below is considered low correlation. A correlation coefficient between 0.5 and 0.9 is considered medium correlation.
Some things to note about correlation coefficient value:
a) A correlation coefficient of 0.50 meant that the one variable explains only about 25% of the variation in the other variable;
b) It takes a correlation coefficient of 0.70 for one variable to explain about 50% of the variation in the other variable;
c) For a correlation coefficient to be convincing in determining the linear relationship between the two variables, a medium correlation needs to tested for statistical significance using t statistic;
d) It is often safe to say, that low correlations means "no correlations". By precision, no correlation will have a correlation value of 0.
t-Statistic of the Correlation Coefficient
The t-Statistic of the Correlation Coefficient is given by the formula:
where: r = value of the correlation coefficient
n = is the number of samples
The t-Statistic is used to test the following hypothesis:
a) Ho (Null Hypothesis) that r is equal to 0 and there is no significant correlation between the two variables under study;
b) Ha (Alternative Hypothesis) the r is not equal to zero and that there is a significant correlation between the two variables under study.
As a rule of the thumb for samples larger than 60, a t-Statistic value of 2 or more (regardless of the sign) means that it is statistically significant and therefore the Ha (alternative hypothesis) is accepted and the Ho (null hypothesis) is rejected. Inversely, a t-Statistic value of less than 2 (regardless of the sign) means that it is NOT statistically significant and therefore the Ho (null hypothesis) is accepted and the Ha (alternative hypothesis) is rejected.
For boundary values, the reference t-Statistic is found in most college level textbooks. However, the reference t-Statistic can also be viewed using tinv() function found in most computer spreadsheets. For the LibreCalc spreadsheet, the tinv() function is given by formula =tinv(risk level,degrees of freedom). To illustrate, a sample of 200 with a confidence level of 95%, we place =tinv(0.05,198). This gives a t-Statistic reference value of (1.972017). The degrees of freedom is 200-2=198. The risk level is 1 minus the confidence level of 95% (0.95) equals (0.05).As a note, the t-Statistic of the Correlation Coefficient is equal to the t-Statistic of the Simple Regression Equation. As such, the t-Statistic can be derived from the Simple Regression Model using the F-Statistic as F=t^2 or t-Statistic is the square root of the F-Statistic.
| X | Y |
| 1 | 1234 |
| 2 | 1768 |
| 3 | 2234 |
| 4 | 2555 |
| 5 | 2800 |
| Slope |
| 391.9 |
| Intercept |
| 942.5 |
| Y Forecast |
| 1334.4 |
| 1726.3 |
| 2118.2 |
| 2510.1 |
| 2902 |
| Y Forecast | Y Original |
| 1334.4 | 1234 |
| 1726.3 | 1768 |
| 2118.2 | 2234 |
| 2510.1 | 2555 |
| 2902 | 2800 |
| Y Forecast | Y Original | Y Error |
| 1334.4 | 1234 | 100.40000000000009 |
| 1726.3 | 1768 | -41.700000000000045 |
| 2118.2 | 2234 | -115.80000000000018 |
| 2510.1 | 2555 | -44.90000000000009 |
| 2902 | 2800 | 102 |
| MAD |
| 80.96000000000008 |
| RMSE |
| 86.77407446927921 |
| R-Squared |
| 0.9760733246803284 |
| Correlation |
| 0.9879642448615398 |
| F Statistic |
| 122.38319782621953 |
| t Statistic |
| 11.062693967846148 |
| Intercept | Slope | t Stat | R Squared | Correlation | F Stat |
| 942.5 | 391.9 | 11.062693 | 0.976073 | 0.987964 | 122.383197 |
| X | Y |
| 1 | 1234 |
| 2 | 1768 |
| 3 | 2234 |
| 4 | 2555 |
| 5 | 2800 |
| Slope |
| 391.9 |
| Intercept |
| 942.5 |
| Y Forecast |
| 1334.4 |
| 1726.3 |
| 2118.2 |
| 2510.1 |
| 2902 |
| Y Forecast | Y Original |
| 1334.4 | 1234 |
| 1726.3 | 1768 |
| 2118.2 | 2234 |
| 2510.1 | 2555 |
| 2902 | 2800 |
| Y Forecast | Y Original | Y Error |
| 1334.4 | 1234 | 100.40000000000009 |
| 1726.3 | 1768 | -41.700000000000045 |
| 2118.2 | 2234 | -115.80000000000018 |
| 2510.1 | 2555 | -44.90000000000009 |
| 2902 | 2800 | 102 |
| MAD |
| 80.96000000000008 |
| RMSE |
| 86.77407446927921 |
| R-Squared |
| 0.9760733246803284 |
| Correlation |
| 0.9879642448615398 |
| F Statistic |
| 122.38319782621953 |
| t Statistic |
| 11.062693967846148 |
| Intercept | Slope | t Stat | R Squared | Correlation | F Stat |
| 942.5 | 391.9 | 11.062693 | 0.976073 | 0.987964 | 122.383197 |