library(readxl)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
BD_Precio <- read_excel("~/Desktop/R/BD_Precio.xlsx")
baseX <- read_excel("~/Desktop/R/baseX.xlsx")
baseY <- read_excel("~/Desktop/R/baseY.xlsx")
baseXY <- read_excel("~/Desktop/R/baseXY.xlsx")
attach(BD_Precio)
names(BD_Precio)
## [1] "Columna 1" "Precio" "Terreno" "Construcción"
## [5] "Baños" "Recámaras" "Estacionamiento" "Edad"
## [9] "Privada"
#attach(BD_Precio)
# B = ((X'X)^-1X'Y)
mx=data.matrix(baseX)
my=data.matrix(baseY)
Xt=t(mx)
XtY=Xt%*%my
XtX=Xt%*%mx
XtXi = solve(XtX)
B=XtXi%*%XtY
#Correlación entre Variables
cor(Terreno,Precio)
## [1] 0.8574874
cor(Construcción,Precio)
## [1] 0.9085217
cor(Baños,Precio)
## [1] 0.516519
cor(Recámaras,Precio)
## [1] 0.2563773
cor(Estacionamiento,Precio)
## [1] 0.7065584
cor(Edad,Precio)
## [1] -0.1595029
cor(Privada,Precio)
## [1] 0.4121894
#Gráficas de la Base y jarque.bera.test
plot(Terreno, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
plot(Construcción, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
plot(Baños, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
plot(Recámaras, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
plot(Estacionamiento, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
plot(Edad, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
plot(Privada, Precio, data=BD_Precio)
## Warning in plot.window(...): "data" is not a graphical parameter
## Warning in plot.xy(xy, type, ...): "data" is not a graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in axis(side = side, at = at, labels = labels, ...): "data" is not a
## graphical parameter
## Warning in box(...): "data" is not a graphical parameter
## Warning in title(...): "data" is not a graphical parameter
jarque.bera.test(Precio)
##
## Jarque Bera Test
##
## data: Precio
## X-squared = 1800.9, df = 2, p-value < 2.2e-16
jarque.bera.test(Terreno)
##
## Jarque Bera Test
##
## data: Terreno
## X-squared = 6076.6, df = 2, p-value < 2.2e-16
jarque.bera.test(Construcción)
##
## Jarque Bera Test
##
## data: Construcción
## X-squared = 2581.8, df = 2, p-value < 2.2e-16
jarque.bera.test(Baños)
##
## Jarque Bera Test
##
## data: Baños
## X-squared = 33.834, df = 2, p-value = 4.498e-08
jarque.bera.test(Recámaras)
##
## Jarque Bera Test
##
## data: Recámaras
## X-squared = 195.54, df = 2, p-value < 2.2e-16
jarque.bera.test(Estacionamiento)
##
## Jarque Bera Test
##
## data: Estacionamiento
## X-squared = 198.02, df = 2, p-value < 2.2e-16
jarque.bera.test(Edad)
##
## Jarque Bera Test
##
## data: Edad
## X-squared = 71.44, df = 2, p-value = 3.331e-16
jarque.bera.test(Privada)
##
## Jarque Bera Test
##
## data: Privada
## X-squared = 20.936, df = 2, p-value = 2.844e-05
#Modelo (log log)
modelo_log_log=lm(log(Precio)~log(Terreno)+log(Construcción)+log(Baños)+log(Recámaras)+log(Estacionamiento)+log(Edad)+Privada,data=BD_Precio)
summary(modelo_log_log)
##
## Call:
## lm(formula = log(Precio) ~ log(Terreno) + log(Construcción) +
## log(Baños) + log(Recámaras) + log(Estacionamiento) + log(Edad) +
## Privada, data = BD_Precio)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.08669 -0.21050 -0.01806 0.19709 0.91994
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.37578 0.32918 28.482 < 2e-16 ***
## log(Terreno) 0.54253 0.08448 6.422 3.00e-09 ***
## log(Construcción) 0.60241 0.09396 6.411 3.17e-09 ***
## log(Baños) 0.13669 0.09308 1.469 0.145
## log(Recámaras) -0.15948 0.12859 -1.240 0.217
## log(Estacionamiento) 0.11774 0.08907 1.322 0.189
## log(Edad) -0.03303 0.02514 -1.314 0.192
## Privada 0.39802 0.07257 5.485 2.42e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3341 on 117 degrees of freedom
## Multiple R-squared: 0.8935, Adjusted R-squared: 0.8871
## F-statistic: 140.2 on 7 and 117 DF, p-value: < 2.2e-16
#Histograma y jarque.bera.test
rM1=resid(modelo_log_log) #Obtiene los residuales del modelo 1
hist(rM1)
jarque.bera.test(rM1)
##
## Jarque Bera Test
##
## data: rM1
## X-squared = 0.83396, df = 2, p-value = 0.659