Summarise the dataset using descriptive statistics.
Visualise the relationship between each predictor and the outcome (score_outcome).
4.2 Solution
Code
# Summary of the datasetsummary(football_data)# Visualisation example: Minutes Played vs Score Outcomeggplot(football_data, aes(x=score_outcome, y=minutes_played, fill=score_outcome)) +geom_violin(trim=FALSE, alpha=0.5) +geom_boxplot(width=0.1, outlier.shape=NA) +geom_jitter(width=0.1, alpha=0.3, color="black") +labs(title="Minutes Played vs Score Outcome", x="Score Outcome", y="Minutes Played") +theme_minimal() +theme(legend.position="none")
5 Fit a Logistic Regression Model
5.1 Instructions
Fit a logistic regression model to predict score_outcome using all predictors. You need to convert the outcome to a numeric variable (0 = No Score, 1 = Score).
Interpret the model summary.
5.2 Solution
Code
# Convert score_outcome to numeric (0 = No Score, 1 = Score)football_data$score_outcome_binary <-ifelse(football_data$score_outcome =="Score", 1, 0)# Fit logistic regression model using the binary outcomelogit_model <-glm(score_outcome_binary ~ player_position + minutes_played + shots_on_target + assists + defensive_pressure + fatigue_level, data = football_data, family = binomial)summary(logit_model)
6 A Note on Factors in Regression
6.1 Interpreting Factor Variables in Logistic Regression
In logistic regression, factor variables represent categorical data (like player_position) with two or more categories. R handles these factors by creating dummy variables (also known as indicator variables).
6.2 Key Concepts
Reference Category: R automatically selects one category as the reference (usually the first level alphabetically unless specified). The coefficients for other categories are interpreted relative to this reference.
Interpretation of Coefficients:
A positive coefficient means the category increases the log-odds of scoring compared to the reference.
A negative coefficient decreases the log-odds of scoring.
Odds Ratios: Converting coefficients to odds ratios (exp(coef)) helps in understanding the magnitude of the effect.
6.3 Example
# Check the levels of player_positionlevels(football_data$player_position)
NULL
# Fit logistic regression with player_positionlogit_model <-glm(score_outcome_binary ~ player_position + minutes_played + shots_on_target + assists + defensive_pressure + fatigue_level, data = football_data, family = binomial)summary(logit_model)
Call:
glm(formula = score_outcome_binary ~ player_position + minutes_played +
shots_on_target + assists + defensive_pressure + fatigue_level,
family = binomial, data = football_data)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.57361 1.32565 -1.941 0.052211 .
player_positionForward 0.58691 0.48764 1.204 0.228749
player_positionMidfielder -0.30626 0.52452 -0.584 0.559295
minutes_played 0.03537 0.01425 2.481 0.013096 *
shots_on_target 0.25403 0.11530 2.203 0.027582 *
assists 0.43043 0.23134 1.861 0.062797 .
defensive_pressure -0.26614 0.08671 -3.069 0.002145 **
fatigue_level -0.35567 0.10357 -3.434 0.000594 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 197.36 on 199 degrees of freedom
Residual deviance: 156.09 on 192 degrees of freedom
AIC: 172.09
Number of Fisher Scoring iterations: 5
# Convert coefficients to odds ratiosexp(coef(logit_model))