Contexto: Una empresa de renta de bicicletas quiere obtener un pronostico de rentas mensuales para el próximo año.

El “file.choose() fue hecho a través de la consola de R”

df <- read.csv("C:\\Users\\memil\\OneDrive\\Desktop\\aaTecDeMonterrey\\5to Semestre\\SemanaTecProgra\\rentadebicis (2).csv")

summary(df)
##       hora            dia              mes              año      
##  Min.   : 0.00   Min.   : 1.000   Min.   : 1.000   Min.   :2011  
##  1st Qu.: 6.00   1st Qu.: 5.000   1st Qu.: 4.000   1st Qu.:2011  
##  Median :12.00   Median :10.000   Median : 7.000   Median :2012  
##  Mean   :11.54   Mean   : 9.993   Mean   : 6.521   Mean   :2012  
##  3rd Qu.:18.00   3rd Qu.:15.000   3rd Qu.:10.000   3rd Qu.:2012  
##  Max.   :23.00   Max.   :19.000   Max.   :12.000   Max.   :2012  
##     estacion     dia_de_la_semana     asueto         temperatura   
##  Min.   :1.000   Min.   :1.000    Min.   :0.00000   Min.   : 0.82  
##  1st Qu.:2.000   1st Qu.:2.000    1st Qu.:0.00000   1st Qu.:13.94  
##  Median :3.000   Median :4.000    Median :0.00000   Median :20.50  
##  Mean   :2.507   Mean   :4.014    Mean   :0.02857   Mean   :20.23  
##  3rd Qu.:4.000   3rd Qu.:6.000    3rd Qu.:0.00000   3rd Qu.:26.24  
##  Max.   :4.000   Max.   :7.000    Max.   :1.00000   Max.   :41.00  
##  sensacion_termica    humedad       velocidad_del_viento
##  Min.   : 0.76     Min.   :  0.00   Min.   : 0.000      
##  1st Qu.:16.66     1st Qu.: 47.00   1st Qu.: 7.002      
##  Median :24.24     Median : 62.00   Median :12.998      
##  Mean   :23.66     Mean   : 61.89   Mean   :12.799      
##  3rd Qu.:31.06     3rd Qu.: 77.00   3rd Qu.:16.998      
##  Max.   :45.45     Max.   :100.00   Max.   :56.997      
##  rentas_de_no_registrados rentas_de_registrados rentas_totales 
##  Min.   :  0.00           Min.   :  0.0         Min.   :  1.0  
##  1st Qu.:  4.00           1st Qu.: 36.0         1st Qu.: 42.0  
##  Median : 17.00           Median :118.0         Median :145.0  
##  Mean   : 36.02           Mean   :155.6         Mean   :191.6  
##  3rd Qu.: 49.00           3rd Qu.:222.0         3rd Qu.:284.0  
##  Max.   :367.00           Max.   :886.0         Max.   :977.0
#Día es de 1 - 19, no hasta el 31.
#La base de datos es de 2011-2012.
#Día 1 = Domingo
options(scipen = 9999)
plot(df$temperatura, df$rentas_totales, main="Influencia de la temperatura sobre las rentas", xlab="Temperatura", ylab="Rentas Totales")

regresion <- lm(rentas_totales ~ hora + dia + mes + año + estacion + dia_de_la_semana + asueto + temperatura + sensacion_termica + humedad + velocidad_del_viento, data =df)

summary(regresion)
## 
## Call:
## lm(formula = rentas_totales ~ hora + dia + mes + año + estacion + 
##     dia_de_la_semana + asueto + temperatura + sensacion_termica + 
##     humedad + velocidad_del_viento, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -305.52  -93.64  -27.70   61.85  649.10 
## 
## Coefficients:
##                           Estimate    Std. Error t value             Pr(>|t|)
## (Intercept)          -166088.13519    5496.44048 -30.217 < 0.0000000000000002
## hora                       7.73502       0.20700  37.368 < 0.0000000000000002
## dia                        0.38436       0.24819   1.549              0.12150
## mes                        9.99563       1.68200   5.943        0.00000000289
## año                       82.58441       2.73229  30.225 < 0.0000000000000002
## estacion                  -7.77367       5.17712  -1.502              0.13324
## dia_de_la_semana           0.43929       0.69180   0.635              0.52545
## asueto                    -4.86435       8.36472  -0.582              0.56089
## temperatura                1.58175       1.03786   1.524              0.12752
## sensacion_termica          4.74849       0.95523   4.971        0.00000067607
## humedad                   -2.11520       0.07884 -26.827 < 0.0000000000000002
## velocidad_del_viento       0.55819       0.18086   3.086              0.00203
##                         
## (Intercept)          ***
## hora                 ***
## dia                     
## mes                  ***
## año                  ***
## estacion                
## dia_de_la_semana        
## asueto                  
## temperatura             
## sensacion_termica    ***
## humedad              ***
## velocidad_del_viento ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 141.7 on 10874 degrees of freedom
## Multiple R-squared:  0.3891, Adjusted R-squared:  0.3885 
## F-statistic: 629.6 on 11 and 10874 DF,  p-value: < 0.00000000000000022
regresion2 <- lm(rentas_totales ~ hora + mes + año + sensacion_termica + humedad + velocidad_del_viento, data =df)

summary(regresion2)
## 
## Call:
## lm(formula = rentas_totales ~ hora + mes + año + sensacion_termica + 
##     humedad + velocidad_del_viento, data = df)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -308.60  -93.85  -28.34   61.05  648.09 
## 
## Coefficients:
##                           Estimate    Std. Error t value             Pr(>|t|)
## (Intercept)          -166245.29647    5495.62373 -30.250 < 0.0000000000000002
## hora                       7.73428       0.20700  37.364 < 0.0000000000000002
## mes                        7.57371       0.42071  18.002 < 0.0000000000000002
## año                       82.66237       2.73191  30.258 < 0.0000000000000002
## sensacion_termica          6.17185       0.16891  36.539 < 0.0000000000000002
## humedad                   -2.12076       0.07858 -26.988 < 0.0000000000000002
## velocidad_del_viento       0.62084       0.17708   3.506             0.000457
##                         
## (Intercept)          ***
## hora                 ***
## mes                  ***
## año                  ***
## sensacion_termica    ***
## humedad              ***
## velocidad_del_viento ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 141.7 on 10879 degrees of freedom
## Multiple R-squared:  0.3886, Adjusted R-squared:  0.3883 
## F-statistic:  1153 on 6 and 10879 DF,  p-value: < 0.00000000000000022
datos <- data.frame(hora = 12, mes = 1:12, año = 2013, sensacion_termica = 23.66, humedad = 61.89, velocidad_del_viento = 12.79)
predict(regresion2,datos)
##        1        2        3        4        5        6        7        8 
## 277.1523 284.7260 292.2997 299.8734 307.4471 315.0209 322.5946 330.1683 
##        9       10       11       12 
## 337.7420 345.3157 352.8894 360.4631