# Importar la base de datos
## Store Date Weekly_Sales Holiday_Flag
## Min. : 1 Length:6435 Min. : 209986 Min. :0.00000
## 1st Qu.:12 Class :character 1st Qu.: 553350 1st Qu.:0.00000
## Median :23 Mode :character Median : 960746 Median :0.00000
## Mean :23 Mean :1046965 Mean :0.06993
## 3rd Qu.:34 3rd Qu.:1420159 3rd Qu.:0.00000
## Max. :45 Max. :3818686 Max. :1.00000
## Temperature Fuel_Price CPI Unemployment
## Min. : -2.06 Min. :2.472 Min. :126.1 Min. : 3.879
## 1st Qu.: 47.46 1st Qu.:2.933 1st Qu.:131.7 1st Qu.: 6.891
## Median : 62.67 Median :3.445 Median :182.6 Median : 7.874
## Mean : 60.66 Mean :3.359 Mean :171.6 Mean : 7.999
## 3rd Qu.: 74.94 3rd Qu.:3.735 3rd Qu.:212.7 3rd Qu.: 8.622
## Max. :100.14 Max. :4.468 Max. :227.2 Max. :14.313
## 'data.frame': 6435 obs. of 8 variables:
## $ Store : int 1 1 1 1 1 1 1 1 1 1 ...
## $ Date : chr "05-02-2010" "12-02-2010" "19-02-2010" "26-02-2010" ...
## $ Weekly_Sales: num 1643691 1641957 1611968 1409728 1554807 ...
## $ Holiday_Flag: int 0 1 0 0 0 0 0 0 0 0 ...
## $ Temperature : num 42.3 38.5 39.9 46.6 46.5 ...
## $ Fuel_Price : num 2.57 2.55 2.51 2.56 2.62 ...
## $ CPI : num 211 211 211 211 211 ...
## $ Unemployment: num 8.11 8.11 8.11 8.11 8.11 ...
df$Month <- format(df$Date, "%m")
df$Month <- as.integer(df$Month)
df$Day <- format(df$Date, "%d")
df$Day <- as.integer(df$Day)
#df$Year <- format(df$Date, "%Y")
#df$Year <- as.integer(df$Year)
#df$WeekDay <- format(df$Date, "%u") #Inicia en lunes
#df$WeekDay <- as.integer(df$WeekDay)
df$WeekYear <- format(df$Date, "%W") #Inicia en lunes
df$WeekYear <- as.integer(df$WeekYear)##
## Call:
## lm(formula = Weekly_Sales ~ ., data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1094800 -382464 -42860 375406 2587123
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2716040.65 1471779.49 1.845 0.0650 .
## Store -15384.99 520.19 -29.576 < 2e-16 ***
## Date -70.43 79.35 -0.888 0.3748
## Holiday_Flag 47726.21 27064.04 1.763 0.0779 .
## Temperature -1817.31 405.32 -4.484 7.47e-06 ***
## Fuel_Price 61238.34 28755.79 2.130 0.0332 *
## CPI -2109.06 192.77 -10.941 < 2e-16 ***
## Unemployment -22090.54 3966.76 -5.569 2.67e-08 ***
## Month 117654.10 385750.62 0.305 0.7604
## Day 2170.57 12689.24 0.171 0.8642
## WeekYear -23298.88 89087.15 -0.262 0.7937
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 520900 on 6424 degrees of freedom
## Multiple R-squared: 0.1495, Adjusted R-squared: 0.1482
## F-statistic: 113 on 10 and 6424 DF, p-value: < 2.2e-16
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
df_ajustada <- df %>% select(-Store, -Date, -Month:-WeekYear, -Fuel_Price)
regresion <- lm(Weekly_Sales ~ .,data=df_ajustada)
summary(regresion)##
## Call:
## lm(formula = Weekly_Sales ~ ., data = df_ajustada)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1020421 -477999 -115859 396128 2800875
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1687798.2 52515.7 32.139 < 2e-16 ***
## Holiday_Flag 75760.1 27605.3 2.744 0.00608 **
## Temperature -773.1 393.2 -1.966 0.04930 *
## CPI -1570.0 189.9 -8.267 < 2e-16 ***
## Unemployment -41235.7 3942.0 -10.460 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 557300 on 6430 degrees of freedom
## Multiple R-squared: 0.02538, Adjusted R-squared: 0.02477
## F-statistic: 41.86 on 4 and 6430 DF, p-value: < 2.2e-16