1 Úvod

Tento notebook vysvetľuje dva dôležité diagnostické testy v ekonometrii:

  1. Breusch–Paganov test pre heteroskedasticitu,
  2. Breusch–Godfreyho test pre autokoreláciu.

2 Breusch–Paganov test

2.1 Myšlienka

Uvažujme lineárny regresný model:

\[ y_i = \beta_0 + \beta_1 x_{1i} + \cdots + \beta_k x_{ki} + u_i \]

Za predpokladu homoskedasticity platí:

\[ \mathrm{Var}(u_i) = \sigma^2 \]

Test skúma, či variancia závisí od vysvetľujúcich premenných.

2.2 Hypotézy

\[ H_0: \mathrm{Var}(u_i) = \sigma^2 \]

\[ H_1: \mathrm{Var}(u_i) \neq \sigma^2 \]

2.3 Postup

  1. Odhadneme model pomocou OLS a získame rezíduá:

\[ \hat{u}_i \]

  1. Pomocná regresia:

\[ \hat{u}_i^2 = \alpha_0 + \alpha_1 x_{1i} + \cdots + \alpha_m x_{mi} + v_i \]

2.4 Testovacia štatistika

\[ LM = nR^2 \sim \chi^2(m) \]

3 Breusch–Godfreyho test

3.1 Myšlienka

Testuje autokoreláciu rezíduí:

\[ u_t = \rho_1 u_{t-1} + \cdots + \rho_p u_{t-p} + \varepsilon_t \]

3.2 Hypotézy

\[ H_0: \rho_1 = \cdots = \rho_p = 0 \]

\[ H_1: \exists \rho_j \neq 0 \]

3.3 Postup

Pomocná regresia:

\[ \hat{u}_t = \gamma_0 + \gamma_1 x_{1t} + \cdots + \gamma_k x_{kt} + \rho_1 \hat{u}_{t-1} + \cdots + \rho_p \hat{u}_{t-p} + v_t \]

3.4 Testovacia štatistika

\[ LM = nR^2 \sim \chi^2(p) \]

4 R implementácia

library(lmtest)
library(sandwich)

5 Príklad: Breusch–Pagan

set.seed(123)
n <- 200
x <- runif(n, 1, 10)
u <- rnorm(n, sd = 0.5 * x)
y <- 2 + 3*x + u

m <- lm(y ~ x)
summary(m)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.3828 -1.5748 -0.1864  1.3994  9.6110 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.16353    0.46233    4.68 5.32e-06 ***
## x            2.96535    0.07607   38.98  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.646 on 198 degrees of freedom
## Multiple R-squared:  0.8847, Adjusted R-squared:  0.8841 
## F-statistic:  1520 on 1 and 198 DF,  p-value: < 2.2e-16
bptest(m)
## 
##  studentized Breusch-Pagan test
## 
## data:  m
## BP = 24.741, df = 1, p-value = 6.557e-07

6 Príklad: Breusch–Godfrey

set.seed(123)
n <- 200
x <- rnorm(n)
u <- numeric(n)
eps <- rnorm(n)

rho <- 0.7
u[1] <- eps[1]

for (t in 2:n) {
  u[t] <- rho * u[t-1] + eps[t]
}

y <- 1 + 2*x + u

m2 <- lm(y ~ x)
summary(m2)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.7937 -0.9739 -0.0469  0.8434  3.3399 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.15262    0.09073   12.70   <2e-16 ***
## x            2.06205    0.09644   21.38   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.283 on 198 degrees of freedom
## Multiple R-squared:  0.6978, Adjusted R-squared:  0.6963 
## F-statistic: 457.2 on 1 and 198 DF,  p-value: < 2.2e-16
bgtest(m2, order = 1)
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  m2
## LM test = 79.796, df = 1, p-value < 2.2e-16

7 Robustné štandardné chyby

7.1 white robustné štandardné chyby

odhaduje štandardné chyby koeficientov, ktoré sú robustné voči heteroskedasticite

coeftest(m, vcov = vcovHC(m, type = "HC1"))
## 
## t test of coefficients:
## 
##             Estimate Std. Error t value  Pr(>|t|)    
## (Intercept)  2.16353    0.37526  5.7655 3.088e-08 ***
## x            2.96535    0.08092 36.6455 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

7.2 Newey-West robustné štandardné chyby

sú robustné aj v prípade heteroskedasticity a autokorelácie rezíduí

coeftest(m2, vcov = NeweyWest(m2))
## 
## t test of coefficients:
## 
##             Estimate Std. Error t value  Pr(>|t|)    
## (Intercept)  1.15262    0.19178  6.0101 8.768e-09 ***
## x            2.06205    0.10274 20.0713 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

8 Záver

  • Breusch–Pagan test: heteroskedasticita - riešenie White robustné štandardné chyby
  • Breusch–Godfrey test: autokorelácia - riešenie Newey-West robustné štandardné chyby