yorkr pads up for Twenty20s:Part 4- Individual batting and bowling performances!


Introduction

In theory, theory and practice are the same. In practice, they’re not.

                      Yogi Berra

There are two ways to write error-free programs; only the third one works.

                      Alan Perlis

Simplicity does not precede complexity, but follows it.

                      Alan Perlis

Talk is cheap. Show me the code.

                      Linus Torvalds

This post is the 4th and the last part of yorkr padding for the Twenty20s. In this post I look at the top individual batting and bowling performances in the Twenty20s. Also please take a look at my 3 earlier post on yorkr’s handling of Twenty20 matches

  1. yorkr pads up for the Twenty20s: Part 1- Analyzing team“s match performance.
  2. yorkr pads up for the Twenty20s: Part 2-Head to head confrontation between teams
  3. yorkr pads up for the Twenty20s:Part 3:Overall team performance against all oppositions!

The 1st part included functions dealing with a specific T20 match, the 2nd part dealt with functions between 2 opposing teams in T20 confrontations. The 3rd part dealt with functions between a team and all T20 matches with all oppositions. This 4th part includes individual batting and bowling performances in T20 matches and deals with Class 4 functions.

This post has also been published at RPubs yorkrT20-Part4 and can also be downloaded as a PDF document from yorkrT20-Part4.pdf.

You can clone/fork the code for the package yorkr from Github at yorkr-package

The list of Class 4 functions are shown below.The Twenty20 features will be available from yorkr_0.0.4

Take a look at my book with all my articles related to yorkr now available at Amazon in paperback and Kindle formats  Beaten by sheer pace! Cricket analytics with yorkr. The book is also available at Leanpub, which has a variable pricing Beaten by sheer pace! Cricket analytics with yorkr.

Checkout my interactive Shiny apps GooglyPlus (plots & tables) and Googly (only plots) which can be used to analyze IPL players, teams and matches.

Note: To do similar analysis you can use my yorkrT20templates. See my post Analysis of International T20 matches with yorkr templates

Batsman functions

  1. batsmanRunsVsDeliveries
  2. batsmanFoursSixes
  3. batsmanDismissals
  4. batsmanRunsVsStrikeRate
  5. batsmanMovingAverage
  6. batsmanCumulativeAverageRuns
  7. batsmanCumulativeStrikeRate
  8. batsmanRunsAgainstOpposition
  9. batsmanRunsVenue
  10. batsmanRunsPredict

Bowler functions

  1. bowlerMeanEconomyRate
  2. bowlerMeanRunsConceded
  3. bowlerMovingAverage
  4. bowlerCumulativeAvgWickets
  5. bowlerCumulativeAvgEconRate
  6. bowlerWicketPlot
  7. bowlerWicketsAgainstOpposition
  8. bowlerWicketsVenue
  9. bowlerWktsPredict

Note: The yorkr package in its current avatar only supports ODI & Twenty20 matches. I will be upgrading the package to handle IPL in the months to come.

library(yorkr)
library(gridExtra)
library(rpart.plot)
library(dplyr)
library(ggplot2)
rm(list=ls())

A. Batsman functions

1. Get Team Batting details

The function below gets the overall team batting details based on the RData file available in T20 matches. This is currently also available in Github at [yorkrData] (https://github.com/tvganesh/yorkrData/tree/master/Twenty20/T20-matches). The batting details of the team in each match is created and a huge data frame is created by rbinding the individual dataframes. This can be saved as a RData file

setwd("C:/software/cricket-package/york-test/yorkrData/Twenty20/T20-matches")
india_details <- getTeamBattingDetails("India",dir=".", save=TRUE)
sa_details <- getTeamBattingDetails("South Africa",dir=".",save=TRUE)
nz_details <- getTeamBattingDetails("New Zealand",dir=".",save=TRUE)
eng_details <- getTeamBattingDetails("England",dir=".",save=TRUE)
pak_details <- getTeamBattingDetails("Pakistan",dir=".",save=TRUE)
aus_details <- getTeamBattingDetails("Australia",dir=".",save=TRUE)
wi_details <- getTeamBattingDetails("West Indies",dir=".",save=TRUE)

2. Get batsman details

This function is used to get the individual T20 batting record for a the specified batsman of the country as in the functions below. For analyzing the batting performances the top T20 batsmen from different countries have been chosen. The batting scorecard functions from yorkr pads up for the Twenty20s:Part 3:Overall team performance against all oppositions! was used for selecting these batsmen

  1. Virat Kohli (Ind)
  2. DA Warner (Aus)
  3. Umar Akmal (Pak)
  4. BB McCullum (NZ)
  5. EJG Morgan (Eng)
  6. CH Gayle (WI)
setwd("C:/software/cricket-package/cricsheet/cleanup/T20/rmd/part4")
kohli <- getBatsmanDetails(team="India",name="Kohli",dir=".")
## [1] "./India-BattingDetails.RData"
warner <- getBatsmanDetails(team="Australia",name="DA Warner")
## [1] "./Australia-BattingDetails.RData"
akmal <-  getBatsmanDetails(team="Pakistan",name="Umar Akmal",dir=".")
## [1] "./Pakistan-BattingDetails.RData"
mccullum <-  getBatsmanDetails(team="New Zealand",name="BB McCullum",dir=".")
## [1] "./New Zealand-BattingDetails.RData"
emorgan <-  getBatsmanDetails(team="England",name="EJG Morgan",dir=".")
## [1] "./England-BattingDetails.RData"
gayle <-  getBatsmanDetails(team="West Indies",name="CH Gayle",dir=".")
## [1] "./West Indies-BattingDetails.RData"

3. Runs versus deliveries

Chris Gayle and B McCullum have an astounding strike rate and touch close to 120 runs in 60 balls. David Warner also has a great strike rate

p1 <-batsmanRunsVsDeliveries(kohli,"Kohli")
p2 <-batsmanRunsVsDeliveries(warner, "DA Warner")
p3 <-batsmanRunsVsDeliveries(akmal,"U Akmal")
p4 <-batsmanRunsVsDeliveries(mccullum,"BB McCullum")
p5 <-batsmanRunsVsDeliveries(emorgan,"EJG Morgan")
p6 <-batsmanRunsVsDeliveries(gayle,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

runsVsDeliveries-1

4. Batsman Total runs, Fours and Sixes

The plots below show the total runs, fours and sixes by the batsmen. Gayle tops in the runs from sixes

kohli46 <- select(kohli,batsman,ballsPlayed,fours,sixes,runs)
p1 <- batsmanFoursSixes(kohli46,"Kohli")
warner46 <- select(warner,batsman,ballsPlayed,fours,sixes,runs)
p2 <- batsmanFoursSixes(warner46,"DA Warner")
akmal46 <- select(akmal,batsman,ballsPlayed,fours,sixes,runs)
p3 <- batsmanFoursSixes(akmal46, "U Akmal")
mccullum46 <- select(mccullum,batsman,ballsPlayed,fours,sixes,runs)
p4 <- batsmanFoursSixes(mccullum46,"BB McCullum")
emorgan46 <- select(emorgan,batsman,ballsPlayed,fours,sixes,runs)
p5 <- batsmanFoursSixes(emorgan46,"EJG Morgan")
gayle46 <- select(gayle,batsman,ballsPlayed,fours,sixes,runs)
p6 <- batsmanFoursSixes(gayle46,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

foursSixes-1

5. Batsman dismissals

The type of dismissal for each batsman is shown below

p1 <-batsmanDismissals(kohli,"Kohli")
p2 <-batsmanDismissals(warner, "DA Warner")
p3 <-batsmanDismissals(akmal,"U Akmal")
p4 <-batsmanDismissals(mccullum,"BB McCullum")
p5 <-batsmanDismissals(emorgan,"EJG Morgan")
p6 <-batsmanDismissals(gayle,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

dismissal-1

6. Runs versus Strike Rate

Gayle’s and McCullum’s strike rate touch 120% for runs in the range of 130-150

p1 <-batsmanRunsVsStrikeRate(kohli,"Kohli")
p2 <-batsmanRunsVsStrikeRate(warner, "DA Warner")
p3 <-batsmanRunsVsStrikeRate(akmal,"U Akmal")
p4 <-batsmanRunsVsStrikeRate(mccullum,"BB McCullum")
p5 <-batsmanRunsVsStrikeRate(emorgan,"EJG Morgan")
p6 <-batsmanRunsVsStrikeRate(gayle,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

runsSR-1

7. Batsman moving average

Kohli and Gayle T20 average is on the increase touching 50. Eoin Morgan and BB McCullum average around 40.

p1 <-batsmanMovingAverage(kohli,"Kohli")
p2 <-batsmanMovingAverage(warner, "DA Warner")
p3 <-batsmanMovingAverage(akmal,"U Akmal")
p4 <-batsmanMovingAverage(mccullum,"BB McCullum")
p5 <-batsmanMovingAverage(emorgan,"EJG Morgan")
p6 <-batsmanMovingAverage(gayle,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

ma-1

8. Batsman cumulative average

Kohli’s cumulative average steadies around 40, McCullum shows a gentle decline from 40+ to 35+. Gayle oscillates between 30+ to 40-.

p1 <-batsmanCumulativeAverageRuns(kohli,"Kohli")
p2 <-batsmanCumulativeAverageRuns(warner, "DA Warner")
p3 <-batsmanCumulativeAverageRuns(akmal,"U Akmal")
p4 <-batsmanCumulativeAverageRuns(mccullum,"BB McCullum")
p5 <-batsmanCumulativeAverageRuns(emorgan,"EJG Morgan")
p6 <-batsmanCumulativeAverageRuns(gayle,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cAvg-1

9. Cumulative Average Strike Rate

BB McCullum has the best overall cumulative strike rate which hovered around the 150 and steadies around 130. Gayle has a rocky cumulative strike between 150 -130s. Warner is steady around 120.

p1 <-batsmanCumulativeStrikeRate(kohli,"Kohli")
p2 <-batsmanCumulativeStrikeRate(warner, "DA Warner")
p3 <-batsmanCumulativeStrikeRate(akmal,"U Akmal")
p4 <-batsmanCumulativeStrikeRate(mccullum,"BB McCullum")
p5 <-batsmanCumulativeStrikeRate(emorgan,"EJG Morgan")
p6 <-batsmanCumulativeStrikeRate(gayle,"CH Gayle")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cSR-1

10. Batsman runs against opposition

#Kohli's best performances are against New Zealand and Sri Lanka
batsmanRunsAgainstOpposition(kohli,"Kohli")

runsOppn1-1

batsmanRunsAgainstOpposition(warner, "DA Warner")

runsOppn2-1

batsmanRunsAgainstOpposition(akmal,"U Akmal")

runsOppn3-1

batsmanRunsAgainstOpposition(mccullum,"BB McCullum")

runsOppn4-1

batsmanRunsAgainstOpposition(emorgan,"EJG Morgan")

runsOppn5-1

# Gayle's best performance is against India and South Africa
batsmanRunsAgainstOpposition(gayle,"CH Gayle")

runsOppn6-1

11. Runs at different venues

The plots below give the performances of the batsmen at different grounds.

batsmanRunsVenue(kohli,"Kohli")

runsVenue1-1

batsmanRunsVenue(warner, "DA Warner")

runsVenue2-1

batsmanRunsVenue(akmal,"U Akmal")

runsVenue3-1

batsmanRunsVenue(mccullum,"BB McCullum")

runsVenue4-1

batsmanRunsVenue(emorgan,"EJG Morgan")

runsVenue5-1

batsmanRunsVenue(gayle,"CH Gayle")

runsVenue6-1

12. Predict number of runs to deliveries

The plots below use rpart classification tree to predict the number of deliveries required to score the runs in the leaf node. For e.g. Kohli takes

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsmanRunsPredict(kohli,"Kohli")
batsmanRunsPredict(warner, "DA Warner")
batsmanRunsPredict(akmal,"U Akmal")

runsPredict1,runsVenue1-1

# BB McCullum needs >32 deliveries to score 69+ runs while Gayle needs >28 deliveries to score 67 runs
par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsmanRunsPredict(mccullum,"BB McCullum")
batsmanRunsPredict(emorgan,"EJG Morgan")
batsmanRunsPredict(gayle,"CH Gayle")

runsPredict2,runsVenue1-1

B. Bowler functions

13. Get bowling details

The function below gets the overall team T20 bowling details based on the RData file available in T20 matches. This is currently also available in Github at [yorkrData] (https://github.com/tvganesh/yorkrData/tree/master/Twenty20/T20-matches). The T20 bowling details of the team in each match is created and a huge data frame is created by rbinding the individual dataframes. This can be saved as a RData file

setwd("C:/software/cricket-package/york-test/yorkrData/Twenty20/T20-matches")
ind_bowling <- getTeamBowlingDetails("India",dir=".",save=TRUE)
dim(ind_bowling)
## [1] 872  12
aus_bowling <- getTeamBowlingDetails("Australia",dir=".",save=TRUE)
dim(aus_bowling)
## [1] 1364   12
eng_bowling <- getTeamBowlingDetails("England",dir=".",save=TRUE)
dim(eng_bowling)
## [1] 1183   12
sa_bowling <- getTeamBowlingDetails("South Africa",dir=".",save=TRUE)
dim(sa_bowling)
## [1] 995  12
pak_bowling <- getTeamBowlingDetails("Pakistan",dir=".",save=TRUE)
dim(pak_bowling)
## [1] 1186   12
nz_bowling <- getTeamBowlingDetails("New Zealand",dir=".",save=TRUE)
dim(nz_bowling)
## [1] 1295   12

14. Get bowling details of the individual bowlers

This function is used to get the individual bowling record for a specified bowler of the country as in the functions below. For analyzing the bowling performances the following cricketers have been chosen

  1. Ravichander Ashwin (Ind)
  2. SR Watson (Aus)
  3. SCJ Broad (Eng)
  4. Saeed Ajmal (Pak)
  5. Dale Steyn (SA)
  6. NL McCullum (NZ)
ashwin <- getBowlerWicketDetails(team="India",name="Ashwin",dir=".")
watson <-  getBowlerWicketDetails(team="Australia",name="SR Watson",dir=".")
broad <-  getBowlerWicketDetails(team="England",name="SCJ Broad",dir=".")
ajmal <-  getBowlerWicketDetails(team="Pakistan",name="Saeed Ajmal",dir=".")
steyn <-  getBowlerWicketDetails(team="South Africa",name="Steyn",dir=".")
nmccullum <-  getBowlerWicketDetails(team="New Zealand",name="NL McCullum",dir=".")

15. Bowler Mean Economy Rate

Ashwin has a mean economy rate of 5.0 for 3 & 4 overs. Saeed Ajmal is more expensive

p1<-bowlerMeanEconomyRate(ashwin,"R Ashwin")
p2<-bowlerMeanEconomyRate(watson, "SR Watson")
p3<-bowlerMeanEconomyRate(broad, "SCJ Broad")
p4<-bowlerMeanEconomyRate(ajmal, "Saeed Ajmal")
p5<-bowlerMeanEconomyRate(steyn, "D Steyn")
p6<-bowlerMeanEconomyRate(nmccullum, "NL Mccullum")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

meanER-1

16. Bowler Mean Runs conceded

p1<-bowlerMeanRunsConceded(ashwin,"R Ashwin")
p2<-bowlerMeanRunsConceded(watson, "SR Watson")
p3<-bowlerMeanRunsConceded(broad, "SCJ Broad")
p4<-bowlerMeanRunsConceded(ajmal, "Saeed Ajmal")
p5<-bowlerMeanRunsConceded(steyn, "D Steyn")
p6<-bowlerMeanRunsConceded(nmccullum, "NL Mccullum")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

meanRunsConceded-1

17. Bowler Moving average

Aswin, SCJ Broad and Steyn have an improving performance in T20s. NL McCullum has a drop and Ajmal’s performance is on the decline

p1<-bowlerMovingAverage(ashwin,"R Ashwin")
p2<-bowlerMovingAverage(watson, "SR Watson")
p3<-bowlerMovingAverage(broad, "SCJ Broad")
p4<-bowlerMovingAverage(ajmal, "Saeed Ajmal")
p5<-bowlerMovingAverage(steyn, "D Steyn")
p6<-bowlerMovingAverage(nmccullum, "NL Mccullum")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

bowlerMA-1

17. Bowler cumulative average wickets

Interestingly Ajmal and NL McCullum have a cumulative average wickets of around 2.0. Steyn also has a cumulative average of 2.0+

p1<-bowlerCumulativeAvgWickets(ashwin,"R Ashwin")
p2<-bowlerCumulativeAvgWickets(watson, "SR Watson")
p3<-bowlerCumulativeAvgWickets(broad, "SCJ Broad")
p4<-bowlerCumulativeAvgWickets(ajmal, "Saeed Ajmal")
p5<-bowlerCumulativeAvgWickets(steyn, "D Steyn")
p6<-bowlerCumulativeAvgWickets(nmccullum, "NL Mccullum")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cumWkts-1

18. Bowler cumulative Economy Rate (ER)

Ajmal’s economy rate deteriorates from a excellent rate of 5.5, while Ashwin’s economy rate improves from a terrible rate of 9.0+.

p1<-bowlerCumulativeAvgEconRate(ashwin,"R Ashwin")
p2<-bowlerCumulativeAvgEconRate(watson, "SR Watson")
p3<-bowlerCumulativeAvgEconRate(broad, "SCJ Broad")
p4<-bowlerCumulativeAvgEconRate(ajmal, "Saeed Ajmal")
p5<-bowlerCumulativeAvgEconRate(steyn, "D Steyn")
p6<-bowlerCumulativeAvgEconRate(nmccullum, "NL Mccullum")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

cumER-1

19. Bowler wicket plot

The plot below gives the average wickets versus number of overs

p1<-bowlerWicketPlot(ashwin,"R Ashwin")
p2<-bowlerWicketPlot(watson, "SR Watson")
p3<-bowlerWicketPlot(broad, "SCJ Broad")
p4<-bowlerWicketPlot(ajmal, "Saeed Ajmal")
p5<-bowlerWicketPlot(steyn, "D Steyn")
p6<-bowlerWicketPlot(nmccullum, "NL Mccullum")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)

wktPlot-1

20. Bowler wicket against opposition

#Ashwin's best pertformance are against South Africa,Sri Lanka, Bangaldesh and Afghanistan
bowlerWicketsAgainstOpposition(ashwin,"R Ashwin")

wktsOppn1-1

#Watson's bets pertformance are against England, Ireland and New Zealand
bowlerWicketsAgainstOpposition(watson, "SR Watson")

wktsOppn2-1

bowlerWicketsAgainstOpposition(broad, "SCJ Broad")

wktsOppn3-1

#Ajmal's best performances are against Sri Lanka, New Zealand and South Africa
bowlerWicketsAgainstOpposition(ajmal, "Saeed Ajmal")

wktsOppn4-1

#Steyn has good performances against New Zealand, Sri Lanka, Pakistan, West Indies
bowlerWicketsAgainstOpposition(steyn, "D Steyn")

wktsOppn5-1

bowlerWicketsAgainstOpposition(nmccullum, "NL Mccullum")

wktsOppn6-1

21. Bowler wicket at cricket grounds

bowlerWicketsVenue(ashwin,"R Ashwin")

wktsAve1-1

bowlerWicketsVenue(watson, "SR Watson")

wktsAve2-1

bowlerWicketsVenue(broad, "SCJ Broad")

wktsAve3-1

bowlerWicketsVenue(ajmal, "Saeed Ajmal")

wktsAve4-1

bowlerWicketsVenue(steyn, "D Steyn")

wktsAve5-1

bowlerWicketsVenue(nmccullum, "NL Mccullum")

wktsAve6-1

22. Get Delivery wickets for bowlers

This function creates a dataframe of deliveries and the wickets taken

setwd("C:/software/cricket-package/york-test/yorkrData/Twenty20/T20-matches")
ashwin1 <- getDeliveryWickets(team="India",dir=".",name="Ashwin",save=FALSE)
watson1 <- getDeliveryWickets(team="Australia",dir=".",name="SR Watson",save=FALSE)
broad1 <- getDeliveryWickets(team="England",dir=".",name="SCJ Broad",save=FALSE)
ajmal1 <- getDeliveryWickets(team="Pakistan",dir=".",name="Saeed Ajmal",save=FALSE)
steyn1 <- getDeliveryWickets(team="South Africa",dir=".",name="Steyn",save=FALSE)
nmccullum1 <- getDeliveryWickets(team="New Zealand",dir=".",name="NL McCullum",save=FALSE)

23. Predict number of deliveries to wickets

#Ashwin takes 
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(ashwin1,"R Ashwin")
bowlerWktsPredict(watson1,"SR Watson")

wktsPred1-1

#Broad and Ajmal need around 8 deliveries for a wicket
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(broad1,"SCJ Broad")
bowlerWktsPredict(ajmal1,"Saeed Ajmal")

wktsPred2-1

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(steyn1,"D Steyn")
bowlerWktsPredict(nmccullum1,"NL Mccullum")

wktsPred3-1

Advertisements

4 thoughts on “yorkr pads up for Twenty20s:Part 4- Individual batting and bowling performances!

  1. Pingback: yorkr pads up for Twenty20s:Part 4- Individual batting and bowling performances! – Mubashir Qasim

  2. Pingback: yorkr crashes the IPL party ! – Part 1 | Giga thoughts …

  3. Pingback: yorkr crashes the IPL party! – Part 2 | Giga thoughts …

  4. Pingback: yorkr is generic! | Giga thoughts …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s