library(wooldridge)
library(printr)
data(hprice1)
head(force(hprice1),n=5)
| price | assess | bdrms | lotsize | sqrft | colonial | lprice | lassess | llotsize | lsqrft |
|---|---|---|---|---|---|---|---|---|---|
| 300 | 349.1 | 4 | 6126 | 2438 | 1 | 5.703783 | 5.855359 | 8.720297 | 7.798934 |
| 370 | 351.5 | 3 | 9903 | 2076 | 1 | 5.913503 | 5.862210 | 9.200593 | 7.638198 |
| 191 | 217.7 | 3 | 5200 | 1374 | 0 | 5.252274 | 5.383118 | 8.556414 | 7.225481 |
| 195 | 231.8 | 3 | 4600 | 1448 | 1 | 5.273000 | 5.445875 | 8.433811 | 7.277938 |
| 373 | 319.1 | 4 | 6095 | 2514 | 1 | 5.921578 | 5.765504 | 8.715224 | 7.829630 |
modelo_precio<-lm(formula = price~lotsize+sqrft+bdrms,data = hprice1)
library(stargazer)
stargazer(modelo_precio,title="Modelo Precio",type = "html", digits=4)
| Dependent variable: | |
| price | |
| lotsize | 0.0021*** |
| (0.0006) | |
| sqrft | 0.1228*** |
| (0.0132) | |
| bdrms | 13.8525 |
| (9.0101) | |
| Constant | -21.7703 |
| (29.4750) | |
| Observations | 88 |
| R2 | 0.6724 |
| Adjusted R2 | 0.6607 |
| Residual Std. Error | 59.8335 (df = 84) |
| F Statistic | 57.4602*** (df = 3; 84) |
| Note: | p<0.1; p<0.05; p<0.01 |
\(u_i=\rho u_{i-1}+v_i\)
\(H_0 : \rho=0\) No hay evidencia de autocorrelación de primer orden, en los residuos del modelo
\(H_A : \rho \neq 0\) Hay evidencia de autocorrelación de primer orden, en los residuos del modelo
library(lmtest)
dwtest(modelo_precio,alternative = "two.sided",iterations = 1000)
##
## Durbin-Watson test
##
## data: modelo_precio
## DW = 2.1098, p-value = 0.6218
## alternative hypothesis: true autocorrelation is not 0
library(car)
durbinWatsonTest(modelo_precio,simulate = TRUE,reps = 1000)
## lag Autocorrelation D-W Statistic p-value
## 1 -0.05900522 2.109796 0.66
## Alternative hypothesis: rho != 0
\(u_j=\rho_1 u_{j-1}+\rho_2 u_{j-2}+\rho_3 u_{j-3}+...+v_j\)
\(H_0 : \rho_1=\rho_2=\rho_3=...=\rho_m=0\) No hay evidencia de autocorrelación de orden “m”, en los residuos del modelo
\(H_A : \rho_1=\rho_2=\rho_3=...=\rho_m \neq 0\)$ Hay evidencia de autocorrelación de orden “m”, en los residuos del modelo
library(lmtest)
bgtest(modelo_precio,order = 1)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: modelo_precio
## LM test = 0.39362, df = 1, p-value = 0.5304
library(lmtest)
bgtest(modelo_precio,order = 2)
##
## Breusch-Godfrey test for serial correlation of order up to 2
##
## data: modelo_precio
## LM test = 3.0334, df = 2, p-value = 0.2194