Introduction

This analysis uses the Dodgers dataset to examine attendance, temperature, opponents, game time, and promotional events. The purpose is to determine which factors may help explain attendance at Dodgers home games.

rm(list = ls())

DodgersData <- read.csv("DodgersData.csv",
                        stringsAsFactors = FALSE)

head(DodgersData)
##   month day attend day_of_week opponent temp  skies day_night cap shirt
## 1   APR  10  56000     Tuesday  Pirates   67 Clear        Day  NO    NO
## 2   APR  11  29729   Wednesday  Pirates   58 Cloudy     Night  NO    NO
## 3   APR  12  28328    Thursday  Pirates   57 Cloudy     Night  NO    NO
## 4   APR  13  31601      Friday   Padres   54 Cloudy     Night  NO    NO
## 5   APR  14  46549    Saturday   Padres   57 Cloudy     Night  NO    NO
## 6   APR  15  38359      Sunday   Padres   65 Clear        Day  NO    NO
##   fireworks bobblehead
## 1        NO         NO
## 2        NO         NO
## 3        NO         NO
## 4       YES         NO
## 5        NO         NO
## 6        NO         NO
str(DodgersData)
## 'data.frame':    81 obs. of  12 variables:
##  $ month      : chr  "APR" "APR" "APR" "APR" ...
##  $ day        : int  10 11 12 13 14 15 23 24 25 27 ...
##  $ attend     : int  56000 29729 28328 31601 46549 38359 26376 44014 26345 44807 ...
##  $ day_of_week: chr  "Tuesday" "Wednesday" "Thursday" "Friday" ...
##  $ opponent   : chr  "Pirates" "Pirates" "Pirates" "Padres" ...
##  $ temp       : int  67 58 57 54 57 65 60 63 64 66 ...
##  $ skies      : chr  "Clear " "Cloudy" "Cloudy" "Cloudy" ...
##  $ day_night  : chr  "Day" "Night" "Night" "Night" ...
##  $ cap        : chr  "NO" "NO" "NO" "NO" ...
##  $ shirt      : chr  "NO" "NO" "NO" "NO" ...
##  $ fireworks  : chr  "NO" "NO" "NO" "YES" ...
##  $ bobblehead : chr  "NO" "NO" "NO" "NO" ...

Question 1A

DodgersData[25, c("temp", "attend", "opponent", "bobblehead")]
##    temp attend opponent bobblehead
## 25   61  36561   Astros         NO

Question 1B

median_attendance <- median(DodgersData$attend,
                            na.rm = TRUE)

median_attendance
## [1] 40284

Question 2

boxplot(attend ~ bobblehead,
        data = DodgersData,
        main = "Dodgers Attendance by Bobblehead Promotion",
        xlab = "Bobblehead Promotion",
        ylab = "Attendance",
        col = c("lightblue", "lightgreen"))

The box plot compares attendance for games with and without bobblehead promotions. Games with bobblehead promotions generally had higher attendance than games without them. This suggests that promotions may encourage more fans to attend Dodgers games. However, attendance is also affected by other factors, such as the opponent, weather, and day of the week.

Question 3

DodgersData$month <- as.factor(DodgersData$month)
DodgersData$day_of_week <- as.factor(DodgersData$day_of_week)
DodgersData$bobblehead <- as.factor(DodgersData$bobblehead)

dodgers_model <- lm(attend ~ month + day_of_week + bobblehead,
                    data = DodgersData)

summary(dodgers_model)
## 
## Call:
## lm(formula = attend ~ month + day_of_week + bobblehead, data = DodgersData)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -10786.5  -3628.1   -516.1   2230.2  14351.0 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          38792.98    2364.68  16.405  < 2e-16 ***
## monthAUG              2377.92    2402.91   0.990   0.3259    
## monthJUL              2849.83    2578.60   1.105   0.2730    
## monthJUN              7163.23    2732.72   2.621   0.0108 *  
## monthMAY             -2385.62    2291.22  -1.041   0.3015    
## monthOCT              -662.67    4046.45  -0.164   0.8704    
## monthSEP                29.03    2521.25   0.012   0.9908    
## day_of_weekMonday    -4883.82    2504.65  -1.950   0.0554 .  
## day_of_weekSaturday   1488.24    2442.68   0.609   0.5444    
## day_of_weekSunday     1840.18    2426.79   0.758   0.4509    
## day_of_weekThursday  -4108.45    3381.22  -1.215   0.2286    
## day_of_weekTuesday    3027.68    2686.43   1.127   0.2638    
## day_of_weekWednesday -2423.80    2485.46  -0.975   0.3330    
## bobbleheadYES        10714.90    2419.52   4.429 3.59e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 6120 on 67 degrees of freedom
## Multiple R-squared:  0.5444, Adjusted R-squared:  0.456 
## F-statistic: 6.158 on 13 and 67 DF,  p-value: 2.083e-07

The regression results suggest that bobblehead promotions had a positive relationship with Dodgers attendance. According to the model, games with a bobblehead promotion had approximately 10,715 more fans than games without a bobblehead promotion, while controlling for the month and day of the week. The p-value was less than 0.001, which means the relationship was statistically significant. The model explained about 54.4% of the variation in attendance. This shows that the model was helpful, but other factors not included in the model also affected attendance.