- Agora, veremos formas mais gerais de testes de hipótese, que não são normalmente informadas nos resultados das regressões.
Teste de Wald
-
Considere:
- $G$ o número de restrições lineares
- $\boldsymbol{\beta}$ é um vetor de parâmetros $(K+1) \times 1$
- $\boldsymbol{h}$ é um vetor de constantes $G \times 1$
- $\boldsymbol{R}$ é uma matriz $G \times (K+1)$, que empilha $G$ vetores-linha $\boldsymbol{r}'_g$ de dimensões $1 \times (K+1)$, para $g=1, 2, ..., G$
- Modelo multivariado:
-
A partir destas matrizes e vetores, é possível construir testes de hipótese na forma: \begin{align} \text{H}_0: &\underset{G\times (K+1)}{\boldsymbol{R}} \underset{(K+1)\times 1}{\boldsymbol{\beta}} = \underset{G \times 1}{\boldsymbol{h}} \\ \text{H}_0: &\left[ \begin{matrix} \boldsymbol{r}'_1 \\ \boldsymbol{r}'_2 \\ \vdots \\ \boldsymbol{r}'_{G} \end{matrix} \right] \boldsymbol{\beta} = \left[ \begin{matrix} h_1 \\ h_2 \\ \vdots \\ h_G \end{matrix} \right] \\ \text{H}_0: &\left\{ \begin{matrix} \boldsymbol{r}'_1 \boldsymbol{\beta} = h_1 \\ \boldsymbol{r}'_2 \boldsymbol{\beta} = h_2 \\ \vdots \\ \boldsymbol{r}'_G \boldsymbol{\beta} = h_G \end{matrix} \right. \end{align}
Uma restrição linear
-
Considere o modelo: $$y = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \varepsilon$$
-
Logo, há $K=2$ variáveis explicativas (e há 3 parâmetros)
-
1 restrição linear $\Longrightarrow \ G=1$
-
Logo, neste caso específico, temos $$\boldsymbol{R} = \boldsymbol{r}'_1\ \implies\ \text{H}_0:\ \boldsymbol{r}'_1 \boldsymbol{\beta} = h_1 $$
Avaliando a hipótese nula com restrição única
-
Para o caso com uma única restrição, assumimos que $$ \boldsymbol{r}'_1 \hat{\boldsymbol{\beta}} \sim N(\boldsymbol{r}'_1 \hat{\boldsymbol{\beta}};\ \boldsymbol{r}'_1 \boldsymbol{V(\hat{\boldsymbol{\beta}}) r_1})$$
-
Calcula-se a estatística de Wald (igual à estatística t, quando tem uma única restrição): $$ w = t = \frac{\boldsymbol{r}'_1 \hat{\boldsymbol{\beta}} - h_1}{\sqrt{\boldsymbol{r}'_1 \hat{\sigma}^2 (\boldsymbol{X}'\boldsymbol{X})^{-1} \boldsymbol{r}_1}} = \frac{\boldsymbol{r}'_1 \hat{\boldsymbol{\beta}} - h_1}{\sqrt{\boldsymbol{r}'_1 \boldsymbol{V(\hat{\boldsymbol{\beta}})} \boldsymbol{r}_1}} $$
-
Escolhe-se o nível de significância $\alpha$ e rejeita-se a hipótese nula se a estatística t não pertencer ao intervalo de confiança.
Exemplo 1: H$_0: \ \beta_1 = 4$
- Note que $h_1 = 4$
- O vetor $r'_1$ pode ser escrito como
-
Então, a hipótese nula é $$\text{H}_0:\ \boldsymbol{r}'_1 \boldsymbol{\beta}\ =\ \left[ \begin{matrix} 0 & 1 & 0 \end{matrix} \right] \left[ \begin{matrix} \beta_0 \\ \beta_1 \\ \beta_2 \end{matrix} \right] = 4\ \iff\ \beta_1 = 4 $$
-
E o denomidor da estatística t é igual a: \begin{align} &\sqrt{\boldsymbol{r}'_1 \boldsymbol{V(\hat{\boldsymbol{\beta}})} \boldsymbol{r}_1} \\ &= \sqrt{\left[ \begin{matrix} 0 & 1 & 0 \end{matrix} \right] {\small \begin{bmatrix} var(\hat{\beta}_0) & cov(\hat{\beta}_0, \hat{\beta}_1) & cov(\hat{\beta}_0, \hat{\beta}_2) \\ cov(\hat{\beta}_0, \hat{\beta}_1) & var(\hat{\beta}_1) & cov(\hat{\beta}_1, \hat{\beta}_2) \\ cov(\hat{\beta}_0, \hat{\beta}_2) & cov(\hat{\beta}_1, \hat{\beta}_2) & var(\hat{\beta}_2) \\ \end{bmatrix}} \left[ \begin{matrix} 0 \\ 1 \\ 0 \end{matrix} \right]} \\ &= \sqrt{\small{\begin{bmatrix} cov(\hat{\beta}_0, \hat{\beta}_1) & var(\hat{\beta}_1) & cov(\hat{\beta}_1, \hat{\beta}_2) \end{bmatrix}} \left[ \begin{matrix} 0 \\ 1 \\ 0 \end{matrix} \right]} \\ &= \sqrt{var(\hat{\beta}_1)} = se(\hat{\beta}_1) \end{align}
Exemplo 2: H$_0: \ \beta_1 + \beta_2 = 2$
- Note que $h_1 = 2$
- O vetor $r'_1$ pode ser escrito como
-
Então, a hipótese nula é $$\text{H}_0:\ \boldsymbol{r}'_1 \boldsymbol{\beta}\ =\ \left[ \begin{matrix} 0 & 1 & 1 \end{matrix} \right] \left[ \begin{matrix} \beta_0 \\ \beta_1 \\ \beta_2 \end{matrix} \right] = 2\ \iff\ \beta_1 + \beta_2 = 2 $$
-
E o denomidor da estatística t é igual a: \begin{align} &\sqrt{\boldsymbol{r}'_1 \boldsymbol{V(\hat{\boldsymbol{\beta}})} \boldsymbol{r}_1} \\ &= \sqrt{\left[ \begin{matrix} 0 & 1 & 1 \end{matrix} \right] {\small \begin{bmatrix} var(\hat{\beta}_0) & cov(\hat{\beta}_0, \hat{\beta}_1) & cov(\hat{\beta}_0, \hat{\beta}_2) \\ cov(\hat{\beta}_0, \hat{\beta}_1) & var(\hat{\beta}_1) & cov(\hat{\beta}_1, \hat{\beta}_2) \\ cov(\hat{\beta}_0, \hat{\beta}_2) & cov(\hat{\beta}_1, \hat{\beta}_2) & var(\hat{\beta}_2) \\ \end{bmatrix}} \left[ \begin{matrix} 0 \\ 1 \\ 1 \end{matrix} \right]} \\ &= \sqrt{\small{\begin{bmatrix} cov(\hat{\beta}_0, \hat{\beta}_1)+cov(\hat{\beta}_0, \hat{\beta}_2) \\ var(\hat{\beta}_1) + cov(\hat{\beta}_1, \hat{\beta}_2) \\ cov(\hat{\beta}_1, \hat{\beta}_2) + var(\hat{\beta}_2) \end{bmatrix}}' \left[ \begin{matrix} 0 \\ 1 \\ 1 \end{matrix} \right]} \\ &= \sqrt{var(\hat{\beta}_1) + var(\hat{\beta}_2) + 2cov(\hat{\beta}_1, \hat{\beta}_2)} = \sqrt{var(\hat{\beta}_1 + \hat{\beta}_2)} \end{align}
Exemplo 3: H$_0: \ \beta_1 = \beta_2$
-
Note que $$\beta_1 = \beta_2 \iff \beta_1 - \beta_2 = 0 $$
-
Logo, $h_1 = 0$
-
O vetor $r'_1$ pode ser escrito como
-
Então, a hipótese nula é $$\text{H}_0:\ \boldsymbol{r}'_1 \boldsymbol{\beta}\ =\ \left[ \begin{matrix} 0 & 1 & -1 \end{matrix} \right] \left[ \begin{matrix} \beta_0 \\ \beta_1 \\ \beta_2 \end{matrix} \right] = 0\ \iff\ \beta_1 - \beta_2 = 0 $$
-
E o denomidor da estatística t é igual a: \begin{align} &\sqrt{\boldsymbol{r}'_1 \boldsymbol{V(\hat{\boldsymbol{\beta}})} \boldsymbol{r}_1} \\ &= \sqrt{\left[ \begin{matrix} 0 & 1 & -1 \end{matrix} \right] {\small \begin{bmatrix} var(\hat{\beta}_0) & cov(\hat{\beta}_0, \hat{\beta}_1) & cov(\hat{\beta}_0, \hat{\beta}_2) \\ cov(\hat{\beta}_0, \hat{\beta}_1) & var(\hat{\beta}_1) & cov(\hat{\beta}_1, \hat{\beta}_2) \\ cov(\hat{\beta}_0, \hat{\beta}_2) & cov(\hat{\beta}_1, \hat{\beta}_2) & var(\hat{\beta}_2) \\ \end{bmatrix}} \left[ \begin{matrix} 0 \\ 1 \\ -1 \end{matrix} \right]} \\ &= \sqrt{\small{\begin{bmatrix} cov(\hat{\beta}_0, \hat{\beta}_1)-cov(\hat{\beta}_0, \hat{\beta}_2) \\ var(\hat{\beta}_1) - cov(\hat{\beta}_1, \hat{\beta}_2) \\ cov(\hat{\beta}_1, \hat{\beta}_2) - var(\hat{\beta}_2) \end{bmatrix}}' \left[ \begin{matrix} 0 \\ 1 \\ -1 \end{matrix} \right]} \\ &= \sqrt{var(\hat{\beta}_1) + var(\hat{\beta}_2) - 2cov(\hat{\beta}_1, \hat{\beta}_2)} = \sqrt{var(\hat{\beta}_1 - \hat{\beta}_2)} \end{align}
Aplicando no R
(Continuação) Exemplo 7.5 - Equação do Log do Salário-Hora (Wooldridge, 2006)
- Anteriormente, estimamos o seguinte modelo:
\begin{align} \log(\text{wage}) = &\beta_0 + \beta_1 \text{female} + \beta_2 \text{married} + \delta_2 \text{female*married} + \beta_3 \text{educ} +\\ &\beta_4 \text{exper} + \beta_5 \text{exper}^2 + \beta_6 \text{tenure} + \beta_7 \text{tenure}^2 + \varepsilon \end{align} em que:
wage: salário médio por horafemale: dummy em que (1) mulher e (0) homemmarried: dummy em que (1) casado e (0) solteirofemale*married: interação (multiplicação) das dummiesfemaleemarriededuc: anos de educaçãoexper: anos de experiência (expersq= anos ao quadrado)tenure: anos de trabalho no empregador atual (tenursq= anos ao quadrado)
# Carregando a base de dados necessária
data(wage1, package="wooldridge")
# Estimando o modelo
res_7.14 = lm(lwage ~ female*married + educ + exper + expersq + tenure + tenursq, data=wage1)
round( summary(res_7.14)$coef, 4 )
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.3214 0.1000 3.2135 0.0014
## female -0.1104 0.0557 -1.9797 0.0483
## married 0.2127 0.0554 3.8419 0.0001
## educ 0.0789 0.0067 11.7873 0.0000
## exper 0.0268 0.0052 5.1118 0.0000
## expersq -0.0005 0.0001 -4.8471 0.0000
## tenure 0.0291 0.0068 4.3016 0.0000
## tenursq -0.0005 0.0002 -2.3056 0.0215
## female:married -0.3006 0.0718 -4.1885 0.0000
- Notamos que o efeito do casamento sobre mulheres é diferente do efeito sobre homens, pois o parâmetro de
female:married( $\delta_2$) é significante. - No entanto, para avaliar se o efeito do casamento sobre a mulher é significante, precisamos ver se H$_0 :\ \beta_2 + \delta_2 = 0$.
- Como tem apenas uma restrição, a hipótese pode ser avaliada por teste t:
# Extraindo objetos da regressão
bhat = matrix(coef(res_7.14), ncol=1) # coeficientes como vetor-coluna
Vbhat = vcov(res_7.14) # matriz de variância-covariância do estimador
N = nrow(wage1) # número de observações
K = length(bhat) - 1 # número de covariadas
ehat = residuals(res_7.14) # resíduos da regressão
# Criando vetor-linha de restrição
r1prime = matrix(c(0, 0, 1, 0, 0, 0, 0, 0, 1), nrow=1) # vetor restrição
h1 = 0 # constante da H0
G = 1 # número de restrições
# Fazendo teste t
t = (r1prime %*% bhat - h1) / sqrt(r1prime %*% Vbhat %*% t(r1prime))
abs(t)
## [,1]
## [1,] 1.679475
# Calculando o p-valor
p = 2 * pt(-abs(t), N-K-1)
p
## [,1]
## [1,] 0.09366368
-
Como $|t| < 2$ (valor crítico aproximada para nível de significância de 5%), então não rejeitamos a hipótese nula e concluímos que o efeito do casamento sobre o salário de mulheres ( $\beta_2 + \delta_2$) é estatisticamente não-significante.
-
Também podemos fazer o mesmo pelo teste de Wald, mas avaliando a estatística pela distribuição $\chi^2$ com 1 grau de liberdade (pois há apenas $G=1$ restrição)
-
Lembre-se também que usa-se o teste qui-quadrado unicaudal à direita.
# Calculando estatística de Wald
aux = r1prime %*% bhat - h1 # R \beta - h
w = t(aux) %*% solve( r1prime %*% Vbhat %*% t(r1prime)) %*% aux
w
## [,1]
## [1,] 2.820636
# Calculando p-valor de w
p = 1 - pchisq(w, df=G)
p
## [,1]
## [1,] 0.09305951
Múltiplas restrições lineares
Avaliando a hipótese nula com múltiplas restrições
-
Para o caso com G restrições, assumimos que $$ \boldsymbol{R} \hat{\boldsymbol{\beta}} \sim N(\boldsymbol{R} \hat{\boldsymbol{\beta}};\ \sigma^2 \boldsymbol{R} \boldsymbol{V(\hat{\boldsymbol{\beta}}) R'})$$
-
Calcula-se a estatística de Wald $$ w = \left[ \boldsymbol{R}\hat{\boldsymbol{\beta}} - \boldsymbol{h} \right]' \left[ \boldsymbol{R V(\hat{\beta}) R}' \right]^{-1} \left[ \boldsymbol{R}\hat{\boldsymbol{\beta}} - \boldsymbol{h} \right]\ \sim\ \chi^2_{(G)} $$
-
Escolhe-se o nível de significância $\alpha$ e rejeita-se a hipótese nula se a estatística $w$ não pertencer ao intervalo de confiança (do zero ao valor crítico).
Exemplo 4: H$_0: \ \beta_1 = 0\ \text{ e }\ \beta_1 + \beta_2 = 2$
- Note que $h_1 = 0 \text{ e } h_2 = 2$
- Os vetores $r'_1 \text{ e } r'_2$ podem ser escritos como
-
Logo, $\boldsymbol{R}$ é $$ \boldsymbol{R} = \left[ \begin{matrix} \boldsymbol{r}'_1 \\ \boldsymbol{r}'_2 \end{matrix} \right] = \left[ \begin{matrix} 0 & 1 & 0 \\ 0 & 1 & 1 \end{matrix} \right] $$
-
Então, a hipótese nula é $$\text{H}_0:\ \boldsymbol{R} \boldsymbol{\beta} = \left[ \begin{matrix} 0 & 1 & 0 \\ 0 & 1 & 1 \end{matrix} \right] \left[ \begin{matrix} \beta_0 \\ \beta_1 \\ \beta_2 \end{matrix} \right] = \left[ \begin{matrix} h_1 \\ h_2 \end{matrix} \right]\ \iff\ \text{H}_0:\ \left\{ \begin{matrix} \beta_1 &= 0 \\ \beta_1 + \beta_2 &= 2 \end{matrix} \right. $$
Aplicando no R
- Como exemplo, usaremos a base de dados
mlb1(pacotewooldridge) com estatísticas de jogadores de beisebol (Wooldridge, 2006, Seção 4.5) - Queremos estimar o modelo:
\begin{align} \log(\text{salary}) = &\beta_0 + \beta_1. \text{years} + \beta_2. \text{gameyr} + \beta_3. \text{bavg} + \\
&\beta_4 .\text{hrunsyr} + \beta_5. \text{rbisyr} + \varepsilon \end{align}
em que:
log(salary): log do salário de 1993years: anos jogando na 1ª divisão de beisebol americanogamesyr: média de jogos por anobavg: média de rebatidas na carreirahrunsyr: média de home runs por anorbisyr: média de corridas impulsionadas por ano
data(mlb1, package="wooldridge")
# Estimando o modelo completo (irrestrito)
resMLB = lm(log(salary) ~ years + gamesyr + bavg + hrunsyr + rbisyr, data=mlb1)
round(summary(resMLB)$coef, 5) # coeficientes da estimação
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11.19242 0.28882 38.75184 0.00000
## years 0.06886 0.01211 5.68430 0.00000
## gamesyr 0.01255 0.00265 4.74244 0.00000
## bavg 0.00098 0.00110 0.88681 0.37579
## hrunsyr 0.01443 0.01606 0.89864 0.36947
## rbisyr 0.01077 0.00717 1.50046 0.13440
-
Note que, individualmente, as variáveis
bavg,hrunsyrerbisyrsão estatisticamente não significantes. -
Queremos avaliar se eles são estatisticamente significantes de forma conjunta, ou seja, $$ \text{H}_0:\ \left\{ \begin{matrix} \beta_3 = 0 \\ \beta_4 = 0 \\ \beta_5 = 0\end{matrix} \right. $$
-
Logo, temos que $$ \boldsymbol{R} = \left[ \begin{matrix} \boldsymbol{r}'_1 \\ \boldsymbol{r}'_2 \\ \boldsymbol{r}'_3 \end{matrix} \right] = \left[ \begin{matrix} 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \end{matrix} \right] $$
Usando função Wald.test()
# Extraindo matriz de variância-covariância do estimador
Vbhat = vcov(resMLB)
round(Vbhat, 5)
## (Intercept) years gamesyr bavg hrunsyr rbisyr
## (Intercept) 0.08342 0.00001 -0.00027 -0.00029 -0.00148 0.00082
## years 0.00001 0.00015 -0.00001 0.00000 -0.00002 0.00001
## gamesyr -0.00027 -0.00001 0.00001 0.00000 0.00002 -0.00002
## bavg -0.00029 0.00000 0.00000 0.00000 0.00000 0.00000
## hrunsyr -0.00148 -0.00002 0.00002 0.00000 0.00026 -0.00010
## rbisyr 0.00082 0.00001 -0.00002 0.00000 -0.00010 0.00005
# Calculando a estatística de Wald
# install.packages("aod") # instalando o pacote necessário
aod::wald.test(Sigma = Vbhat, # matriz de variância-covariância
b = coef(resMLB), # estimativas
Terms = 4:6, # posições dos parâmetros a serem testados
H0 = c(0, 0, 0) # vetor h (tudo igual a zero)
)
## Wald test:
## ----------
##
## Chi-squared test:
## X2 = 28.7, df = 3, P(> X2) = 2.7e-06
- Observe que rejeitamos a hipótese nula e, portanto, os parâmetros $\beta_3, \beta_4 \text{ e } \beta_5$ são conjuntamente significantes.
Calculando “na mão”
- Estimando o modelo
# Criando variavel log_salary
mlb1$log_salary = log(mlb1$salary)
name_y = "log_salary"
names_X = c("years", "gamesyr", "bavg", "hrunsyr", "rbisyr")
# Criando o vetor y
y = as.matrix(mlb1[,name_y]) # transformando coluna de data frame em matriz
# Criando a matriz de covariadas X com primeira coluna de 1's
X = as.matrix( cbind( const=1, mlb1[,names_X] ) ) # juntando 1's com as covariadas
# Pegando valores N e K
N = nrow(mlb1)
K = ncol(X) - 1
# Estimando o modelo
bhat = solve( t(X) %*% X ) %*% t(X) %*% y
round(bhat, 5)
## [,1]
## const 11.19242
## years 0.06886
## gamesyr 0.01255
## bavg 0.00098
## hrunsyr 0.01443
## rbisyr 0.01077
# Calculando os resíduos
ehat = y - X %*% bhat
# Variância do termo de erro
sig2hat = as.numeric( t(ehat) %*% ehat / (N-K-1) )
# Matriz de variância-covariância do estimador
Vbhat = sig2hat * solve( t(X) %*% X )
round(Vbhat, 5)
## const years gamesyr bavg hrunsyr rbisyr
## const 0.08342 0.00001 -0.00027 -0.00029 -0.00148 0.00082
## years 0.00001 0.00015 -0.00001 0.00000 -0.00002 0.00001
## gamesyr -0.00027 -0.00001 0.00001 0.00000 0.00002 -0.00002
## bavg -0.00029 0.00000 0.00000 0.00000 0.00000 0.00000
## hrunsyr -0.00148 -0.00002 0.00002 0.00000 0.00026 -0.00010
## rbisyr 0.00082 0.00001 -0.00002 0.00000 -0.00010 0.00005
- Agora, vamos criar a matriz das restrições
# Número de restrições
G = 3
# Matriz das restrições
R = matrix(c(0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 1),
nrow=G, byrow=TRUE)
R
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 0 0 0 1 0 0
## [2,] 0 0 0 0 1 0
## [3,] 0 0 0 0 0 1
# Vetor de constantes h
h = matrix(c(0, 0, 0),
nrow=3, ncol=1)
h
## [,1]
## [1,] 0
## [2,] 0
## [3,] 0
- Lembre-se que, por padrão, a função
matrix()“preenche” a matrix por coluna. - No entanto, é mais intuito preencher as restrições por linha (já que cada linha representa uma restrição). Para isto, foi usado o argumento
byrow=TRUE. - Calculando a estatística de Wald, dada por $$ w(\hat{\boldsymbol{\beta}}) = \left[ \boldsymbol{R}\hat{\boldsymbol{\beta}} - \boldsymbol{h} \right]' \left[ \boldsymbol{R V_{\hat{\beta}} R}' \right]^{-1} \left[ \boldsymbol{R}\hat{\boldsymbol{\beta}} - \boldsymbol{h} \right]\ \sim\ \chi^2_{(G)} $$
# Estatística de Wald
w = t( R %*% bhat - h ) %*% solve( R %*% Vbhat %*% t(R) ) %*% (R %*% bhat - h)
w
## [,1]
## [1,] 28.65076
# Encontrando valor crítico Qui-quadrado para 5% de signif.
alpha = 0.05
c = qchisq(1-alpha, df=G)
c
## [1] 7.814728
# Comparando estatística de Wald e valor crítico
w > c
## [,1]
## [1,] TRUE
- Como Estatística de Wald (= 28,65) é maior do que o valor crítico (= 7,81), então rejeitamos a hipótese nula conjunta de que todos parâmetros testados são iguais a zero.
- Também poderíamos verificar o p-valor por meio da estatística de Wald:
1 - pchisq(w, df=G)
## [,1]
## [1,] 2.651604e-06
- Como é menor do que 5%, rejeita-se a hipótese nula.
Teste F
- Seção 4.3 de Heiss (2020)
- Uma outra forma de avaliar restrições múltiplas é por meio do teste F.
- Nele, estimamos dois modelos:
- Irrestrito: inclui todas as variáveis explicativas de interesse
- Restrito: exclui algumas variáveis da estimação
- O teste F compara as somas dos quadrados dos resíduos (SQR) ou os R$^2$ de ambos modelos.
- A ideia é: se as variáveis excluídas forem significantes conjuntamente, então haverá uma diferença de poder explicativo entre os modelos e, logo, as variáveis seriam significantes.
- A estatística F pode ser calculada por:
em que ur indica o modelo irrestrito, e r indica o modelo restrito.
- Depois, avalia-se a estatística F a partir de um teste unicaudal à direita em uma distribuição F:
Aplicando no R
-
Aqui, continuaremos usando a base de dados
mlb1da Seção 4.5 de Wooldridge (2006) -
O modelo irrestrito (com todas variáveis explicativas) é: \begin{align} \log(\text{salary}) = &\beta_0 + \beta_1. \text{years} + \beta_2. \text{gameyr} + \beta_3. \text{bavg} + \\ &\beta_4 .\text{hrunsyr} + \beta_5. \text{rbisyr} + \varepsilon \end{align}
-
O modelo restrito (excluindo as variáveis) é: \begin{align} \log(\text{salary}) = &\beta_0 + \beta_1. \text{years} + \beta_2. \text{gameyr} + \varepsilon \end{align}
Usando função linearHypothesis()
- É possível fazer o teste F a partir da função
linearHypothesis()do pacotecar - Além de incluir o objeto resultante de uma estimação, é necessário incluir um vetor de texto com as restrições:
# Estimando o modelo irrestrito
res.ur = lm(log(salary) ~ years + gamesyr + bavg + hrunsyr + rbisyr, data=mlb1)
# Criando vetor com as restrições
myH0 = c("bavg = 0", "hrunsyr = 0", "rbisyr = 0")
# Aplicando o teste F
# install.packages("car") # instalando o pacote necessário
car::linearHypothesis(res.ur, myH0)
## Linear hypothesis test
##
## Hypothesis:
## bavg = 0
## hrunsyr = 0
## rbisyr = 0
##
## Model 1: restricted model
## Model 2: log(salary) ~ years + gamesyr + bavg + hrunsyr + rbisyr
##
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 350 198.31
## 2 347 183.19 3 15.125 9.5503 4.474e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
- Note que na 2ª linha (modelo irrestrito), a soma dos quadrados dos resíduos (SQR/RSS) é menor do que o do modelo restrito e, portanto, o conjunto maior de covariadas tem um maior poder explicativo (o que é esperado)
- Para avaliar a hipótese nula ( $\beta_3 = \beta_4 = \beta_5 = 0$), podemos verificar se a estatística F é maior do que um valor crítico (dado um nível de significância), ou avaliarmos se o p-valor é menor do que esse nível de significância.
- É possível ver acima, pelo segundo critério, que rejeitamos a hipótese nula.
- Podemos ver o valor crítico a 5% de significância via:
qf(1-0.05, G, N-K-1)
## [1] 2.630641
- Como 9,55 > 2,63, então rejeitamos a hipótese nula.
Calculando “na mão”
- Aqui, vamos estimar os resultados dos modelos irrestrito e restrito, estimados por
lm()para não ter que fazer todos passos da estimação duas vezes.
# Estimando o modelo irrestrito
res.ur = lm(log(salary) ~ years + gamesyr + bavg + hrunsyr + rbisyr, data=mlb1)
# Estimando o modelo restrito
res.r = lm(log(salary) ~ years + gamesyr, data=mlb1)
# Extraindo os R2 dos resultados das estimações
r2.ur = summary(res.ur)$r.squared
r2.ur
## [1] 0.6278028
r2.r = summary(res.r)$r.squared
r2.r
## [1] 0.5970716
# Calculando a estatística F
F = ( r2.ur - r2.r ) / (1 - r2.ur) * (N-K-1) / G
F
## [1] 9.550254
# p-valor do teste F
1 - pf(F, G, N-K-1)
## [1] 4.473708e-06