Datos a Utilizar

library(wooldridge)
data("hprice1")
head(force(hprice1), n = 5)
##   price assess bdrms lotsize sqrft colonial   lprice  lassess llotsize   lsqrft
## 1   300  349.1     4    6126  2438        1 5.703783 5.855359 8.720297 7.798934
## 2   370  351.5     3    9903  2076        1 5.913503 5.862210 9.200593 7.638198
## 3   191  217.7     3    5200  1374        0 5.252274 5.383118 8.556414 7.225482
## 4   195  231.8     3    4600  1448        1 5.273000 5.445875 8.433811 7.277938
## 5   373  319.1     4    6095  2514        1 5.921578 5.765504 8.715224 7.829630

#1. estime el siguiente modelo,

price = ˆα + ˆα1(lotsize) + ˆα2(sqrft) + ˆα3(bdrms) + e

 modelo_estimado <- lm( formula = price ~ lotsize + sqrft + bdrms, data = hprice1)
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
stargazer(modelo_estimado, title = 'Modelo estimado', type = 'text')
## 
## Modelo estimado
## ===============================================
##                         Dependent variable:    
##                     ---------------------------
##                                price           
## -----------------------------------------------
## lotsize                      0.002***          
##                               (0.001)          
##                                                
## sqrft                        0.123***          
##                               (0.013)          
##                                                
## bdrms                         13.853           
##                               (9.010)          
##                                                
## Constant                      -21.770          
##                              (29.475)          
##                                                
## -----------------------------------------------
## Observations                    88             
## R2                             0.672           
## Adjusted R2                    0.661           
## Residual Std. Error      59.833 (df = 84)      
## F Statistic           57.460*** (df = 3; 84)   
## ===============================================
## Note:               *p<0.1; **p<0.05; ***p<0.01
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
datos2 <- select(hprice1, price, lotsize, sqrft, bdrms)
modelo_estimado2 <- lm(formula = price ~ lotsize + sqrft + bdrms, data = datos2)

2. Verifique si los residuos del modelo son independientes entre sí (no autocorrelación), a través de:

#a) Prueba de Durbin Watson.

library(lmtest)
## Warning: package 'lmtest' was built under R version 4.0.5
## Warning: package 'zoo' was built under R version 4.0.5
dwtest(modelo_estimado2, alternative = "two.side",iterations = 1000 )
## 
##  Durbin-Watson test
## 
## data:  modelo_estimado2
## DW = 2.1098, p-value = 0.6218
## alternative hypothesis: true autocorrelation is not 0
#Como p value es mucho mayor que el indice de confiaza. y se concluye que no hay presencia de autocorrelacion de primer orden

#b) Prueba del Multiplicador de Lagrange (verifique autocorrelación de primer y segundo orden). #de primer orden

library(lmtest)
bgtest(modelo_estimado2, order = 1)
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  modelo_estimado2
## LM test = 0.39362, df = 1, p-value = 0.5304
# p > indice de confianza. no hay sificiente evidencia de autocorrelacion de primer orden

#de orden superior(orden m)

library(lmtest)
bgtest(modelo_estimado2, order = 2)
## 
##  Breusch-Godfrey test for serial correlation of order up to 2
## 
## data:  modelo_estimado2
## LM test = 3.0334, df = 2, p-value = 0.2194
# p > indice de confianza. no hay sificiente evidencia de autocorrelacion de segundo orden