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
modelo_estimado_libreria<-lm(formula = price~lotsize+sqrft+bdrms, data = hprice1)
library(stargazer)
stargazer(modelo_estimado_libreria, title = "Modelo Estimado Regresion Lineal",type="html", digits=5)
##
## <table style="text-align:center"><caption><strong>Modelo Estimado Regresion Lineal</strong></caption>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td><em>Dependent variable:</em></td></tr>
## <tr><td></td><td colspan="1" style="border-bottom: 1px solid black"></td></tr>
## <tr><td style="text-align:left"></td><td>price</td></tr>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">lotsize</td><td>0.00207<sup>***</sup></td></tr>
## <tr><td style="text-align:left"></td><td>(0.00064)</td></tr>
## <tr><td style="text-align:left"></td><td></td></tr>
## <tr><td style="text-align:left">sqrft</td><td>0.12278<sup>***</sup></td></tr>
## <tr><td style="text-align:left"></td><td>(0.01324)</td></tr>
## <tr><td style="text-align:left"></td><td></td></tr>
## <tr><td style="text-align:left">bdrms</td><td>13.85252</td></tr>
## <tr><td style="text-align:left"></td><td>(9.01015)</td></tr>
## <tr><td style="text-align:left"></td><td></td></tr>
## <tr><td style="text-align:left">Constant</td><td>-21.77031</td></tr>
## <tr><td style="text-align:left"></td><td>(29.47504)</td></tr>
## <tr><td style="text-align:left"></td><td></td></tr>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Observations</td><td>88</td></tr>
## <tr><td style="text-align:left">R<sup>2</sup></td><td>0.67236</td></tr>
## <tr><td style="text-align:left">Adjusted R<sup>2</sup></td><td>0.66066</td></tr>
## <tr><td style="text-align:left">Residual Std. Error</td><td>59.83348 (df = 84)</td></tr>
## <tr><td style="text-align:left">F Statistic</td><td>57.46023<sup>***</sup> (df = 3; 84)</td></tr>
## <tr><td colspan="2" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"><em>Note:</em></td><td style="text-align:right"><sup>*</sup>p<0.1; <sup>**</sup>p<0.05; <sup>***</sup>p<0.01</td></tr>
## </table>
Se Encuentra el P Value para prueba T
cof<-summary(modelo_estimado_libreria)$coefficients
t_value<-cof[,"t value"]
nombres<-names(t_value)
Para Prueba T
library(fastGraph)
shadeDist(qt(c(.025, .975),df=5),ddist="dnorm",parm1=0,lower.tail=T,col=c("black","red"), main = "Forma Grafica Valor T")
Prueba T desde P Valor
shadeDist(c(-.025, .025),ddist="dnorm",parm1=0,lower.tail=T,col=c("black","green"), main = "Forma Grafica de P Valor",xmin=-0.03,xmax = 0.03)
Para prueba F
pruebaf<-summary(modelo_estimado_libreria)
shadeDist(57.46023,ddist="dchisq",parm1 =qf(0.05,84,3),lower.tail=F,col=c("black","yellow"), main = "Prueba F Valor Critico")
pruebaf2<-summary(modelo_estimado_libreria)
shadeDist(0,ddist="dchisq",parm1 =0.05,lower.tail=F,col=c("black","green"), main = "Prueba F para valor p")
Para Distribucion Chi Cuadrado
library(lmtest)
Prueba_de_White<-bptest(modelo_estimado_libreria,~I(lotsize^2)+I(sqrft^2)+(bdrms^2)+lotsize*sqrft+bdrms, data = hprice1)
print(Prueba_de_White)
##
## studentized Breusch-Pagan test
##
## data: modelo_estimado_libreria
## BP = 32.606, df = 6, p-value = 0.00001248
library(fastGraph)
LM_w<-Prueba_de_White$BP
VC<-qchisq(p = 0.95,df = 6+choose(3,2))
shadeDist(LM_w,ddist = 'dchisq',parm1 =VC,lower.tail = FALSE)
el Valor LMw, que en los resultados se define como BP es mayor al X cuadrado encontrado en la tabla Chi Cuadrado, quiere decir, segun la teoria, hay existencia de heterocedasticidad en el modelo, lo que significa que la varianza de los errores de dichas variables explicativas no es constante
Desde el enfoque de Valor P
shadeDist(Prueba_de_White$p.value,ddist="dchisq",parm1 = 1,lower.tail=F,col=c("black","yellow"), main = "Grafico Chi Cuadrado desde Enfoque de Vaor P")
Distribucion Normal (Z)
pruebashapiro<-shapiro.test(modelo_estimado_libreria$residuals)
qqnorm(modelo_estimado_libreria$residuals)
qqline(modelo_estimado_libreria$residuals)
print(pruebashapiro)
##
## Shapiro-Wilk normality test
##
## data: modelo_estimado_libreria$residuals
## W = 0.94132, p-value = 0.0005937
Con la prueba de Shapiro-Wilk existe suficiente evidencia para rechazar la hipotesis nula y se demuestra que no hay evidencia de que los residuos mantenganuna distribucion normal con varianza constante
Distribucion Normal (Z) desde P Valor
shadeDist(c(-pruebashapiro$p.value,pruebashapiro$p.value),,ddist="dnorm",parm1=0,lower.tail=T,col=c("black","darkblue"), main = "Grafico de Distribucion Normal desde P valor", xmin=-0.001,xmax = 0.001)