Importar la base de datos

df <- read.csv("C:\\Users\\Emili\\OneDrive\\Desktop\\TEC\\Tec 6to Semestre Concentracion\\Modulo 2\\HousePriceData.csv")

Usar file.choose()

Entender la base de datos

str(df)
## 'data.frame':    905 obs. of  10 variables:
##  $ Observation  : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ Dist_Taxi    : int  9796 8294 11001 8301 10510 6665 13153 5882 7495 8233 ...
##  $ Dist_Market  : int  5250 8186 14399 11188 12629 5142 11869 9948 11589 7067 ...
##  $ Dist_Hospital: int  10703 12694 16991 12289 13921 9972 17811 13315 13370 11400 ...
##  $ Carpet       : int  1659 1461 1340 1451 1770 1442 1542 1261 1090 1030 ...
##  $ Builtup      : int  1961 1752 1609 1748 2111 1733 1858 1507 1321 1235 ...
##  $ Parking      : chr  "Open" "Not Provided" "Not Provided" "Covered" ...
##  $ City_Category: chr  "CAT B" "CAT B" "CAT A" "CAT B" ...
##  $ Rainfall     : int  530 210 720 620 450 760 1030 1020 680 1130 ...
##  $ House_Price  : int  6649000 3982000 5401000 5373000 4662000 4526000 7224000 3772000 4631000 4415000 ...
summary(df)
##   Observation      Dist_Taxi      Dist_Market    Dist_Hospital  
##  Min.   :  1.0   Min.   :  146   Min.   : 1666   Min.   : 3227  
##  1st Qu.:237.0   1st Qu.: 6477   1st Qu.: 9367   1st Qu.:11302  
##  Median :469.0   Median : 8228   Median :11149   Median :13189  
##  Mean   :468.4   Mean   : 8235   Mean   :11022   Mean   :13091  
##  3rd Qu.:700.0   3rd Qu.: 9939   3rd Qu.:12675   3rd Qu.:14855  
##  Max.   :932.0   Max.   :20662   Max.   :20945   Max.   :23294  
##                                                                 
##      Carpet         Builtup        Parking          City_Category     
##  Min.   :  775   Min.   :  932   Length:905         Length:905        
##  1st Qu.: 1317   1st Qu.: 1579   Class :character   Class :character  
##  Median : 1478   Median : 1774   Mode  :character   Mode  :character  
##  Mean   : 1511   Mean   : 1794                                        
##  3rd Qu.: 1654   3rd Qu.: 1985                                        
##  Max.   :24300   Max.   :12730                                        
##  NA's   :7                                                            
##     Rainfall       House_Price       
##  Min.   :-110.0   Min.   :  1492000  
##  1st Qu.: 600.0   1st Qu.:  4623000  
##  Median : 780.0   Median :  5860000  
##  Mean   : 786.9   Mean   :  6083992  
##  3rd Qu.: 970.0   3rd Qu.:  7200000  
##  Max.   :1560.0   Max.   :150000000  
## 

Eliminar Valores Atipicos

df <- df[-349, ]

Generar el modelo

regresion <- lm(House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital + Carpet + factor(Parking) + factor(City_Category) + Rainfall, data=df)
summary(regresion)
## 
## Call:
## lm(formula = House_Price ~ Dist_Taxi + Dist_Market + Dist_Hospital + 
##     Carpet + factor(Parking) + factor(City_Category) + Rainfall, 
##     data = df)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -4365818 -1143410   -40235  1148630 11949292 
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 -2.131e+06  3.994e+05  -5.335 1.22e-07 ***
## Dist_Taxi                    5.910e+01  3.908e+01   1.512  0.13080    
## Dist_Market                  4.281e+01  3.031e+01   1.412  0.15818    
## Dist_Hospital                1.759e+01  4.381e+01   0.401  0.68818    
## Carpet                       5.739e+03  7.587e+01  75.641  < 2e-16 ***
## factor(Parking)No Parking   -5.484e+05  2.021e+05  -2.713  0.00679 ** 
## factor(Parking)Not Provided -3.133e+05  1.796e+05  -1.744  0.08150 .  
## factor(Parking)Open         -1.369e+05  1.641e+05  -0.834  0.40444    
## factor(City_Category)CAT B  -1.983e+06  1.399e+05 -14.176  < 2e-16 ***
## factor(City_Category)CAT C  -2.980e+06  1.541e+05 -19.338  < 2e-16 ***
## Rainfall                     1.585e+02  2.244e+02   0.707  0.48001    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1782000 on 886 degrees of freedom
##   (7 observations deleted due to missingness)
## Multiple R-squared:  0.8797, Adjusted R-squared:  0.8783 
## F-statistic: 647.8 on 10 and 886 DF,  p-value: < 2.2e-16

Generar Pronosticos

datos_nuevos <- data.frame(Dist_Taxi=9796, Dist_Market=5250, Dist_Hospital= 10703, Carpet= 1659, Parking="Open", City_Category="CAT B", Rainfall=530)
predict(regresion, datos_nuevos)
##       1 
## 6346536

Conclusiones

Al incluir todas la variables, el modelo es altamente significativo con un poder explicativo del 94%.
“Builtup” y “Carpet” presentan indicios de multicolinealidad. Al remover la primer variable, el modelo continua siendo altamente significativo con un poder explicativo del 88%.
Las distancias a diferentes establecimientos y la lluvia no son tomados en cuenta para definir el precio.
Todos las varaibles significativas para el modelo representan un efecto negativo hacia el precio, a excepcion de “Carpet”, la cual logicamente tiene un efecto positivo.