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 |
swtest<-shapiro.test(modelo_precio$residuals)
qqnorm(modelo_precio$residuals)
qqline(modelo_precio$residuals)
print(swtest)
##
## Shapiro-Wilk normality test
##
## data: modelo_precio$residuals
## W = 0.94132, p-value = 0.0005937
Con libreria \(FastGraphs\)
library(fastGraph)
# Los argumentos son los siguientes
#shadeDist(xshade, ddist = "dnorm", parm1 = NULL, parm2 = NULL, lower.tail = T)
shadeDist(c(-swtest$statistic,swtest$statistic),ddist="dnorm",parm1=0,lower.tail=T,col=c("black","green"), main = "Distribucion Z Valor Critico")
library(fastGraph)
# Los argumentos son los siguientes
#shadeDist(xshade, ddist = "distribucion", parm1 = NULL, parm2 = NULL, lower.tail = T)
shadeDist(c(-swtest$p.value,swtest$p.value),,ddist="dnorm",parm1=0,lower.tail=T,col=c("black","pink"), main = "Distribucion Z P-Value", xmin=-0.001,xmax = 0.001)
library(fastGraph)
# Los argumentos son los siguientes
#shadeDist(xshade, ddist = "dnorm", parm1 = NULL, parm2 = NULL, lower.tail = T)
shadeDist(qt(c(.025, .975),df=5),ddist="dnorm",parm1=0,lower.tail=T,col=c("black","darkgrey"), main = "Distribucion T Valor Critico")
library(fastGraph)
# Los argumentos son los siguientes
#shadeDist(xshade, ddist = "dnorm", parm1 = NULL, parm2 = NULL, lower.tail = T)
shadeDist(c(-.025, .025),ddist="dnorm",parm1=0,lower.tail=T,col=c("black","red"), main = "Distribucion T P-Value",xmin=-0.03,xmax = 0.03)
library(lmtest)
Wtest<-bptest(modelo_precio,~I(lotsize^2)+I(sqrft^2)+I(bdrms^2)+lotsize*sqrft+lotsize*bdrms+sqrft*bdrms,data = hprice1)
print(Wtest)
##
## studentized Breusch-Pagan test
##
## data: modelo_precio
## BP = 33.732, df = 9, p-value = 0.00009953
gl=3*2+choose(3,2)
VC<-qchisq(p = 0.95,df = gl)
library(fastGraph)
# Los argumentos son los siguientes
#shadeDist(xshade, ddist = "dchisq", parm1 = NULL, parm2 = NULL, lower.tail = F)
shadeDist(Wtest$statistic,ddist="dchisq",parm1=VC,lower.tail=F,col=c("black","cyan"), main = "Distribucion Chi cuadrado Valor Critico")
shadeDist(Wtest$p.value,ddist="dchisq",parm1 = 1,lower.tail=F,col=c("black","brown"), main = "Distribucion Chi cuadrado P-Value")
PF<-summary(modelo_precio)
shadeDist(57.46023,ddist="dchisq",parm1 =qf(0.05,84,3),lower.tail=F,col=c("black","purple"), main = "Distribucion F Valor Critico")
PF<-summary(modelo_precio)
shadeDist(0,ddist="dchisq",parm1 =0.05,lower.tail=F,col=c("black","purple"), main = "Distribucion F P-Value")