Setup

figsize[inches_] := inches(468/3.125);

Input data for English Premier League 2019-2020

{rawdata} = 
Import["/Users/dmeyer/Teaching/180Awinter20/Lecture15/Premier201920.xlsx"];
Print[Style[rawdata,Red,18]];

Organize data

longgoals = {};
game = 0;
Do[
record = rawdata[[i]];
If[NumberQ[record[[1]]],
game = game+1;
goals = Complement[Union[record],{""}];
If[goals≠{0.},
goals = 90(game-1)+goals;
longgoals = Join[longgoals,goals]
]
],
{i,1,Length[rawdata]}
];
Print[Style[longgoals,Red,18]];

Plot data

plotdata =
Table[{longgoals[[i]],1},{i,1,Length[longgoals]}];
plot =
ListPlot[plotdata,
PlotStyle->Red,
Filling->Axis,
AspectRatio->1/(4GoldenRatio),
BaseStyle->{FontSize->18},
AxesOrigin->{0,0},
Ticks->{{900,1800,2700,3600,4500,5400},{1}},
AxesLabel->{"minute",""},
PlotLabel->"Premier League goals, 1st 60 games 2019-2020",
ImageSize->figsize[5]
];

Show[plot]

Analyze data

aggregate[t_,data_]:=
Module[{Npart,counts,part},
Nparts = 5400/t;
counts = 
Table[
Length[Select[data,(part-1)*t<#≤part*t &]],
{part,1,Nparts}
];
{Mean[counts],Sort[Tally[counts]]}
];

t = (1/4)*90;
{λ,data} = aggregate[t,longgoals];

max = First[Last[data]];
Print[
Style["maximum # goals in ",Red,18],
Style[t,Red,18],
Style[" minutes = ",Red,18],
Style[max,Red,18]
];
Print[
Style["average # goals in ",Red,18],
Style[t,Red,18],
Style[" minutes = ",Red,18],
Style[N[λ],Red,18]
];
Print[];
freq = Table[{data[[i,1]],t*data[[i,2]]/5400},{i,1,Length[data]}];
maxf = Max[Last[Transpose[freq]]];

dataplot =
ListPlot[
freq,
PlotStyle->Directive[Red],
AxesStyle->Directive[Thick,Black],
BaseStyle->{FontSize->18},
AxesOrigin->{0,0},
AxesLabel->{"# goals","prob"},
PlotLabel->"Premier League goals/t minutes, 1st 60 games 2019-2020",
ImageSize->figsize[5]
];
model = Table[{k,E^(-λ) λ^k/k!},{k,0,max}];
modelplot =
ListPlot[
model,
PlotStyle->Directive[Blue],
AxesStyle->Directive[Thick,Black],
BaseStyle->{FontSize->18},
AxesOrigin->{0,0},
AxesLabel->{"# goals","prob"},
PlotLabel->"Premier League goals/t minutes, 1st 60 games 2019-2020",
ImageSize->figsize[5]
];
label =
Graphics[
{Text[Style["length t = ",Black,18],{max-1,maxf},{1,0}],
Text[Style[t,Black,18],{max-1,maxf},{-1,0}],
Text[Style["mean λ = ",Red,18],{max-1,0.9maxf},{1,0}],
Text[Style[N[λ],Red,18],{max-1,0.9maxf},{-1,0}],
Text[Style["Poisson(λ)",Blue,18],{max-1,0.8maxf},{0.9,0}]
}
];
Show[
dataplot,modelplot,label
]

Re-organize data

t = 90;
{λ,data} = aggregate[t,longgoals];
firsts = {};
seconds = {};
Do[
record = rawdata[[i]];
If[NumberQ[record[[1]]],
goals = Complement[Union[record],{""}];
If[goals≠{0.},
first = goals[[1]];
AppendTo[firsts,first];
If[Length[goals]≥ 2,
second = goals[[2]];
AppendTo[seconds,second],
AppendTo[seconds,91]
],
AppendTo[firsts,91]
]
],
{i,1,Length[rawdata]}
];
Nfirsts = Length[firsts];
Nseconds = Length[seconds];
Print[
Style["times to first goal:  ",Red,18],
Style[Sort[firsts],Red,18]
];
Print[];
Print[
Style["times to second goal:  ",Red,18],
Style[Sort[seconds],Red,18]
];

Plot data

uniquefirsts = Union[firsts];
fractions = 
Table[
{uniquefirsts[[i]],Length[Select[firsts,#≤uniquefirsts[[i]] &]]/Nfirsts},
{i,1,Length[uniquefirsts]}
];

staircase ={};
Do[
AppendTo[staircase,fractions[[i]]];
AppendTo[staircase,{fractions[[i+1,1]],fractions[[i,2]]}],
{i,1,Length[fractions]-1}
];
staircase = PrependTo[staircase,{fractions[[1,1]],0}];
staircase = PrependTo[staircase,{0,0}];
(*staircase = AppendTo[staircase,Last[fractions]];*)

staircaseplot = 
Graphics[
{Thick,
Red,Line[staircase]
}
];
expplot =
Plot[
1 - E^(-λ*(t/90)),{t,0,90},
PlotStyle->Directive[Blue],
AxesStyle->Directive[Thick,Black],
BaseStyle->{FontSize->18},
AxesOrigin->{0,0},
AxesLabel->{"minutes","CDF"},
PlotLabel->"Time to first goal, Premier League 1st 60 games 2019-2020",
ImageSize->figsize[5]
];
label =
Graphics[
{Text[Style["rate λ = ",Red,18],{60,0.4},{1,0}],
Text[Style[N[λ],Red,18],{60,0.4},{-1,0}],Text[Style["Exp(λ)",Blue,18],{60,0.33},{1.6,0}]
}
];
Show[
expplot,staircaseplot,label,
Axes->True,
AspectRatio->1/GoldenRatio,
AxesStyle->Directive[Large,Black],
AxesLabel->{"minutes","CDF"},
Ticks->{{15,30,45,60,75,90},Automatic},
PlotRange->{{0,92},{0,1.01}},
ImageSize->figsize[5]
]

uniqueseconds = Union[seconds];
fractions = 
Table[
{uniqueseconds[[i]],Length[Select[seconds,#≤uniqueseconds[[i]] &]]/Nseconds},
{i,1,Length[uniqueseconds]}
];

staircase ={};
Do[
AppendTo[staircase,fractions[[i]]];
AppendTo[staircase,{fractions[[i+1,1]],fractions[[i,2]]}],
{i,1,Length[fractions]-1}
];
staircase = PrependTo[staircase,{fractions[[1,1]],0}];
staircase = PrependTo[staircase,{0,0}];
(*staircase = AppendTo[staircase,Last[fractions]];*)

staircaseplot = 
Graphics[
{Thick,
Red,Line[staircase]
}
];
expplot =
Plot[
1 - E^(-λ*(t/90)) - (λ*t/90)E^(-λ*(t/90)),{t,0,90},
PlotStyle->Directive[Blue],
AxesStyle->Directive[Thick,Black],
BaseStyle->{FontSize->18},
AxesOrigin->{0,0},
AxesLabel->{"minutes","CDF"},
PlotLabel->"Time to second goal, Premier League 1st 60 games 2019-2020",
ImageSize->figsize[5]
];
label =
Graphics[
{Text[Style["rate λ = ",Red,18],{70,0.4},{1,0}],
Text[Style[N[λ],Red,18],{70,0.4},{-1,0}],Text[Style["Gamma(2,λ)",Blue,18],{70,0.33},{0.35,0}]
}
];
Show[
expplot,staircaseplot,label,
Axes->True,
AspectRatio->1/GoldenRatio,
AxesStyle->Directive[Large,Black],
AxesLabel->{"minutes","CDF"},
Ticks->{{15,30,45,60,75,90},Automatic},
PlotRange->{{0,92},{0,1.01}},
ImageSize->figsize[5]
]