Analyzing batsmen and bowlers with cricpy template


Introduction

This post shows how you can analyze batsmen and bowlers of Test, ODI and T20s using cricpy templates, using data from ESPN Cricinfo.

The cricpy package

The data for a particular player can be obtained with the getPlayerData() function. To do you will need to go to ESPN CricInfo Player and type in the name of the player for e.g Rahul Dravid, Virat Kohli  etc. This will bring up a page which have the profile number for the player e.g. for Rahul Dravid this would be http://www.espncricinfo.com/india/content/player/28114.html. Hence, Dravid’s profile is 28114. This can be used to get the data for Rahul Dravid as shown below

1. For Test players use batting and bowling.
2. For ODI use batting and bowling
3. For T20 use T20 Batting T20 Bowling

Please mindful of the  ESPN Cricinfo Terms of Use

My posts on Cripy were
a. Introducing cricpy:A python package to analyze performances of cricketers
b. Cricpy takes a swing at the ODIs
c. Cricpy takes guard for the Twenty20s

You can clone/download this cricpy template for your own analysis of players. This can be done using RStudio or IPython notebooks from Github at cricpy-template. You can uncomment the functions and use them.

The cricpy package is now available with pip install cricpy!!!

1 Importing cricpy – Python

# Install the package
# Do a pip install cricpy
# Import cricpy
import cricpy.analytics as ca 
## C:\Users\Ganesh\ANACON~1\lib\site-packages\statsmodels\compat\pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
##   from pandas.core import datetools

2. Invoking functions with Python package cricpy

import cricpy.analytics as ca 
#ca.batsman4s("aplayer.csv","A Player")

3. Getting help from cricpy – Python

import cricpy.analytics as ca
#help(ca.getPlayerData)

The details below will introduce the different functions that are available in cricpy.

4. Get the player data for a player using the function getPlayerData()

Important Note This needs to be done only once for a player. This function stores the player’s data in the specified CSV file (for e.g. dravid.csv as above) which can then be reused for all other functions). Once we have the data for the players many analyses can be done. This post will use the stored CSV file obtained with a prior getPlayerData for all subsequent analyses

4a. For Test players

import cricpy.analytics as ca
#player1 =ca.getPlayerData(profileNo1,dir="..",file="player1.csv",type="batting",homeOrAway=[1,2], result=[1,2,4])
#player1 =ca.getPlayerData(profileNo2,dir="..",file="player2.csv",type="batting",homeOrAway=[1,2], result=[1,2,4])

4b. For ODI players

import cricpy.analytics as ca
#player1 =ca.getPlayerDataOD(profileNo1,dir="..",file="player1.csv",type="batting")
#player1 =ca.getPlayerDataOD(profileNo2,dir="..",file="player2.csv",type="batting"")

4c For T20 players

import cricpy.analytics as ca
#player1 =ca.getPlayerDataTT(profileNo1,dir="..",file="player1.csv",type="batting")
#player1 =ca.getPlayerDataTT(profileNo2,dir="..",file="player2.csv",type="batting"")

5 A Player’s performance – Basic Analyses

The 3 plots below provide the following for Rahul Dravid

  1. Frequency percentage of runs in each run range over the whole career
  2. Mean Strike Rate for runs scored in the given range
  3. A histogram of runs frequency percentages in runs ranges
import cricpy.analytics as ca
import matplotlib.pyplot as plt
#ca.batsmanRunsFreqPerf("aplayer.csv","A Player")
#ca.batsmanMeanStrikeRate("aplayer.csv","A Player")
#ca.batsmanRunsRanges("aplayer.csv","A Player") 

6. More analyses

This gives details on the batsmen’s 4s, 6s and dismissals

import cricpy.analytics as ca
#ca.batsman4s("aplayer.csv","A Player")
#ca.batsman6s("aplayer.csv","A Player") 
#ca.batsmanDismissals("aplayer.csv","A Player")
# The below function is for ODI and T20 only
#ca.batsmanScoringRateODTT("./kohli.csv","Virat Kohli")  

7. 3D scatter plot and prediction plane

The plots below show the 3D scatter plot of Runs versus Balls Faced and Minutes at crease. A linear regression plane is then fitted between Runs and Balls Faced + Minutes at crease

import cricpy.analytics as ca
#ca.battingPerf3d("aplayer.csv","A Player")

8. Average runs at different venues

The plot below gives the average runs scored at different grounds. The plot also the number of innings at each ground as a label at x-axis.

import cricpy.analytics as ca
#ca.batsmanAvgRunsGround("aplayer.csv","A Player")

9. Average runs against different opposing teams

This plot computes the average runs scored against different countries.

import cricpy.analytics as ca
#ca.batsmanAvgRunsOpposition("aplayer.csv","A Player")

10. Highest Runs Likelihood

The plot below shows the Runs Likelihood for a batsman.

import cricpy.analytics as ca
#ca.batsmanRunsLikelihood("aplayer.csv","A Player")

11. A look at the Top 4 batsman

Choose any number of players

1.Player1 2.Player2 3.Player3 …

The following plots take a closer at their performances. The box plots show the median the 1st and 3rd quartile of the runs

12. Box Histogram Plot

This plot shows a combined boxplot of the Runs ranges and a histogram of the Runs Frequency

import cricpy.analytics as ca
#ca.batsmanPerfBoxHist("aplayer001.csv","A Player001")
#ca.batsmanPerfBoxHist("aplayer002.csv","A Player002")
#ca.batsmanPerfBoxHist("aplayer003.csv","A Player003")
#ca.batsmanPerfBoxHist("aplayer004.csv","A Player004")

13. Get Player Data special

import cricpy.analytics as ca
#player1sp = ca.getPlayerDataSp(profile1,tdir=".",tfile="player1sp.csv",ttype="batting")
#player2sp = ca.getPlayerDataSp(profile2,tdir=".",tfile="player2sp.csv",ttype="batting")
#player3sp = ca.getPlayerDataSp(profile3,tdir=".",tfile="player3sp.csv",ttype="batting")
#player4sp = ca.getPlayerDataSp(profile4,tdir=".",tfile="player4sp.csv",ttype="batting")

14. Contribution to won and lost matches

Note:This can only be used for Test matches

import cricpy.analytics as ca
#ca.batsmanContributionWonLost("player1sp.csv","A Player001")
#ca.batsmanContributionWonLost("player2sp.csv","A Player002")
#ca.batsmanContributionWonLost("player3sp.csv","A Player003")
#ca.batsmanContributionWonLost("player4sp.csv","A Player004")

15. Performance at home and overseas

Note:This can only be used for Test matches This function also requires the use of getPlayerDataSp() as shown above

import cricpy.analytics as ca
#ca.batsmanPerfHomeAway("player1sp.csv","A Player001")
#ca.batsmanPerfHomeAway("player2sp.csv","A Player002")
#ca.batsmanPerfHomeAway("player3sp.csv","A Player003")
#ca.batsmanPerfHomeAway("player4sp.csv","A Player004")

16 Moving Average of runs in career

import cricpy.analytics as ca
#ca.batsmanMovingAverage("aplayer001.csv","A Player001")
#ca.batsmanMovingAverage("aplayer002.csv","A Player002")
#ca.batsmanMovingAverage("aplayer003.csv","A Player003")
#ca.batsmanMovingAverage("aplayer004.csv","A Player004")

17 Cumulative Average runs of batsman in career

This function provides the cumulative average runs of the batsman over the career.

import cricpy.analytics as ca
#ca.batsmanCumulativeAverageRuns("aplayer001.csv","A Player001")
#ca.batsmanCumulativeAverageRuns("aplayer002.csv","A Player002")
#ca.batsmanCumulativeAverageRuns("aplayer003.csv","A Player003")
#ca.batsmanCumulativeAverageRuns("aplayer004.csv","A Player004")

18 Cumulative Average strike rate of batsman in career

.

import cricpy.analytics as ca
#ca.batsmanCumulativeStrikeRate("aplayer001.csv","A Player001")
#ca.batsmanCumulativeStrikeRate("aplayer002.csv","A Player002")
#ca.batsmanCumulativeStrikeRate("aplayer003.csv","A Player003")
#ca.batsmanCumulativeStrikeRate("aplayer004.csv","A Player004")

19 Future Runs forecast

import cricpy.analytics as ca
#ca.batsmanPerfForecast("aplayer001.csv","A Player001")

20 Relative Batsman Cumulative Average Runs

The plot below compares the Relative cumulative average runs of the batsman for each of the runs ranges of 10 and plots them.

import cricpy.analytics as ca
frames = ["aplayer1.csv","aplayer2.csv","aplayer3.csv","aplayer4.csv"]
names = ["A Player1","A Player2","A Player3","A Player4"]
#ca.relativeBatsmanCumulativeAvgRuns(frames,names)

21 Plot of 4s and 6s

import cricpy.analytics as ca
frames = ["aplayer1.csv","aplayer2.csv","aplayer3.csv","aplayer4.csv"]
names = ["A Player1","A Player2","A Player3","A Player4"]
#ca.batsman4s6s(frames,names)

22. Relative Batsman Strike Rate

The plot below gives the relative Runs Frequency Percetages for each 10 run bucket. The plot below show

import cricpy.analytics as ca
frames = ["aplayer1.csv","aplayer2.csv","aplayer3.csv","aplayer4.csv"]
names = ["A Player1","A Player2","A Player3","A Player4"]
#ca.relativeBatsmanCumulativeStrikeRate(frames,names)

23. 3D plot of Runs vs Balls Faced and Minutes at Crease

The plot is a scatter plot of Runs vs Balls faced and Minutes at Crease. A prediction plane is fitted

import cricpy.analytics as ca
#ca.battingPerf3d("aplayer001.csv","A Player001")
#ca.battingPerf3d("aplayer002.csv","A Player002")
#ca.battingPerf3d("aplayer003.csv","A Player003")
#ca.battingPerf3d("aplayer004.csv","A Player004")

24. Predicting Runs given Balls Faced and Minutes at Crease

A multi-variate regression plane is fitted between Runs and Balls faced +Minutes at crease.

import cricpy.analytics as ca
import numpy as np
import pandas as pd
BF = np.linspace( 10, 400,15)
Mins = np.linspace( 30,600,15)
newDF= pd.DataFrame({'BF':BF,'Mins':Mins})
#aplayer = ca.batsmanRunsPredict("aplayer.csv",newDF,"A Player")
#print(aplayer)

The fitted model is then used to predict the runs that the batsmen will score for a given Balls faced and Minutes at crease.

25 Analysis of Top 3 wicket takers

Take any number of bowlers from either Test, ODI or T20

  1. Bowler1
  2. Bowler2
  3. Bowler3 …

26. Get the bowler’s data (Test)

This plot below computes the percentage frequency of number of wickets taken for e.g 1 wicket x%, 2 wickets y% etc and plots them as a continuous line

import cricpy.analytics as ca
#abowler1 =ca.getPlayerData(profileNo1,dir=".",file="abowler1.csv",type="bowling",homeOrAway=[1,2], result=[1,2,4])
#abowler2 =ca.getPlayerData(profileNo2,dir=".",file="abowler2.csv",type="bowling",homeOrAway=[1,2], result=[1,2,4])
#abowler3 =ca.getPlayerData(profile3,dir=".",file="abowler3.csv",type="bowling",homeOrAway=[1,2], result=[1,2,4])

26b For ODI bowlers

import cricpy.analytics as ca
#abowler1 =ca.getPlayerDataOD(profileNo1,dir=".",file="abowler1.csv",type="bowling")
#abowler2 =ca.getPlayerDataOD(profileNo2,dir=".",file="abowler2.csv",type="bowling")
#abowler3 =ca.getPlayerDataOD(profile3,dir=".",file="abowler3.csv",type="bowling")

26c For T20 bowlers

import cricpy.analytics as ca
#abowler1 =ca.getPlayerDataTT(profileNo1,dir=".",file="abowler1.csv",type="bowling")
#abowler2 =ca.getPlayerDataTT(profileNo2,dir=".",file="abowler2.csv",type="bowling")
#abowler3 =ca.getPlayerDataTT(profile3,dir=".",file="abowler3.csv",type="bowling")

27. Wicket Frequency Plot

This plot below plots the frequency of wickets taken for each of the bowlers

import cricpy.analytics as ca
#ca.bowlerWktsFreqPercent("abowler1.csv","A Bowler1")
#ca.bowlerWktsFreqPercent("abowler2.csv","A Bowler2")
#ca.bowlerWktsFreqPercent("abowler3.csv","A Bowler3")

28. Wickets Runs plot

The plot below create a box plot showing the 1st and 3rd quartile of runs conceded versus the number of wickets taken

import cricpy.analytics as ca
#ca.bowlerWktsRunsPlot("abowler1.csv","A Bowler1")
#ca.bowlerWktsRunsPlot("abowler2.csv","A Bowler2")
#ca.bowlerWktsRunsPlot("abowler3.csv","A Bowler3")

29 Average wickets at different venues

The plot gives the average wickets taken bat different venues.

import cricpy.analytics as ca
#ca.bowlerAvgWktsGround("abowler1.csv","A Bowler1")
#ca.bowlerAvgWktsGround("abowler2.csv","A Bowler2")
#ca.bowlerAvgWktsGround("abowler3.csv","A Bowler3")

30 Average wickets against different opposition

The plot gives the average wickets taken against different countries.

import cricpy.analytics as ca
#ca.bowlerAvgWktsOpposition("abowler1.csv","A Bowler1")
#ca.bowlerAvgWktsOpposition("abowler2.csv","A Bowler2")
#ca.bowlerAvgWktsOpposition("abowler3.csv","A Bowler3")

31 Wickets taken moving average

import cricpy.analytics as ca
#ca.bowlerMovingAverage("abowler1.csv","A Bowler1")
#ca.bowlerMovingAverage("abowler2.csv","A Bowler2")
#ca.bowlerMovingAverage("abowler3.csv","A Bowler3")

32 Cumulative average wickets taken

The plots below give the cumulative average wickets taken by the bowlers.

import cricpy.analytics as ca
#ca.bowlerCumulativeAvgWickets("abowler1.csv","A Bowler1")
#ca.bowlerCumulativeAvgWickets("abowler2.csv","A Bowler2")
#ca.bowlerCumulativeAvgWickets("abowler3.csv","A Bowler3")

33 Cumulative average economy rate

The plots below give the cumulative average economy rate of the bowlers.

import cricpy.analytics as ca
#ca.bowlerCumulativeAvgEconRate("abowler1.csv","A Bowler1")
#ca.bowlerCumulativeAvgEconRate("abowler2.csv","A Bowler2")
#ca.bowlerCumulativeAvgEconRate("abowler3.csv","A Bowler3")

34 Future Wickets forecast

import cricpy.analytics as ca
#ca.bowlerPerfForecast("abowler1.csv","A bowler1")

35 Get player data special

import cricpy.analytics as ca
#abowler1sp =ca.getPlayerDataSp(profile1,tdir=".",tfile="abowler1sp.csv",ttype="bowling")
#abowler2sp =ca.getPlayerDataSp(profile2,tdir=".",tfile="abowler2sp.csv",ttype="bowling")
#abowler3sp =ca.getPlayerDataSp(profile3,tdir=".",tfile="abowler3sp.csv",ttype="bowling")

36 Contribution to matches won and lost

Note:This can be done only for Test cricketers

import cricpy.analytics as ca
#ca.bowlerContributionWonLost("abowler1sp.csv","A Bowler1")
#ca.bowlerContributionWonLost("abowler2sp.csv","A Bowler2")
#ca.bowlerContributionWonLost("abowler3sp.csv","A Bowler3")

37 Performance home and overseas

Note:This can be done only for Test cricketers

import cricpy.analytics as ca
#ca.bowlerPerfHomeAway("abowler1sp.csv","A Bowler1")
#ca.bowlerPerfHomeAway("abowler2sp.csv","A Bowler2")
#ca.bowlerPerfHomeAway("abowler3sp.csv","A Bowler3")

38 Relative cumulative average economy rate of bowlers

import cricpy.analytics as ca
frames = ["abowler1.csv","abowler2.csv","abowler3.csv"]
names = ["A Bowler1","A Bowler2","A Bowler3"]
#ca.relativeBowlerCumulativeAvgEconRate(frames,names)

39 Relative Economy Rate against wickets taken

import cricpy.analytics as ca
frames = ["abowler1.csv","abowler2.csv","abowler3.csv"]
names = ["A Bowler1","A Bowler2","A Bowler3"]
#ca.relativeBowlingER(frames,names)

40 Relative cumulative average wickets of bowlers in career

import cricpy.analytics as ca
frames = ["abowler1.csv","abowler2.csv","abowler3.csv"]
names = ["A Bowler1","A Bowler2","A Bowler3"]
#ca.relativeBowlerCumulativeAvgWickets(frames,names)

Clone/download this cricpy template for your own analysis of players. This can be done using RStudio or IPython notebooks from Github at cricpy-template

Key Findings

Analysis of Top 4 batsman

Analysis of Top 3 bowlers

You may also like
1. My book ‘Deep Learning from first principles:Second Edition’ now on Amazon
2. Presentation on ‘Evolution to LTE’
3. Stacks of protocol stacks – A primer
4. Taking baby steps in Lisp
5. Introducing cricket package yorkr: Part 1- Beaten by sheer pace!

To see all posts click Index of posts

Cricpy takes a swing at the ODIs


No computer has ever been designed that is ever aware of what it’s doing; but most of the time, we aren’t either.” Marvin Minksy

“The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague” Edgser Djikstra

Introduction

In this post, cricpy, the Python avatar of my R package cricketr, learns some new tricks to be able to handle ODI matches. To know more about my R package cricketr see Re-introducing cricketr! : An R package to analyze performances of cricketers

Cricpy uses the statistics info available in ESPN Cricinfo Statsguru. The current version of this package supports only Test cricket

You should be able to install the package using pip install cricpy and use the many functions available in the package. Please mindful of the ESPN Cricinfo Terms of Use

To know how to use cricpy see Introducing cricpy:A python package to analyze performances of cricketers. To the original version of cricpy, I have added 3 new functions for ODI. The earlier functions work for Test and ODI.

This post is also hosted on Rpubs at Cricpy takes a swing at the ODIs. You can also down the pdf version of this post at cricpy-odi.pdf

You can fork/clone the package at Github cricpy

Note: If you would like to do a similar analysis for a different set of batsman and bowlers, you can clone/download my skeleton cricpy-template from Github (which is the R Markdown file I have used for the analysis below). You will only need to make appropriate changes for the players you are interested in. The functions can be executed in RStudio or in a IPython notebook.

The cricpy package

The data for a particular player in ODI can be obtained with the getPlayerDataOD() function. To do you will need to go to ESPN CricInfo Player and type in the name of the player for e.g Virat Kohli, Virendar Sehwag, Chris Gayle etc. This will bring up a page which have the profile number for the player e.g. for Virat Kohli this would be http://www.espncricinfo.com/india/content/player/253802.html. Hence, Kohli’s profile is 253802. This can be used to get the data for Virat Kohlis shown below

The cricpy package is a clone of my R package cricketr. The signature of all the python functions are identical with that of its clone ‘cricketr’, with only the necessary variations between Python and R. It may be useful to look at my post R vs Python: Different similarities and similar differences. In fact if you are familar with one of the lanuguages you can look up the package in the other and you will notice the parallel constructs.

You can fork/clone the package at Github cricpy

Note: The charts are self-explanatory and I have not added much of my owy interpretation to it. Do look at the plots closely and check out the performances for yourself.

1 Importing cricpy – Python

# Install the package
# Do a pip install cricpy
# Import cricpy
import cricpy.analytics as ca 

2. Invoking functions with Python package crlcpy

import cricpy.analytics as ca 
ca.batsman4s("./kohli.csv","Virat Kohli")

3. Getting help from cricpy – Python

import cricpy.analytics as ca 
help(ca.getPlayerDataOD)
## Help on function getPlayerDataOD in module cricpy.analytics:
## 
## getPlayerDataOD(profile, opposition='', host='', dir='./data', file='player001.csv', type='batting', homeOrAway=[1, 2, 3], result=[1, 2, 3, 5], create=True)
##     Get the One day player data from ESPN Cricinfo based on specific inputs and store in a file in a given directory
##     
##     Description
##     
##     Get the player data given the profile of the batsman. The allowed inputs are home,away or both and won,lost or draw of matches. The data is stored in a <player>.csv file in a directory specified. This function also returns a data frame of the player
##     
##     Usage
##     
##     getPlayerDataOD(profile, opposition="",host="",dir = "../", file = "player001.csv", 
##     type = "batting", homeOrAway = c(1, 2, 3), result = c(1, 2, 3,5))
##     Arguments
##     
##     profile     
##     This is the profile number of the player to get data. This can be obtained from http://www.espncricinfo.com/ci/content/player/index.html. Type the name of the player and click search. This will display the details of the player. Make a note of the profile ID. For e.g For Virender Sehwag this turns out to be http://www.espncricinfo.com/india/content/player/35263.html. Hence the profile for Sehwag is 35263
##     opposition      The numerical value of the opposition country e.g.Australia,India, England etc. The values are Australia:2,Bangladesh:25,Bermuda:12, England:1,Hong Kong:19,India:6,Ireland:29, Netherlands:15,New Zealand:5,Pakistan:7,Scotland:30,South Africa:3,Sri Lanka:8,United Arab Emirates:27, West Indies:4, Zimbabwe:9; Africa XI:405 Note: If no value is entered for opposition then all teams are considered
##     host            The numerical value of the host country e.g.Australia,India, England etc. The values are Australia:2,Bangladesh:25,England:1,India:6,Ireland:29,Malaysia:16,New Zealand:5,Pakistan:7, Scotland:30,South Africa:3,Sri Lanka:8,United Arab Emirates:27,West Indies:4, Zimbabwe:9 Note: If no value is entered for host then all host countries are considered
##     dir 
##     Name of the directory to store the player data into. If not specified the data is stored in a default directory "../data". Default="../data"
##     file        
##     Name of the file to store the data into for e.g. tendulkar.csv. This can be used for subsequent functions. Default="player001.csv"
##     type        
##     type of data required. This can be "batting" or "bowling"
##     homeOrAway  
##     This is vector with either or all 1,2, 3. 1 is for home 2 is for away, 3 is for neutral venue
##     result      
##     This is a vector that can take values 1,2,3,5. 1 - won match 2- lost match 3-tied 5- no result
##     Details
##     
##     More details can be found in my short video tutorial in Youtube https://www.youtube.com/watch?v=q9uMPFVsXsI
##     
##     Value
##     
##     Returns the player's dataframe
##     
##     Note
##     
##     Maintainer: Tinniam V Ganesh <tvganesh.85@gmail.com>
##     
##     Author(s)
##     
##     Tinniam V Ganesh
##     
##     References
##     
##     http://www.espncricinfo.com/ci/content/stats/index.html
##     https://gigadom.wordpress.com/
##     
##     See Also
##     
##     getPlayerDataSp getPlayerData
##     
##     Examples
##     
##     
##     ## Not run: 
##     # Both home and away. Result = won,lost and drawn
##     sehwag =getPlayerDataOD(35263,dir="../cricketr/data", file="sehwag1.csv",
##     type="batting", homeOrAway=[1,2],result=[1,2,3,4])
##     
##     # Only away. Get data only for won and lost innings
##     sehwag = getPlayerDataOD(35263,dir="../cricketr/data", file="sehwag2.csv",
##     type="batting",homeOrAway=[2],result=[1,2])
##     
##     # Get bowling data and store in file for future
##     malinga = getPlayerData(49758,dir="../cricketr/data",file="malinga1.csv",
##     type="bowling")
##     
##     # Get Dhoni's ODI record in Australia against Australua
##     dhoni = getPlayerDataOD(28081,opposition = 2,host=2,dir=".",
##     file="dhoniVsAusinAusOD",type="batting")
##     
##     ## End(Not run)

The details below will introduce the different functions that are available in cricpy.

4. Get the ODI player data for a player using the function getPlayerDataOD()

Important Note This needs to be done only once for a player. This function stores the player’s data in the specified CSV file (for e.g. kohli.csv as above) which can then be reused for all other functions). Once we have the data for the players many analyses can be done. This post will use the stored CSV file obtained with a prior getPlayerDataOD for all subsequent analyses

import cricpy.analytics as ca
#sehwag=ca.getPlayerDataOD(35263,dir=".",file="sehwag.csv",type="batting")
#kohli=ca.getPlayerDataOD(253802,dir=".",file="kohli.csv",type="batting")
#jayasuriya=ca.getPlayerDataOD(49209,dir=".",file="jayasuriya.csv",type="batting")
#gayle=ca.getPlayerDataOD(51880,dir=".",file="gayle.csv",type="batting")

Included below are some of the functions that can be used for ODI batsmen and bowlers. For this I have chosen, Virat Kohli, ‘the run machine’ who is on-track for breaking many of the Test & ODI records

5 Virat Kohli’s performance – Basic Analyses

The 3 plots below provide the following for Virat Kohli

  1. Frequency percentage of runs in each run range over the whole career
  2. Mean Strike Rate for runs scored in the given range
  3. A histogram of runs frequency percentages in runs ranges
import cricpy.analytics as ca
import matplotlib.pyplot as plt
ca.batsmanRunsFreqPerf("./kohli.csv","Virat Kohli")

ca.batsmanMeanStrikeRate("./kohli.csv","Virat Kohli")

ca.batsmanRunsRanges("./kohli.csv","Virat Kohli")

6. More analyses

import cricpy.analytics as ca
ca.batsman4s("./kohli.csv","Virat Kohli")

ca.batsman6s("./kohli.csv","Virat Kohli")

ca.batsmanDismissals("./kohli.csv","Virat Kohli")

ca.batsmanScoringRateODTT("./kohli.csv","Virat Kohli")


7. 3D scatter plot and prediction plane

The plots below show the 3D scatter plot of Kohli’s Runs versus Balls Faced and Minutes at crease. A linear regression plane is then fitted between Runs and Balls Faced + Minutes at crease

import cricpy.analytics as ca
ca.battingPerf3d("./kohli.csv","Virat Kohli")

Average runs at different venues

The plot below gives the average runs scored by Kohli at different grounds. The plot also the number of innings at each ground as a label at x-axis.

import cricpy.analytics as ca
ca.batsmanAvgRunsGround("./kohli.csv","Virat Kohli")

9. Average runs against different opposing teams

This plot computes the average runs scored by Kohli against different countries.

import cricpy.analytics as ca
ca.batsmanAvgRunsOpposition("./kohli.csv","Virat Kohli")

10 . Highest Runs Likelihood

The plot below shows the Runs Likelihood for a batsman. For this the performance of Kohli is plotted as a 3D scatter plot with Runs versus Balls Faced + Minutes at crease. K-Means. The centroids of 3 clusters are computed and plotted. In this plot Kohli’s highest tendencies are computed and plotted using K-Means

import cricpy.analytics as ca
ca.batsmanRunsLikelihood("./kohli.csv","Virat Kohli")

A look at the Top 4 batsman – Kohli, Jayasuriya, Sehwag and Gayle

The following batsmen have been very prolific in ODI cricket and will be used for the analyses

  1. Virat Kohli: Runs – 10232, Average:59.83 ,Strike rate-92.88
  2. Sanath Jayasuriya : Runs – 13430, Average:32.36 ,Strike rate-91.2
  3. Virendar Sehwag :Runs – 8273, Average:35.05 ,Strike rate-104.33
  4. Chris Gayle : Runs – 9727, Average:37.12 ,Strike rate-85.82

The following plots take a closer at their performances. The box plots show the median the 1st and 3rd quartile of the runs

12. Box Histogram Plot

This plot shows a combined boxplot of the Runs ranges and a histogram of the Runs Frequency

import cricpy.analytics as ca
ca.batsmanPerfBoxHist("./kohli.csv","Virat Kohli")

ca.batsmanPerfBoxHist("./jayasuriya.csv","Sanath jayasuriya")

ca.batsmanPerfBoxHist("./gayle.csv","Chris Gayle")

ca.batsmanPerfBoxHist("./sehwag.csv","Virendar Sehwag")

13 Moving Average of runs in career

Take a look at the Moving Average across the career of the Top 4 (ignore the dip at the end of all plots. Need to check why this is so!). Kohli’s performance has been steadily improving over the years, so has Sehwag. Gayle seems to be on the way down

import cricpy.analytics as ca
ca.batsmanMovingAverage("./kohli.csv","Virat Kohli")

ca.batsmanMovingAverage("./jayasuriya.csv","Sanath jayasuriya")

ca.batsmanMovingAverage("./gayle.csv","Chris Gayle")

ca.batsmanMovingAverage("./sehwag.csv","Virendar Sehwag")

14 Cumulative Average runs of batsman in career

This function provides the cumulative average runs of the batsman over the career. Kohli seems to be getting better with time and reaches a cumulative average of 45+. Sehwag improves with time and reaches around 35+. Chris Gayle drops from 42 to 35

import cricpy.analytics as ca
ca.batsmanCumulativeAverageRuns("./kohli.csv","Virat Kohli")

ca.batsmanCumulativeAverageRuns("./jayasuriya.csv","Sanath jayasuriya")

ca.batsmanCumulativeAverageRuns("./gayle.csv","Chris Gayle")

ca.batsmanCumulativeAverageRuns("./sehwag.csv","Virendar Sehwag")

15 Cumulative Average strike rate of batsman in career

Sehwag has the best strike rate of almost 90. Kohli and Jayasuriya have a cumulative strike rate of 75.

import cricpy.analytics as ca
ca.batsmanCumulativeStrikeRate("./kohli.csv","Virat Kohli")

ca.batsmanCumulativeStrikeRate("./jayasuriya.csv","Sanath jayasuriya")

ca.batsmanCumulativeStrikeRate("./gayle.csv","Chris Gayle")

ca.batsmanCumulativeStrikeRate("./sehwag.csv","Virendar Sehwag")

16 Relative Batsman Cumulative Average Runs

The plot below compares the Relative cumulative average runs of the batsman . It can be seen that Virat Kohli towers above all others in the runs. He is followed by Chris Gayle and then Sehwag

import cricpy.analytics as ca
frames = ["./sehwag.csv","./gayle.csv","./jayasuriya.csv","./kohli.csv"]
names = ["Sehwag","Gayle","Jayasuriya","Kohli"]
ca.relativeBatsmanCumulativeAvgRuns(frames,names)

Relative Batsman Strike Rate

The plot below gives the relative Runs Frequency Percentages for each 10 run bucket. The plot below show Sehwag has the best strike rate, followed by Jayasuriya

import cricpy.analytics as ca
frames = ["./sehwag.csv","./gayle.csv","./jayasuriya.csv","./kohli.csv"]
names = ["Sehwag","Gayle","Jayasuriya","Kohli"]
ca.relativeBatsmanCumulativeStrikeRate(frames,names)

18. 3D plot of Runs vs Balls Faced and Minutes at Crease

The plot is a scatter plot of Runs vs Balls faced and Minutes at Crease. A 3D prediction plane is fitted

import cricpy.analytics as ca
ca.battingPerf3d("./kohli.csv","Virat Kohli")

ca.battingPerf3d("./jayasuriya.csv","Sanath jayasuriya")

ca.battingPerf3d("./gayle.csv","Chris Gayle")

ca.battingPerf3d("./sehwag.csv","Virendar Sehwag")

3D plot of Runs vs Balls Faced and Minutes at Crease

From the plot below it can be seen that Sehwag has more runs by way of 4s than 1’s,2’s or 3s. Gayle and Jayasuriya have large number of 6s

import cricpy.analytics as ca
frames = ["./sehwag.csv","./kohli.csv","./gayle.csv","./jayasuriya.csv"]
names = ["Sehwag","Kohli","Gayle","Jayasuriya"]
ca.batsman4s6s(frames,names)

20. Predicting Runs given Balls Faced and Minutes at Crease

A multi-variate regression plane is fitted between Runs and Balls faced +Minutes at crease.

import cricpy.analytics as ca
import numpy as np
import pandas as pd
BF = np.linspace( 10, 400,15)
Mins = np.linspace( 30,600,15)
newDF= pd.DataFrame({'BF':BF,'Mins':Mins})
kohli= ca.batsmanRunsPredict("./kohli.csv",newDF,"Kohli")
print(kohli)
##             BF        Mins        Runs
## 0    10.000000   30.000000    6.807407
## 1    37.857143   70.714286   36.034833
## 2    65.714286  111.428571   65.262259
## 3    93.571429  152.142857   94.489686
## 4   121.428571  192.857143  123.717112
## 5   149.285714  233.571429  152.944538
## 6   177.142857  274.285714  182.171965
## 7   205.000000  315.000000  211.399391
## 8   232.857143  355.714286  240.626817
## 9   260.714286  396.428571  269.854244
## 10  288.571429  437.142857  299.081670
## 11  316.428571  477.857143  328.309096
## 12  344.285714  518.571429  357.536523
## 13  372.142857  559.285714  386.763949
## 14  400.000000  600.000000  415.991375

The fitted model is then used to predict the runs that the batsmen will score for a given Balls faced and Minutes at crease.

21 Analysis of Top Bowlers

The following 4 bowlers have had an excellent career and will be used for the analysis

  1. Muthiah Muralitharan:Wickets: 534, Average = 23.08, Economy Rate – 3.93
  2. Wasim Akram : Wickets: 502, Average = 23.52, Economy Rate – 3.89
  3. Shaun Pollock: Wickets: 393, Average = 24.50, Economy Rate – 3.67
  4. Javagal Srinath : Wickets:315, Average – 28.08, Economy Rate – 4.44

How do Muralitharan, Akram, Pollock and Srinath compare with one another with respect to wickets taken and the Economy Rate. The next set of plots compute and plot precisely these analyses.

22. Get the bowler’s data

This plot below computes the percentage frequency of number of wickets taken for e.g 1 wicket x%, 2 wickets y% etc and plots them as a continuous line

import cricpy.analytics as ca
#akram=ca.getPlayerDataOD(43547,dir=".",file="akram.csv",type="bowling")
#murali=ca.getPlayerDataOD(49636,dir=".",file="murali.csv",type="bowling")
#pollock=ca.getPlayerDataOD(46774,dir=".",file="pollock.csv",type="bowling")
#srinath=ca.getPlayerDataOD(34105,dir=".",file="srinath.csv",type="bowling")

23. Wicket Frequency Plot

This plot below plots the frequency of wickets taken for each of the bowlers

import cricpy.analytics as ca
ca.bowlerWktsFreqPercent("./murali.csv","M Muralitharan")

ca.bowlerWktsFreqPercent("./akram.csv","Wasim Akram")

ca.bowlerWktsFreqPercent("./pollock.csv","Shaun Pollock")

ca.bowlerWktsFreqPercent("./srinath.csv","J Srinath")

24. Wickets Runs plot

The plot below create a box plot showing the 1st and 3rd quartile of runs conceded versus the number of wickets taken. Murali’s median runs for wickets ia around 40 while Akram, Pollock and Srinath it is around 32+ runs. The spread around the median is larger for these 3 bowlers in comparison to Murali

import cricpy.analytics as ca
ca.bowlerWktsRunsPlot("./murali.csv","M Muralitharan")

ca.bowlerWktsRunsPlot("./akram.csv","Wasim Akram")

ca.bowlerWktsRunsPlot("./pollock.csv","Shaun Pollock")

ca.bowlerWktsRunsPlot("./srinath.csv","J Srinath")

25 Average wickets at different venues

The plot gives the average wickets taken by Muralitharan at different venues. McGrath best performances are at Centurion, Lord’s and Port of Spain averaging about 4 wickets. Kapil Dev’s does good at Kingston and Wellington. Anderson averages 4 wickets at Dunedin and Nagpur

import cricpy.analytics as ca
ca.bowlerAvgWktsGround("./murali.csv","M Muralitharan")

ca.bowlerAvgWktsGround("./akram.csv","Wasim Akram")

ca.bowlerAvgWktsGround("./pollock.csv","Shaun Pollock")

ca.bowlerAvgWktsGround("./srinath.csv","J Srinath")

26 Average wickets against different opposition

The plot gives the average wickets taken by Muralitharan against different countries. The x-axis also includes the number of innings against each team

import cricpy.analytics as ca
ca.bowlerAvgWktsOpposition("./murali.csv","M Muralitharan")

ca.bowlerAvgWktsOpposition("./akram.csv","Wasim Akram")

ca.bowlerAvgWktsOpposition("./pollock.csv","Shaun Pollock")

ca.bowlerAvgWktsOpposition("./srinath.csv","J Srinath")

27 Wickets taken moving average

From the plot below it can be see James Anderson has had a solid performance over the years averaging about wickets

import cricpy.analytics as ca
ca.bowlerMovingAverage("./murali.csv","M Muralitharan")

ca.bowlerMovingAverage("./akram.csv","Wasim Akram")

ca.bowlerMovingAverage("./pollock.csv","Shaun Pollock")

ca.bowlerMovingAverage("./srinath.csv","J Srinath")

28 Cumulative average wickets taken

The plots below give the cumulative average wickets taken by the bowlers. Muralitharan has consistently taken wickets at an average of 1.6 wickets per game. Shaun Pollock has an average of 1.5

import cricpy.analytics as ca
ca.bowlerCumulativeAvgWickets("./murali.csv","M Muralitharan")

ca.bowlerCumulativeAvgWickets("./akram.csv","Wasim Akram")

ca.bowlerCumulativeAvgWickets("./pollock.csv","Shaun Pollock")

ca.bowlerCumulativeAvgWickets("./srinath.csv","J Srinath")

29 Cumulative average economy rate

The plots below give the cumulative average economy rate of the bowlers. Pollock is the most economical, followed by Akram and then Murali

import cricpy.analytics as ca
ca.bowlerCumulativeAvgEconRate("./murali.csv","M Muralitharan")

ca.bowlerCumulativeAvgEconRate("./akram.csv","Wasim Akram")

ca.bowlerCumulativeAvgEconRate("./pollock.csv","Shaun Pollock")

ca.bowlerCumulativeAvgEconRate("./srinath.csv","J Srinath")

30 Relative cumulative average economy rate of bowlers

The Relative cumulative economy rate shows that Pollock is the most economical of the 4 bowlers. He is followed by Akram and then Murali

import cricpy.analytics as ca
frames = ["./srinath.csv","./akram.csv","./murali.csv","pollock.csv"]
names = ["J Srinath","Wasim Akram","M Muralitharan", "S Pollock"]
ca.relativeBowlerCumulativeAvgEconRate(frames,names)

31 Relative Economy Rate against wickets taken

Pollock is most economical vs number of wickets taken. Murali has the best figures for 4 wickets taken.

import cricpy.analytics as ca
frames = ["./srinath.csv","./akram.csv","./murali.csv","pollock.csv"]
names = ["J Srinath","Wasim Akram","M Muralitharan", "S Pollock"]
ca.relativeBowlingER(frames,names)

32 Relative cumulative average wickets of bowlers in career

The plot below shows that McGrath has the best overall cumulative average wickets. While the bowlers are neck to neck around 130 innings, you can see Muralitharan is most consistent and leads the pack after 150 innings in the number of wickets taken.

import cricpy.analytics as ca
frames = ["./srinath.csv","./akram.csv","./murali.csv","pollock.csv"]
names = ["J Srinath","Wasim Akram","M Muralitharan", "S Pollock"]
ca.relativeBowlerCumulativeAvgWickets(frames,names)

33. Key Findings

The plots above capture some of the capabilities and features of my cricpy package. Feel free to install the package and try it out. Please do keep in mind ESPN Cricinfo’s Terms of Use.

Here are the main findings from the analysis above

Analysis of Top 4 batsman

The analysis of the Top 4 test batsman Tendulkar, Kallis, Ponting and Sangakkara show the folliwing

  1. Kohli is a mean run machine and has been consistently piling on runs. Clearly records will lay shattered in days to come for Kohli
  2. Virendar Sehwag has the best strike rate of the 4, followed by Jayasuriya and then Kohli
  3. Shaun Pollock is the most economical of the bowlers followed by Wasim Akram
  4. Muralitharan is the most consistent wicket of the lot.

Also see
1. Architecting a cloud based IP Multimedia System (IMS)
2. Exploring Quantum Gate operations with QCSimulator
3. Dabbling with Wiener filter using OpenCV
4. Deep Learning from first principles in Python, R and Octave – Part 5
5. Big Data-2: Move into the big league:Graduate from R to SparkR
6. Singularity
7. Practical Machine Learning with R and Python – Part 4
8. Literacy in India – A deepR dive
9. Modeling a Car in Android

To see all posts click Index of Posts

yorkr is generic!


The features and functionality in my yorkr package is now complete. My R package yorkr, is totally generic, which means that the R package  can be used for all ODI, T20 matches. Hence yorkr can be used for professional or amateur ODI and T20 matches. The R package can be used for both men and women ODI, T20 international or domestic matches. The main requirement is, that the match data  be created as a Yaml file in the format Cricsheet (Required yaml format for the match data).

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

$4.99/Rs 320 and $6.99/Rs448 respectively

 

I have successfully used my R functions for the Indian Premier League (IPL) matches with changes only to the convertAllYamlFiles2RDataFramesXX (please see posts below)

The convertAllYamlFiles2RDataframes &convertAllYamlFiles2RDataFramesT20 will have to be customized for the names of the teams playing in the domestic professional or amateur matches. All other classes of functions namely Class1, Class2, Class 3 and Class 4 as discussed in my post Introducing cricket package yorkr-Part 1: Beaten by sheer pace can be used as is without any changes.

There are numerous professional & amateur T20 matches that are played around the world. Here are a list of domestic T20 tournaments that are played around the world (from Wikipedia). The yorkr package can be used for any of these matches once the match data is saved as yaml as mentioned above.

So do go ahead and have fun, analyzing cricket performances with yorkr!

Please take a look at my posts on how to use yorkr for ODI, Twenty20 matches.

  1. Introducing cricket package yorkr:Part 1- Beaten by sheer pace!
    2. Introducing cricket package yorkr:Part 2- Trapped leg before wicket!
    3.  Introducing cricket package yorkr:Part 3- foxed by flight!
    4. Introducing cricket package yorkr:Part 4-In the block hole!
    5. yorkr pads up for the Twenty20s: Part 1- Analyzing team”s match performance
    6. yorkr pads up for the Twenty20s: Part 2-Head to head confrontation between teams
    7. yorkr pads up for the Twenty20s:Part 3:Overall team performance against all oppositions!
    8. yorkr pads up for Twenty20s:Part 4- Individual batting and bowling performances!
    9. yorkr crashes the IPL party ! – Part 1
    10. yorkr crashes the IPL party! – Part 2
    11. yorkr crashes the IPL party! – Part 3
    12. yorkr crashes the IPL party! – Part 4
    13. yorkr ranks IPL batsmen and bowlers
    14. yorkr ranks T20 batsmen and bowlers
    15. yorkr ranks ODI batsmen and bowlers

yorkr ranks ODI batsmen and bowlers


This is the last and final post in which yorkr ranks ODI batsmen and bowlers. These are based on match data from Cricsheet. The ranking is done on

  1. average runs and average strike rate for batsmen and
  2. average wickets and average economy rate for bowlers.

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

nd $4.99/Rs 320 and $6.99/Rs448 respectively

 

This post has also been published in RPubs RankODIPlayers. You can download this as a pdf file at RankODIPlayers.pdf.

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

You can take a look at the code at rankODIPlayers (available in yorkr_0.0.5)

rm(list=ls())
library(yorkr)
library(dplyr)
source("rankODIBatsmen.R")
source("rankODIBowlers.R")

Rank ODI batsmen

The top 3 ODI batsmen are hashim Amla (SA), Matther Hayden(Aus) & Virat Kohli (Ind) . Note: For ODI a a cutoff of at least 50 matches played was chosen.

ODIBatsmanRank <- rankODIBatsmen()
as.data.frame(ODIBatsmanRank[1:30,])
##            batsman matches meanRuns    meanSR
## 1          HM Amla     185 51.96216  84.15508
## 2        ML Hayden      79 50.08861  81.20646
## 3          V Kohli     279 48.51971  78.55197
## 4   AB de Villiers     253 47.93676  95.05561
## 5     SR Tendulkar     151 45.82119  79.62311
## 6         S Dhawan     116 45.03448  81.54043
## 7         V Sehwag     167 44.49102 106.27563
## 8          JE Root     111 43.64865  81.66054
## 9        Q de Kock      85 43.61176  82.55235
## 10       IJL Trott     113 43.36283  70.69761
## 11   KC Sangakkara     293 42.81911  75.10420
## 12      TM Dilshan     283 41.76678  89.70360
## 13   KS Williamson     146 41.24658  73.49267
## 14   S Chanderpaul      93 40.07527  70.59613
## 15        HH Gibbs      75 40.00000  79.03813
## 16     Salman Butt      57 39.85965  59.29807
## 17    Anamul Haque      58 39.72414  56.45224
## 18      RT Ponting     238 38.88235  71.94294
## 19       JH Kallis     136 38.77941  67.17794
## 20        MS Dhoni     328 38.57927  90.30555
## 21      MJ Guptill     199 38.54774  73.88090
## 22       DA Warner     138 38.52174  87.24978
## 23 Mohammad Yousuf      94 38.44681  72.69851
## 24        JD Ryder      66 38.40909  91.29667
## 25       GJ Bailey     133 38.38346  75.74519
## 26       G Gambhir     209 37.83254  75.15483
## 27      AJ Strauss     122 37.80328  71.54844
## 28       MJ Clarke     301 37.67442  69.78415
## 29       SR Watson     274 37.08029  83.46489
## 30        AJ Finch     103 36.36893  79.49845

Rank ODI bowlers

The top 3 ODI bowlers are R J Harris (Aus), MJ Henry(NZ) and MA Starc(Aus). Mohammed Shami is 4th and Amit Mishra is 8th A cutoff of 20 matches was considered for bowlers

ODIBowlersRank <- rankODIBowlers()
## [1] 35072     3
## [1] "C:/software/cricket-package/york-test/yorkrData/ODI/ODI-matches"
as.data.frame(ODIBowlersRank[1:30,])
##               bowler matches meanWickets   meanER
## 1  Mustafizur Rahman      56    4.000000 4.293214
## 2           JH Davey      53    3.528302 4.455094
## 3          RJ Harris      94    3.276596 4.361489
## 4           MA Starc     208    3.144231 4.425865
## 5           MJ Henry      88    3.125000 4.961250
## 6         A Flintoff     139    2.956835 4.283022
## 7           A Mishra     106    2.886792 4.365849
## 8     Mohammed Shami     144    2.777778 5.609306
## 9     MJ McClenaghan     165    2.751515 5.640424
## 10          CJ McKay     230    2.704348       NA
## 11       MF Maharoof     114    2.701754 4.427018
## 12       Imran Tahir     156    2.660256 4.461923
## 13        BAW Mendis     234    2.641026 4.532308
## 14     RK Kleinveldt      54    2.629630 4.306667
## 15      Arafat Sunny      62    2.612903 4.103226
## 16         JE Taylor     156    2.602564 5.115192
## 17           AJ Hall      55    2.600000 3.879091
## 18        WD Parnell     129    2.596899 5.477597
## 19         CR Woakes     129    2.596899 5.340620
## 20      DE Bollinger     152    2.592105 4.282763
## 21        Wahab Riaz     206    2.567961 5.431748
## 22        PJ Cummins     148    2.567568 5.715405
## 23         R Rampaul     173    2.549133 4.726590
## 24      Taskin Ahmed      56    2.535714 5.325357
## 25          DW Steyn     292    2.534247 4.534007
## 26      JR Hazlewood      64    2.531250 4.392500
## 27        Abdur Rauf      84    2.523810 4.786667
## 28           SW Tait     141    2.517730 5.173191
## 29      Hamid Hassan     106    2.509434 4.686038
## 30        SL Malinga     419    2.498807 4.968974

Hope you have fun with my yorkr package.!

Introducing cricket package yorkr: Part 2-Trapped leg before wicket!


“It was a puzzling thing. The truth knocks on the door and you say ‘Go away, I ’m looking for the truth,’ and so it goes away. Puzzling.”

“But even though Quality cannot be defined, you know what Quality is!”

“The Buddha, the Godhead, resides quite comfortably in the circuits of a digital computer or the gears of a cycle transmission as he does at the top of a mountain or in the petals of the flower. To think otherwise is to demean the Buddha – which is to demean oneself.”

                Zen and the Art of Motorcycle maintenance - Robert M Pirsig

Introduction

If we were to to extend the last quote from Zen and the Art of Motorcycle Maintenance, by Robert M Pirsig, I think it would be fair to say that the Buddha also comfortably resides in the exquisite backhand cross-court return of Bjorn Borg, to the the graceful arc of the football in a Lionel Messi’s free kick to the smashing cover drive of Sunil Gavaskar.

In this post I continue to introduce my latest cricket package yorkr. This post is a continuation of my earlier post – Introducing cricket package yorkr-Part1:Beaten by sheer pace!. This post deals with Class 2 functions namely the performances of a team in all matches against a single opposition for e.g all matches of India-Australia, Pakistan-West Indies etc. You can clone/fork the code for my package yorkr from Github at yorkr

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

 

Note 1: The package currently only supports ODI, T20s and IPL T20 matches.

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

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

The list of function in Class 2 are

  1. teamBatsmenPartnershiOppnAllMatches()
  2. teamBatsmenPartnershipOppnAllMatchesChart()
  3. teamBatsmenVsBowlersOppnAllMatches()
  4. teamBattingScorecardOppnAllMatches()
  5. teamBowlingPerfOppnAllMatches()
  6. teamBowlersWicketsOppnAllMatches()
  7. teamBowlersVsBatsmenOppnAllMatches()
  8. teamBowlersWicketKindOppnAllMatches()
  9. teamBowlersWicketRunsOppnAllMatches()
  10. plotWinLossBetweenTeams()

1. Install the package from CRAN

if (!require("yorkr")) {
  install.packages("yorkr") 
  library("yorkr")
}
library(plotly) 
rm(list=ls())

2. Get data for all matches between 2 teams

We can get all matches between any 2 teams using the function below. The dir parameter should point to the folder which RData files of the individual matches. This function creates a data frame of all the matches and also saves the dataframe as RData

setwd("C:/software/cricket-package/york-test/yorkrData/ODI/ODI-matches")
matches <- getAllMatchesBetweenTeams("Australia","India",dir=".")
dim(matches)
## [1] 67428    25

I have however already saved the matches for all possible combination of opposing countries. The data for these matches for the individual teams/countries can be obtained from Github at in the folder ODI-allmatches-between-two-teams

Note: The dataframe for the different head-to-head matches can be loaded directly into your code. The datframes are 15000+ rows x 25 columns. While I have 10 functions to process the details between teams, feel free to let loose any statistical or machine learning algorithms on the dataframe. So go ahead with any insights that can be gleaned from random forests, ridge regression,SVM classifiers and so on. If you do come up with something interesting, I would appreciate if you could drop me a note. Also please do attribute source to Cricsheet (http://cricsheet.org), the package york and my blog Giga thoughts

3. Save data for all matches between all combination of 2 teams

This can be done locally using the function below. You could use this function to combine all matches between any 2 teams into a single dataframe and save it in the current folder. The current implementation expectes that the the RData files of individual matches are in ../data folder. Since I already have converted this I will not be running this again

#saveAllMatchesBetweenTeams()

4. Load data directly for all matches between 2 teams

As in my earlier post I pick all matches between 2 random teams. I load the data directly from the stored RData files. When we load the Rdata file a “matches” object will be created. This object can be stored for the apporpriate teams as below

setwd("C:/software/cricket-package/york-test/yorkrData/ODI/ODI-allmatches-between-two-teams")
load("India-Australia-allMatches.RData")
aus_ind_matches <- matches
dim(aus_ind_matches)
## [1] 21909    25
load("England-New Zealand-allMatches.RData")
eng_nz_matches <- matches
dim(eng_nz_matches)
## [1] 15343    25
load("Pakistan-South Africa-allMatches.RData")
pak_sa_matches <- matches
dim(pak_sa_matches)
## [1] 17083    25
load("Sri Lanka-West Indies-allMatches.RData")
sl_wi_matches <- matches
dim(sl_wi_matches)
## [1] 4869   25
load("Bangladesh-Ireland-allMatches.RData")
ban_ire_matches <-matches
dim(ban_ire_matches)
## [1] 1668   25
load("Kenya-Bermuda-allMatches.RData")
ken_ber_matches <- matches
dim(ken_ber_matches)
## [1] 1518   25
load("Scotland-Canada-allMatches.RData")
sco_can_matches <-matches
dim(sco_can_matches)
## [1] 1061   25
load("Netherlands-Afghanistan-allMatches.RData")
nl_afg_matches <- matches
dim(nl_afg_matches)
## [1] 402  25

5. Team Batsmen partnership (all matches with opposition)

This function will create a report of the batting partnerships in the teams. The report can be brief or detailed depending on the parameter ‘report’. The top batsmen in India-Australia clashes are Ricky Ponting from Australia and Mahendra Singh Dhoni of India.

m<- teamBatsmenPartnershiOppnAllMatches(aus_ind_matches,'Australia',report="summary")
m
## Source: local data frame [47 x 2]
## 
##       batsman totalRuns
##        (fctr)     (dbl)
## 1  RT Ponting       876
## 2  MEK Hussey       753
## 3   GJ Bailey       614
## 4   SR Watson       609
## 5   MJ Clarke       607
## 6   ML Hayden       573
## 7   A Symonds       536
## 8    AJ Finch       525
## 9   SPD Smith       467
## 10  DA Warner       391
## ..        ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(aus_ind_matches,'India',report="summary")
m
## Source: local data frame [44 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1      MS Dhoni      1156
## 2     RG Sharma       918
## 3  SR Tendulkar       910
## 4       V Kohli       902
## 5     G Gambhir       536
## 6  Yuvraj Singh       524
## 7      SK Raina       509
## 8      S Dhawan       471
## 9      V Sehwag       289
## 10   RV Uthappa       283
## ..          ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(aus_ind_matches,'Australia',report="detailed")
m <-teamBatsmenPartnershiOppnAllMatches(pak_sa_matches,'Pakistan',report="summary")
m
## Source: local data frame [40 x 2]
## 
##            batsman totalRuns
##             (fctr)     (dbl)
## 1    Misbah-ul-Haq       727
## 2      Younis Khan       657
## 3    Shahid Afridi       558
## 4  Mohammad Yousuf       539
## 5  Mohammad Hafeez       477
## 6     Shoaib Malik       452
## 7    Ahmed Shehzad       348
## 8     Abdul Razzaq       246
## 9     Kamran Akmal       241
## 10      Umar Akmal       215
## ..             ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(eng_nz_matches,'England',report="summary")
m
## Source: local data frame [47 x 2]
## 
##           batsman totalRuns
##            (fctr)     (dbl)
## 1         IR Bell       654
## 2         JE Root       612
## 3  PD Collingwood       514
## 4      EJG Morgan       479
## 5         AN Cook       464
## 6       IJL Trott       362
## 7    KP Pietersen       358
## 8      JC Buttler       287
## 9         OA Shah       274
## 10      RS Bopara       222
## ..            ...       ...
m <-teamBatsmenPartnershiOppnAllMatches(sl_wi_matches,'Sri Lanka',report="summary")
m[1:50,]
## Source: local data frame [50 x 2]
## 
##             batsman totalRuns
##              (fctr)     (dbl)
## 1  DPMD Jayawardene       288
## 2     KC Sangakkara       238
## 3        TM Dilshan       224
## 4       WU Tharanga       220
## 5        AD Mathews       161
## 6     ST Jayasuriya       160
## 7       ML Udawatte        87
## 8   HDRL Thirimanne        67
## 9       MDKJ Perera        64
## 10    CK Kapugedera        57
## ..              ...       ...
m <- teamBatsmenPartnershiOppnAllMatches(ban_ire_matches,"Ireland",report="summary")
m
## Source: local data frame [16 x 2]
## 
##             batsman totalRuns
##              (fctr)     (dbl)
## 1   WTS Porterfield       111
## 2        KJ O'Brien        99
## 3        NJ O'Brien        75
## 4         GC Wilson        60
## 5          AR White        38
## 6       DT Johnston        36
## 7           JP Bray        31
## 8         JF Mooney        28
## 9          AC Botha        23
## 10         EC Joyce        16
## 11      PR Stirling        15
## 12      GH Dockrell         9
## 13        WB Rankin         9
## 14 D Langford-Smith         6
## 15       EJG Morgan         5
## 16        AR Cusack         0

6. Team batsmen partnership (all matches with opposition)

This is plotted graphically in the charts below

teamBatsmenPartnershipOppnAllMatchesChart(aus_ind_matches,"India","Australia")

teamBatsmenPartnership-1

teamBatsmenPartnershipOppnAllMatchesChart(pak_sa_matches,main="South Africa",opposition="Pakistan")

teamBatsmenPartnership-2

m<- teamBatsmenPartnershipOppnAllMatchesChart(eng_nz_matches,"New Zealand",opposition="England",plot=FALSE)
m[1:30,]
##          batsman    nonStriker runs
## 1  KS Williamson   LRPL Taylor  354
## 2    BB McCullum    MJ Guptill  275
## 3    LRPL Taylor KS Williamson  273
## 4     MJ Guptill   BB McCullum  227
## 5    BB McCullum      JD Ryder  212
## 6     MJ Guptill KS Williamson  196
## 7  KS Williamson    MJ Guptill  179
## 8       JD Ryder   BB McCullum  175
## 9       JDP Oram     SB Styris  153
## 10   LRPL Taylor    GD Elliott  147
## 11    GD Elliott   LRPL Taylor  143
## 12   LRPL Taylor    MJ Guptill  140
## 13        JM How   BB McCullum  128
## 14    MJ Guptill   LRPL Taylor  125
## 15   BB McCullum        JM How  117
## 16   BB McCullum   LRPL Taylor  116
## 17     SB Styris      JDP Oram  100
## 18   LRPL Taylor        JM How   98
## 19        JM How   LRPL Taylor   98
## 20      JDP Oram   BB McCullum   84
## 21   LRPL Taylor     L Vincent   71
## 22      JDP Oram    DL Vettori   70
## 23   LRPL Taylor   BB McCullum   61
## 24     SB Styris        JM How   55
## 25      DR Flynn     SB Styris   54
## 26    DL Vettori      JDP Oram   53
## 27     L Vincent   LRPL Taylor   53
## 28    MJ Santner   LRPL Taylor   53
## 29    SP Fleming     L Vincent   52
## 30        JM How     SB Styris   50
teamBatsmenPartnershipOppnAllMatchesChart(sl_wi_matches,"Sri Lanka","West Indies")

teamBatsmenPartnership-3

teamBatsmenPartnershipOppnAllMatchesChart(ban_ire_matches,"Bangladesh","Ireland")

teamBatsmenPartnership-4

7. Team batsmen versus bowler (all matches with opposition)

The plots below provide information on how each of the top batsmen fared against the opposition bowlers

teamBatsmenVsBowlersOppnAllMatches(aus_ind_matches,"India","Australia")

batsmenvsBowler-1

teamBatsmenVsBowlersOppnAllMatches(pak_sa_matches,"South Africa","Pakistan",top=3)

batsmenvsBowler-2

m <- teamBatsmenVsBowlersOppnAllMatches(eng_nz_matches,"England","New Zealnd",top=10,plot=FALSE)
m
## Source: local data frame [157 x 3]
## Groups: batsman [1]
## 
##    batsman       bowler  runs
##     (fctr)       (fctr) (dbl)
## 1  IR Bell JEC Franklin    63
## 2  IR Bell      SE Bond    13
## 3  IR Bell MR Gillespie    33
## 4  IR Bell     NJ Astle     0
## 5  IR Bell     JS Patel    20
## 6  IR Bell   DL Vettori    28
## 7  IR Bell     JDP Oram    48
## 8  IR Bell    SB Styris    12
## 9  IR Bell     KD Mills   124
## 10 IR Bell   TG Southee    84
## ..     ...          ...   ...
teamBatsmenVsBowlersOppnAllMatches(sl_wi_matches,"Sri Lanka","West Indies")

batsmenvsBowler-3

teamBatsmenVsBowlersOppnAllMatches(ban_ire_matches,"Bangladesh","Ireland")

batsmenvsBowler-4

8. Team batsmen versus bowler (all matches with opposition)

The following tables gives the overall performances of the country’s batsmen against the opposition. For India-Australia matches Dhoni, Rohit Sharma and Tendulkar lead the way. For Australia it is Ricky Ponting, M Hussey and GJ Bailey. In South Africa- Pakistan matches it is AB Devilliers, Hashim Amla etc.

a <-teamBattingScorecardOppnAllMatches(aus_ind_matches,main="India",opposition="Australia")
## Total= 8331
a
## Source: local data frame [44 x 5]
## 
##         batsman ballsPlayed fours sixes  runs
##          (fctr)       (int) (int) (int) (dbl)
## 1      MS Dhoni        1406    78    22  1156
## 2     RG Sharma        1015    73    24   918
## 3  SR Tendulkar        1157   103     6   910
## 4       V Kohli         961    87     6   902
## 5     G Gambhir         677    44     2   536
## 6  Yuvraj Singh         664    52    11   524
## 7      SK Raina         536    43    11   509
## 8      S Dhawan         470    55     6   471
## 9      V Sehwag         305    42     4   289
## 10   RV Uthappa         295    29     7   283
## ..          ...         ...   ...   ...   ...
teamBattingScorecardOppnAllMatches(aus_ind_matches,"Australia","India")
## Total= 9995
## Source: local data frame [47 x 5]
## 
##       batsman ballsPlayed fours sixes  runs
##        (fctr)       (int) (int) (int) (dbl)
## 1  RT Ponting        1107    86     8   876
## 2  MEK Hussey         816    56     5   753
## 3   GJ Bailey         578    51    13   614
## 4   SR Watson         653    81    10   609
## 5   MJ Clarke         786    45     5   607
## 6   ML Hayden         660    72     8   573
## 7   A Symonds         543    43    15   536
## 8    AJ Finch         617    52     9   525
## 9   SPD Smith         431    44     7   467
## 10  DA Warner         385    40     6   391
## ..        ...         ...   ...   ...   ...
teamBattingScorecardOppnAllMatches(pak_sa_matches,"South Africa","Pakistan")
## Total= 6657
## Source: local data frame [36 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1  AB de Villiers        1533   128    23  1423
## 2         HM Amla         864    88     3   815
## 3        GC Smith         726    68     3   597
## 4       JH Kallis         710    40     8   543
## 5       JP Duminy         620    35     3   481
## 6       CA Ingram         388    32     1   305
## 7    F du Plessis         363    30     4   278
## 8       Q de Kock         336    28     2   270
## 9       DA Miller         329    20     2   250
## 10       HH Gibbs         252    33     2   228
## ..            ...         ...   ...   ...   ...
teamBattingScorecardOppnAllMatches(sl_wi_matches,"West Indies","Sri Lanka")
## Total= 1800
## Source: local data frame [36 x 5]
## 
##          batsman ballsPlayed fours sixes  runs
##           (fctr)       (int) (int) (int) (dbl)
## 1       DM Bravo         353    20     6   265
## 2      RR Sarwan         315    11     3   205
## 3     MN Samuels         209    19     5   188
## 4       CH Gayle         198    18     8   176
## 5  S Chanderpaul         181     6     7   152
## 6      AB Barath         162     9     2   125
## 7       DJ Bravo         139     7     2   102
## 8       CS Baugh         102     5    NA    78
## 9    LMP Simmons          78     5     4    67
## 10     JO Holder          33     5     3    55
## ..           ...         ...   ...   ...   ...
teamBattingScorecardOppnAllMatches(eng_nz_matches,"England","New Zealand")
## Total= 6472
## Source: local data frame [47 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1         IR Bell         871    74     7   654
## 2         JE Root         651    54     5   612
## 3  PD Collingwood         619    34    15   514
## 4      EJG Morgan         445    35    22   479
## 5         AN Cook         616    49     3   464
## 6       IJL Trott         421    26     1   362
## 7    KP Pietersen         481    30     6   358
## 8      JC Buttler         199    28    11   287
## 9         OA Shah         323    17     6   274
## 10      RS Bopara         350    21    NA   222
## ..            ...         ...   ...   ...   ...
teamBatsmenPartnershiOppnAllMatches(sco_can_matches,"Scotland","Canada")
## Source: local data frame [20 x 2]
## 
##          batsman totalRuns
##           (fctr)     (dbl)
## 1     CS MacLeod       177
## 2      MW Machan        68
## 3      CJO Smith        43
## 4    FRJ Coleman        40
## 5      RR Watson        14
## 6     JH Stander        12
## 7       MA Leask        12
## 8     RML Taylor        10
## 9     KJ Coetzer         8
## 10   GM Hamilton         7
## 11        RM Haq         7
## 12    PL Mommsen         6
## 13     CM Wright         5
## 14        JD Nel         5
## 15      MH Cross         4
## 16     SM Sharif         4
## 17     JAR Blain         2
## 18  NFI McCallum         1
## 19 RD Berrington         1
## 20     NS Poonia         0

9. Team performances of bowlers (all matches with opposition)

Like the function above the following tables provide the top bowlers of the countries in the matches against the oppoition. In India-Australia matches Ishant Sharma leads, in Pakistan-South Africa matches Shahid Afridi tops and so on.

teamBowlingPerfOppnAllMatches(aus_ind_matches,"India","Australia")
## Source: local data frame [36 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1         I Sharma    44       1   739      20
## 2  Harbhajan Singh    40       0   926      15
## 3        RA Jadeja    39       0   867      14
## 4        IK Pathan    42       1   702      11
## 5         UT Yadav    37       2   606      10
## 6          P Kumar    27       0   501      10
## 7           Z Khan    33       1   500      10
## 8      S Sreesanth    34       0   454      10
## 9         R Ashwin    43       0   684       9
## 10   R Vinay Kumar    31       1   380       9
## ..             ...   ...     ...   ...     ...
teamBowlingPerfOppnAllMatches(pak_sa_matches,main="Pakistan",opposition="South Africa")
## Source: local data frame [24 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1    Shahid Afridi    38       0  1053      17
## 2      Saeed Ajmal    39       0   658      14
## 3  Mohammad Hafeez    38       0   774      13
## 4   Mohammad Irfan    29       0   467      13
## 5   Iftikhar Anjum    29       1   257      12
## 6       Wahab Riaz    31       0   534      11
## 7      Junaid Khan    32       0   429      10
## 8    Sohail Tanvir    26       1   409       9
## 9    Shoaib Akhtar    22       1   313       9
## 10        Umar Gul    25       2   365       7
## ..             ...   ...     ...   ...     ...
teamBowlingPerfOppnAllMatches(eng_nz_matches,"New Zealand","England")
## Source: local data frame [33 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1      TG Southee    40       0   684      19
## 2        KD Mills    36       1   742      17
## 3      DL Vettori    35       0   561      16
## 4  MJ McClenaghan    34       0   515      14
## 5         SE Bond    17       1   205      11
## 6      GD Elliott    20       0   194      10
## 7    JEC Franklin    24       0   418       7
## 8   KS Williamson    21       1   225       7
## 9        TA Boult    18       2   195       7
## 10    NL McCullum    30       0   425       6
## ..            ...   ...     ...   ...     ...
teamBowlingPerfOppnAllMatches(sl_wi_matches,"Sri Lanka","West Indies")
## Source: local data frame [24 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1       SL Malinga    28       1   280      11
## 2       BAW Mendis    15       0   267       8
## 3  KMDN Kulasekara    13       1   185       7
## 4       AD Mathews    14       0   191       6
## 5   M Muralitharan    20       1   157       6
## 6      MF Maharoof     9       2    14       6
## 7       WPUJC Vaas     7       2    82       5
## 8       RAS Lakmal     7       0    55       4
## 9    ST Jayasuriya     1       0    38       4
## 10    HMRKB Herath    10       1   124       3
## ..             ...   ...     ...   ...     ...
teamBowlingPerfOppnAllMatches(ken_ber_matches,"Kenya","Bermuda")
## Source: local data frame [9 x 5]
## 
##        bowler overs maidens  runs wickets
##        (fctr) (int)   (int) (dbl)   (dbl)
## 1  JK Kamande    16       0   122       5
## 2  HA Varaiya    13       1    64       5
## 3   AS Luseno     6       0    32       4
## 4  PJ Ongondo     7       0    39       3
## 5    TM Odoyo     7       0    36       3
## 6  LN Onyango     7       0    37       2
## 7   SO Tikolo    18       0    81       1
## 8 NN Odhiambo    14       1    76       1
## 9    CO Obuya     4       0    20       0

10. Team bowler’s wickets (all matches with opposition)

This provided a graphical plot of the tables above

teamBowlersWicketsOppnAllMatches(aus_ind_matches,"India","Australia")

bowlerWicketsOppn-1

teamBowlersWicketsOppnAllMatches(aus_ind_matches,"Australia","India")

bowlerWicketsOppn-2

teamBowlersWicketsOppnAllMatches(pak_sa_matches,"South Africa","Pakistan",top=10)

bowlerWicketsOppn-3

m <-teamBowlersWicketsOppnAllMatches(eng_nz_matches,"England","Zealand",plot=FALSE)
m
## Source: local data frame [20 x 2]
## 
##            bowler wickets
##            (fctr)   (int)
## 1     JM Anderson      20
## 2       SCJ Broad      13
## 3         ST Finn      12
## 4  PD Collingwood      11
## 5        GP Swann      10
## 6   RJ Sidebottom       8
## 7       CR Woakes       8
## 8      A Flintoff       7
## 9     LE Plunkett       6
## 10      AU Rashid       6
## 11      BA Stokes       6
## 12     MS Panesar       5
## 13      LJ Wright       4
## 14     TT Bresnan       4
## 15      DJ Willey       4
## 16    JC Tredwell       3
## 17    CT Tremlett       2
## 18      RS Bopara       2
## 19      CJ Jordan       2
## 20        J Lewis       1
teamBowlersWicketsOppnAllMatches(ban_ire_matches,"Bangladesh","Ireland",top=7)

bowlerWicketsOppn-4

11. Team bowler vs batsmen (all matches with opposition)

These plots show how the bowlers fared against the batsmen. It shows which of the opposing teams batsmen were able to score the most runs

teamBowlersVsBatsmenOppnAllMatches(aus_ind_matches,'India',"Australia",top=5)

bowlerVsBatsmen-1

teamBowlersVsBatsmenOppnAllMatches(pak_sa_matches,"Pakistan","South Africa",top=3)

bowlerVsBatsmen-2

teamBowlersVsBatsmenOppnAllMatches(eng_nz_matches,"England","New Zealand")

bowlerVsBatsmen-3

teamBowlersVsBatsmenOppnAllMatches(eng_nz_matches,"New Zealand","England")

bowlerVsBatsmen-4

12. Team bowler’s wicket kind (caught,bowled,etc) (all matches with opposition)

The charts below show the wicket kind taken by the bowler (caught, bowled, lbw etc)

teamBowlersWicketKindOppnAllMatches(aus_ind_matches,"India","Australia",plot=TRUE)

bowlerWickets-1

m <- teamBowlersWicketKindOppnAllMatches(aus_ind_matches,"Australia","India",plot=FALSE)
m[1:30,]
##        bowler        wicketKind wicketPlayerOut runs
## 1  GD McGrath            caught    SR Tendulkar   69
## 2   SR Watson            caught        D Mongia  532
## 3  MG Johnson               lbw        V Sehwag 1020
## 4       B Lee            caught        R Dravid  671
## 5       B Lee            bowled          M Kaif  671
## 6  NW Bracken            caught        SK Raina  429
## 7  GD McGrath            caught       IK Pathan   69
## 8  NW Bracken               lbw        MS Dhoni  429
## 9  MG Johnson               lbw    SR Tendulkar 1020
## 10 MG Johnson            bowled       G Gambhir 1020
## 11   SR Clark            caught    SR Tendulkar  254
## 12   JR Hopes            caught    Yuvraj Singh  346
## 13   SR Clark               lbw      RV Uthappa  254
## 14    GB Hogg            caught        R Dravid  427
## 15  MJ Clarke           run out       IK Pathan  212
## 16  MJ Clarke           stumped Harbhajan Singh  212
## 17  MJ Clarke            bowled        RR Powar  212
## 18    GB Hogg            caught          Z Khan  427
## 19    GB Hogg            caught        MS Dhoni  427
## 20      B Lee               lbw       G Gambhir  671
## 21 MG Johnson               lbw      RV Uthappa 1020
## 22      B Lee            caught        R Dravid  671
## 23    GB Hogg            bowled    SR Tendulkar  427
## 24      B Lee            caught        MS Dhoni  671
## 25   JR Hopes            caught       RG Sharma  346
## 26    GB Hogg               lbw       IK Pathan  427
## 27 MG Johnson            bowled    Yuvraj Singh 1020
## 28    GB Hogg caught and bowled          Z Khan  427
## 29   SR Clark            bowled     S Sreesanth  254
## 30   JR Hopes            caught      SC Ganguly  346
teamBowlersWicketKindOppnAllMatches(sl_wi_matches,"Sri Lanka",'West Indies',plot=TRUE)

bowlerWickets-2

13. Team bowler’s wicket taken and runs conceded (all matches with opposition)

teamBowlersWicketRunsOppnAllMatches(aus_ind_matches,"India","Australia")

wicketRuns-1

m <-teamBowlersWicketRunsOppnAllMatches(pak_sa_matches,"Pakistan","South Africa",plot=FALSE)
m[1:30,]
## Source: local data frame [30 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1         Umar Gul    25       2   365       7
## 2   Iftikhar Anjum    29       1   257      12
## 3     Yasir Arafat     5       0    33       1
## 4     Abdul Razzaq    16       0   290       4
## 5  Mohammad Hafeez    38       0   774      13
## 6    Shahid Afridi    38       0  1053      17
## 7     Shoaib Malik    18       0   219       4
## 8    Sohail Tanvir    26       1   409       9
## 9     Abdur Rehman    25       0   301       4
## 10   Mohammad Asif    10       1   204       2
## ..             ...   ...     ...   ...     ...

14. Plot of wins vs losses between teams.

setwd("C:/software/cricket-package/york-test/yorkrData/ODI/ODI-matches")
plotWinLossBetweenTeams("India","Sri Lanka")

winsLosses-1

plotWinLossBetweenTeams('Pakistan',"South Africa",".")

winsLosses-2

plotWinLossBetweenTeams('England',"New Zealand",".")

winsLosses-3

plotWinLossBetweenTeams("Australia","West Indies",".")

winsLosses-4

plotWinLossBetweenTeams('Bangladesh',"Zimbabwe",".")

winsLosses-5

plotWinLossBetweenTeams('Scotland',"Ireland",".")

winsLosses-6

Conclusion

This post included all functions for all matches between any 2 opposing countries. As before the data frames are already available. You can load the data and begin to use them. If more insights from the dataframe are possible do go ahead. But please do attribute the source to Cricheet (http://cricsheet.org), my package yorkr and my blog. Do give the functions a spin for yourself.

There are 2 more posts required for the introduction of MY yorkr package.So, Hasta la vista, baby! I’ll be back!

Also see

You may also like

  1. Introducing cricketr! : An R package to analyze performances of cricketers
  2. Cricket analytics with cricketr
  3. cricketr adapts to the Twenty20 International!
  4. The making of Total Control Android game
  5. De-blurring revisited with Wiener filter using OpenCV
  6. Rock N’ Roll with Bluemix, Cloudant & NodeExpress

Introducing cricket package yorkr: Part 1- Beaten by sheer pace!


“We need to regard statistical intuition with proper suspicion and replace impression formation by computation wherever possible”

“We are pattern seekers, believers in a coherent world”

“The hot hand is entirely in the eyes of the beholders, who are consistently” “too quick to perceive order and causality in randomeness. The hot hand is a” “massive and widespread cognitive illusion”

                   "Thinking, Fast and Slow - Daniel Kahneman"

Introduction

Yorker (noun) :A yorker is a bowling delivery in cricket, that pitches at or around the batsman’s toes. Also known as ‘toe crusher’

My package ‘yorkr’ is now available on CRAN. This package is based on data from Cricsheet. Cricsheet has the data of ODIs, Test, Twenty20 and IPL matches as yaml files. The yorkr package provides functions to convert the yaml files to more easily R consumable entities, namely dataframes. In fact all ODI matches have already been converted and are available for use at yorkrData. However as future matches are added to Cricsheet, you will have to convert the match files yourself. More details below.

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

 

This post can be viewed at RPubs at yorkr-Part1 or can also be downloaded as a PDF document yorkr-1.pdf

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

Important note: Do check out the python avatar of cricketr, ‘cricpy’ in my post ‘Introducing cricpy:A python package to analyze performances of cricketers

1. First things first

  1. yorkr currently has a total 70 functions as of now. I have intentionally avoided abbreviating function names by dropping vowels, as is the usual practice in coding, because the resulting abbreviated names created would be very difficult to remember, and use. So instead of naming a function as tmBmenPrtshpOppnAllMtches(), I have used the longer form for e.g. teamBatsmenPartnershipOppnAllmatches(), which is much clearer. The longer form will be more intuitive. Moreover RStudio prompts the the different functions which have the same prefix and one does not need to type in the entire function name.
  2. The package yorkr has 4 classes of functions
  • Class 1- Team performances in a match
  • Class 2- Team performances in all matches against a single oppostion (e.g. all matches of India vs Australia or all matches of England vs Pakistan etc.)
  • Class 3- Team performance in all matches against all Opposition (India vs All,Pakistan vs All etc.)
  • Class 4- Individual performances of batsmen and bowlers

In this post I will be looking into Class 1 functions, namely the performances of opposing teams in a single match

The list of functions are

  1. teamBattingScorecardMatch()
  2. teamBatsmenPartnershipMatch()
  3. teamBatsmenVsBowlersMatch()
  4. teamBowlingScorecardMatch()
  5. teamBowlingWicketKindMatch()
  6. teamBowlingWicketRunsMatch()
  7. teamBowlingWicketRunsMatch()
  8. teamBowlingWicketMatch()
  9. teamBowlersVsBatsmenMatch()
  10. matchWormGraph()

2. Install the package from CRAN

library(yorkr)
rm(list=ls())

3. Convert and save yaml file to dataframe

This function will convert a yaml file in the format as specified in Cricsheet to dataframe. This will be saved as as RData file in the target directory. The name of the file wil have the following format team1-team2-date.RData. This is seen below.

convertYaml2RDataframe("225171.yaml","./source","./data")
## [1] "./source/225171.yaml"
## [1] "first loop"
## [1] "second loop"
setwd("./data")
dir()
## [1] "Australia-India-2012-02-12.RData"      
## [2] "Bangladesh-Zimbabwe-2009-10-27.RData"  
## [3] "convertedFiles.txt"                    
## [4] "England-New Zealand-2007-01-30.RData"  
## [5] "Ireland-England-2006-06-13.RData"      
## [6] "Pakistan-South Africa-2013-11-08.RData"
## [7] "Sri Lanka-West Indies-2011-02-06.RData"
setwd("..")

4. Convert and save all yaml files to dataframes

This function will convert all yaml files from a source directory to dataframes and save it in the target directory with the names as mentioned above.

convertAllYaml2RDataframes("./source","./data")
## [1] 1
## i= 1   file= ./source/225171.yaml 
## [1] "first loop"
## [1] "second loop"
## [1] 633  25

5. yorkrData – A Github repositiory

Cricsheet has ODI matches from 2006. There are a total of 1167 ODI matches(files) out of which 34 yaml files had format problems and were skipped. Incidentally I have already converted the 1133 yaml files in the ODI directory of Cricsheet to dataframes and saved then as RData. The rest of the yaml files ave already been converted to RData and are available for use. All the converted RData files can be accessed from my Github link yorkrData under the folder ODI-matches. You will need to use the functions to convert new match files, as they are added to Cricsheet. There is aslo a file named ‘convertedFiles’ which will have the name of the original file and the converted file as below

convertedFiles

  • 225171.yaml:Ireland-England-2006-06-13.RData
  • 225245.yaml:England-Pakistan-2006-08-30.RData
  • 225246.yaml:England-Pakistan-2006-09-02.RData …

You can download the the zip of the files and use it directly in the functions as follows

Note 1: The package in its current form handles ODIs,T20s and IPL T20 matches

Note 2: The link to the converted data frames have been provided above. The dataframes are around 600 rows x 25 columns. In this post I have created 10 functions that analyze team performances in a match. However you are free to slice and dice the dataframe in any way you like. If you do come up with interesting analyses, please do attribute the source of the data to Cricsheet, and my package yorkr and my blog. I would appreciate it if you could send me a note. .

6. Load the match data as dataframes

As mentioned above in this post I will using the functions from Class 1. For this post I will be using the match data from 5 random matches between 10 different opposing teams/countries. For this I will directly use the converted RData files rather than getting the data through the getMatchDetails()

With the RData we can load the data in 2 ways

A. With getMatchDetails()

  1. With getMatchDetails() using the 2 teams and the date on which the match occured
aus_ind <- getMatchDetails("Australia","India","2012-02-12",dir="./data")

or

B.Directly load RData into your code.

The match details will be loaded into a dataframe called ’overs’ which you can assign to a suitable name as below

The randomly selected matches are

  • Australia vs India – 2012-02-12, Adelaide
  • England vs New Zealand – 2007-01-30, Perth
  • Pakistan vs South Africa – 2013-07-08, UAE
  • Sri Lanka vs West Indioes -2011-02-06, Colombo(SSC)
  • Bangladesh vs Zimbabwe -2009-10-27, Dhaka

Directly load RData from file

load("./data/Australia-India-2012-02-12.RData")
aus_ind <- overs
load("./data/England-New Zealand-2007-01-30.RData")
eng_nz <- overs
load("./data/Pakistan-South Africa-2013-11-08.RData")
pak_sa <- overs
load("./data/Sri Lanka-West Indies-2011-02-06.RData")
sl_wi<- overs
load("./data/Bangladesh-Zimbabwe-2009-10-27.RData")
ban_zim <- overs

7. Team batting scorecard

Compute and display the batting scorecard of the teams in the match. The top batsmen in are G Gambhir(Ind), PJ Forrest(Aus), Q De Kock(SA) and KC Sangakkara(SL)

teamBattingScorecardMatch(aus_ind,'India')
## Total= 258
## Source: local data frame [8 x 5]
## 
##     batsman ballsPlayed fours sixes  runs
##      (fctr)       (int) (dbl) (dbl) (dbl)
## 1 G Gambhir         110     7     0    92
## 2  V Sehwag          20     3     0    20
## 3   V Kohli          28     1     0    18
## 4 RG Sharma          41     1     1    33
## 5  SK Raina          30     3     1    38
## 6  MS Dhoni          57     0     1    44
## 7 RA Jadeja           8     0     0    12
## 8  R Ashwin           2     0     0     1
teamBattingScorecardMatch(aus_ind,'Australia')
## Total= 260
## Source: local data frame [9 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (dbl) (dbl) (dbl)
## 1    DA Warner          23     2     0    18
## 2   RT Ponting          13     1     0     6
## 3    MJ Clarke          43     5     0    38
## 4   PJ Forrest          83     5     2    66
## 5    DJ Hussey          76     5     0    72
## 6 DT Christian          36     2     0    39
## 7      MS Wade          17     1     0    16
## 8    RJ Harris           2     0     0     2
## 9     CJ McKay           3     0     0     3
teamBattingScorecardMatch(pak_sa,'South Africa')
## Total= 256
## Source: local data frame [7 x 5]
## 
##          batsman ballsPlayed fours sixes  runs
##           (fctr)       (int) (dbl) (dbl) (dbl)
## 1      Q de Kock         132     9     1   112
## 2        HM Amla          50     6     0    46
## 3   F du Plessis          21     1     0    10
## 4 AB de Villiers          40     2     0    30
## 5      DA Miller           9     0     0     5
## 6      JP Duminy          20     1     1    25
## 7      R McLaren          21     3     1    28
teamBattingScorecardMatch(sl_wi,'Sri Lanka')
## Total= 261
## Source: local data frame [10 x 5]
## 
##             batsman ballsPlayed fours sixes  runs
##              (fctr)       (int) (dbl) (dbl) (dbl)
## 1       WU Tharanga          50     5     0    39
## 2        TM Dilshan          27     2     1    30
## 3     KC Sangakkara         103     4     1    75
## 4  DPMD Jayawardene          52     2     0    44
## 5     CK Kapugedera          17     0     0    17
## 6    TT Samaraweera           7     0     0     4
## 7       NLTC Perera           8     0     0     6
## 8        AD Mathews          22     1     1    36
## 9      HMRKB Herath           4     0     0     2
## 10       BAW Mendis           6     1     0     8

8. Plot the team batting partnerships

The functions below plot the team batting partnetship in the match Note: Many of the plots include an additional parameters plot which is either TRUE or FALSE. The default value is plot=TRUE. When plot=TRUE the plot will be displayed. When plot=FALSE the data frame will be returned to the user. The user can use this to create an interactive chary using one of th epackages like rcharts, ggvis,googleVis or plotly.

teamBatsmenPartnershipMatch(pak_sa,"Pakistan","South Africa")

batsmenPartnership-1

teamBatsmenPartnershipMatch(eng_nz,"New Zealand","England",plot=TRUE)

batsmenPartnership-2

teamBatsmenPartnershipMatch(ban_zim,"Bangladesh","Zimbabwe",plot=FALSE)
##              batsman        nonStriker runs
## 1        Tamim Iqbal   Junaid Siddique    0
## 2        Tamim Iqbal Mohammad Ashraful    5
## 3    Junaid Siddique       Tamim Iqbal    0
## 4  Mohammad Ashraful       Tamim Iqbal    0
## 5  Mohammad Ashraful     Raqibul Hasan   20
## 6      Raqibul Hasan Mohammad Ashraful   13
## 7      Raqibul Hasan   Shakib Al Hasan    3
## 8    Shakib Al Hasan     Raqibul Hasan   12
## 9    Shakib Al Hasan   Mushfiqur Rahim    1
## 10   Mushfiqur Rahim   Shakib Al Hasan    1
## 11   Mushfiqur Rahim       Naeem Islam   30
## 12   Mushfiqur Rahim      Abdur Razzak    6
## 13   Mushfiqur Rahim      Dolar Mahmud   11
## 14   Mushfiqur Rahim     Rubel Hossain    8
## 15       Mahmudullah   Mushfiqur Rahim    4
## 16       Naeem Islam   Mushfiqur Rahim   21
## 17      Abdur Razzak   Mushfiqur Rahim    3
## 18      Dolar Mahmud   Mushfiqur Rahim   41
teamBatsmenPartnershipMatch(aus_ind,"India","Australia", plot=TRUE)

batsmenPartnership-3

9. Batsmen vs Bowler

The function below computes and plots the performances of the batsmen vs the bowlers. As before the plot parameter can be set to TRUE or FALSE. By default it is plot=TRUE

teamBatsmenVsBowlersMatch(pak_sa,'Pakistan',"South Africa", plot=TRUE)

batsmenVsBowler-1

teamBatsmenVsBowlersMatch(aus_ind,'Australia',"India",plot=TRUE)

batsmenVsBowler-2

teamBatsmenVsBowlersMatch(ban_zim,'Zimbabwe',"Bangladesh", plot=TRUE)

batsmenVsBowler-3

m <- teamBatsmenVsBowlersMatch(sl_wi,'West Indies',"Sri Lanka", plot=FALSE)
m
## Source: local data frame [35 x 3]
## Groups: batsman [?]
## 
##      batsman        bowler runsConceded
##       (fctr)        (fctr)        (dbl)
## 1   CH Gayle  CRD Fernando            0
## 2   DM Bravo  CRD Fernando           15
## 3   DM Bravo   NLTC Perera           21
## 4   DM Bravo    AD Mathews           10
## 5   DM Bravo    BAW Mendis           11
## 6   DM Bravo CK Kapugedera            1
## 7   DM Bravo    TM Dilshan            5
## 8   DM Bravo  HMRKB Herath           16
## 9  AB Barath   NLTC Perera            0
## 10 RR Sarwan  CRD Fernando            6
## ..       ...           ...          ...

10. Bowling Scorecard

This function provides the bowling performance, the number of overs bowled, maidens, runs conceded and wickets taken for each match

teamBowlingScorecardMatch(eng_nz,'England')
## Source: local data frame [6 x 5]
## 
##           bowler overs maidens  runs wickets
##           (fctr) (int)   (int) (dbl)   (dbl)
## 1    LE Plunkett     9       0    54       3
## 2    CT Tremlett    10       0    72       1
## 3     A Flintoff    10       0    66       0
## 4     MS Panesar    10       2    35       2
## 5  JWM Dalrymple     5       0    43       0
## 6 PD Collingwood     6       0    36       1
teamBowlingScorecardMatch(eng_nz,'New Zealand')
## Source: local data frame [6 x 5]
## 
##         bowler overs maidens  runs wickets
##         (fctr) (int)   (int) (dbl)   (dbl)
## 1 JEC Franklin     8       1    45       1
## 2      SE Bond    10       0    58       1
## 3     JDP Oram     5       0    23       0
## 4     JS Patel    10       0    53       1
## 5   DL Vettori    10       0    40       3
## 6  CD McMillan     7       1    38       2
teamBowlingScorecardMatch(aus_ind,'Australia')
## Source: local data frame [6 x 5]
## 
##         bowler overs maidens  runs wickets
##         (fctr) (int)   (int) (dbl)   (dbl)
## 1    RJ Harris    10       0    57       1
## 2     MA Starc     8       0    49       0
## 3     CJ McKay    10       1    53       3
## 4 DT Christian    10       0    45       0
## 5    DJ Hussey     3       0    13       0
## 6   XJ Doherty     9       0    51       2

11. Wicket Kind

The plots below provide the bowling kind of wicket taken by the bowler (caught, bowled, lbw etc.)

teamBowlingWicketKindMatch(aus_ind,"India","Australia")

bowlingWicketKind-1

teamBowlingWicketKindMatch(aus_ind,"Australia","India")

bowlingWicketKind-2

teamBowlingWicketKindMatch(pak_sa,"South Africa","Pakistan")

bowlingWicketKind-3

m <-teamBowlingWicketKindMatch(sl_wi,"Sri Lanka",plot=FALSE)
m
##           bowler wicketKind wicketPlayerOut runs
## 1   CRD Fernando     bowled        CH Gayle   45
## 2    NLTC Perera     caught       AB Barath   36
## 3   HMRKB Herath        lbw       RR Sarwan   54
## 4     BAW Mendis     caught   S Chanderpaul   46
## 5    NLTC Perera        lbw        DM Bravo   36
## 6    NLTC Perera     caught       DJG Sammy   36
## 7   CRD Fernando     caught        DJ Bravo   45
## 8     BAW Mendis     caught       NO Miller   46
## 9     BAW Mendis     caught        CS Baugh   46
## 10    BAW Mendis     caught         SJ Benn   46
## 11    AD Mathews   noWicket        noWicket   33
## 12 CK Kapugedera   noWicket        noWicket    7
## 13    TM Dilshan   noWicket        noWicket   25

12. Wicket vs Runs conceded

The plots below provide the wickets taken and the runs conceded by the bowler in the match

teamBowlingWicketRunsMatch(pak_sa,"Pakistan","South Africa")

wicketRuns-1

teamBowlingWicketRunsMatch(aus_ind,"Australia","India")

wicketRuns-2

m <-teamBowlingWicketRunsMatch(sl_wi,"West Indies","Sri Lanka", plot=FALSE)
m
## Source: local data frame [6 x 5]
## 
##      bowler overs maidens  runs wickets
##      (fctr) (int)   (int) (dbl)   (chr)
## 1 R Rampaul     5       0    44       1
## 2 DJG Sammy    10       1    61       1
## 3  DJ Bravo    10       0    58       3
## 4  CH Gayle    10       0    34       0
## 5   SJ Benn    10       1    38       4
## 6 NO Miller     5       0    35       0

13. Wickets taken by bowler

The plots provide the wickets taken by the bowler

m <-teamBowlingWicketMatch(eng_nz,'England',"New Zealand", plot=FALSE)
m
##           bowler wicketKind wicketPlayerOut runs
## 1    LE Plunkett        lbw      SP Fleming   54
## 2    LE Plunkett     caught       PG Fulton   54
## 3 PD Collingwood     caught     LRPL Taylor   36
## 4     MS Panesar    stumped     CD McMillan   35
## 5    LE Plunkett     caught       L Vincent   54
## 6     MS Panesar     caught     BB McCullum   35
## 7    CT Tremlett     caught    JEC Franklin   72
## 8     A Flintoff   noWicket        noWicket   66
## 9  JWM Dalrymple   noWicket        noWicket   43
teamBowlingWicketMatch(sl_wi,"Sri Lanka","West Indies")

bowlingWickets-1

teamBowlingWicketMatch(eng_nz,"New Zealand","England")

bowlingWickets-2

14. Bowler Vs Batsmen

The functions compute and display how the different bowlers of the country performed against the batting opposition.

teamBowlersVsBatsmenMatch(ban_zim,"Bangladesh","Zimbabwe")

bowlerVsBatsmen-1

teamBowlersVsBatsmenMatch(aus_ind,"India","Australia")

bowlerVsBatsmen-2

teamBowlersVsBatsmenMatch(eng_nz,"England","New Zealand")

bowlerVsBatsmen-3

m <- teamBowlersVsBatsmenMatch(pak_sa,"Pakistan",plot=FALSE)
m
## Source: local data frame [30 x 3]
## Groups: bowler [?]
## 
##            bowler        batsman runsConceded
##            (fctr)         (fctr)        (dbl)
## 1  Mohammad Irfan      Q de Kock           25
## 2  Mohammad Irfan        HM Amla           17
## 3  Mohammad Irfan   F du Plessis            0
## 4  Mohammad Irfan AB de Villiers            9
## 5   Sohail Tanvir      Q de Kock           11
## 6   Sohail Tanvir        HM Amla            6
## 7   Sohail Tanvir      JP Duminy            9
## 8   Sohail Tanvir      R McLaren           12
## 9     Junaid Khan      Q de Kock           24
## 10    Junaid Khan        HM Amla            6
## ..            ...            ...          ...

15. Match worm graph

The plots below provide the match worm graph for the matches

matchWormGraph(aus_ind,'Australia',"India")

matchWorm-1

matchWormGraph(sl_wi,'Sri Lanka',"West Indies")

matchWorm-2

Conclusion

This post included all functions between 2 opposing countries from the package yorkr.As mentioned above the yaml match files have been already converted to dataframes and are available for download from Github. Go ahead and give it a try

To be continued. Watch this space!

You may also like

The making of cricket package yorkr – Part 2


Introduction

In this post (The making of cricket package yorkr-Part 2),  I continue to add new functionality to my package cricket package yorkr in R. In my earlier post The making of cricket package yorkr-Part 1 I had included functionality that will plot batsman partnerships, bowlers performances with wicket-kind, wicket-runs in specified ODI match. The earlier post also included functions that were based on confrontations between any 2 teams ( I had chosen the ODI matches between India and Australia).

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

320 and $6.99/Rs448 respectively

 

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

 

This post includes all ODI matches between a country and others. For obvious reasons I have chosen India and selected all ODI matches played by India with other countries. As mentioned in my earlier post the data is taken from Cricsheet. There are a total of 262 ODI matches that India has played. These 262 ODI matches played by India are then combined into one large dataframe that is 140,655 rows x 22 columns.

The analysis is then done on India’s batting and bowling performances on this huge dataframe for e.g. who has the most scores and highest batting partnerships, which bowlers are most effective against a country. Also the functions give details like which Indian bowlers have the worst performance or which bowlers have taken the most wicket against India. The functions also provide information on batsmen and bowlers of the opposing countries who have performed welll against India. Since the dataset is large and rich, the possible insights are infinite.I am including some functions that I have created on this dataset below.

Also note that it is possible to choose all ODI matches played by Australia, Pakistan, South Africa etc with the rest of the world. Similar analysis can be done for these countries also by using the functions below

As before the package ‘yorkr’ is still under development. I will be releasing the package and code in about 6-10 weeks time. Please be patient.

This post is also available at RPubs at yorkr-2. You can download this post as a PDF document at yorkr-2.pdf

My earlier package ‘cricketr’ (see Introducing cricketr: An R package for analyzing performances of cricketers) was based on data from ESPN Cricinfo Statsguru. Take a look at my book with all my articles based on my package cricketr at – Cricket analytics with cricketr!!!. The book is also available in paperback and kindle versions at Amazon which has, by the way, better formatting!

library(dplyr)
library(ggplot2)
library(yorkr)
matches <- getAllMatches("India",save=FALSE)
dim(matches)
## [1] 140655     22

1. Team Batting details – India

The following function provides the overall batting performance of India against all opposition

Virat Kohli has the best performance with a total of 7023 runs in ODIs followed closely by Mahendra Dhoni with 6885 runs and then Suresh Raina with 4964 runs While Kohli leads in the numnber of 4s (662), Dhoni and Raina has twice the number of 6s as compared to Kohli. However Kohli has a better strike rate (7023/774100) = 90.33% while Dhoni has an overall strike rate of (6885/7878100) = 87.39%

df <-teamBattingDetailsAllOppn(matches,theTeam="India")
## Total= 58033
df
## Source: local data frame [71 x 5]
## 
##         batsman ballsPlayed fours sixes  runs
##          (fctr)       (int) (int) (int) (dbl)
## 1       V Kohli        7774   662    65  7023
## 2      MS Dhoni        7878   515   129  6885
## 3      SK Raina        5076   429   114  4964
## 4     G Gambhir        5138   470    15  4495
## 5     RG Sharma        5245   370    89  4377
## 6  SR Tendulkar        4708   504    43  4196
## 7  Yuvraj Singh        4472   403    96  3976
## 8      V Sehwag        3102   494    74  3679
## 9      S Dhawan        2956   314    37  2694
## 10    AM Rahane        2490   194    24  2005
## ..          ...         ...   ...   ...   ...

2. Team batting details – Other countries against India

When we use other countries in theTeam then we get the performance of batsman of these countries against India in ODIs. This is because matches is a selection of all matches played by India against other countries. The following there calls show the performances of the batsman of England, South Africa, Pakistan & Ireland against India.

df <-teamBattingDetailsAllOppn(matches,theTeam="England")
## Total= 7602
df
## Source: local data frame [43 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1         IR Bell        1238   110     9  1085
## 2    KP Pietersen         990    89    10   847
## 3         AN Cook        1049   103     2   822
## 4       RS Bopara         632    42     8   534
## 5  PD Collingwood         450    38     6   393
## 6         OA Shah         394    40     7   385
## 7       IJL Trott         410    33     2   349
## 8         JE Root         408    32     4   336
## 9        SR Patel         336    25    10   329
## 10   C Kieswetter         309    34    13   313
## ..            ...         ...   ...   ...   ...
df <-teamBattingDetailsAllOppn(matches,theTeam="South Africa")
## Total= 6172
df
## Source: local data frame [36 x 5]
## 
##           batsman ballsPlayed fours sixes  runs
##            (fctr)       (int) (int) (int) (dbl)
## 1  AB de Villiers        1026   102    38  1179
## 2         HM Amla         796    74     1   704
## 3       Q de Kock         637    76     8   633
## 4       JH Kallis         666    50     4   554
## 5       JP Duminy         477    19     9   438
## 6    F du Plessis         470    30     8   421
## 7        GC Smith         355    25     3   252
## 8        HH Gibbs         318    26     3   242
## 9      MN van Wyk         270    23     1   202
## 10      DA Miller         188    19     4   193
## ..            ...         ...   ...   ...   ...
df <-teamBattingDetailsAllOppn(matches,theTeam="Pakistan")
## Total= 4660
df
## Source: local data frame [37 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (int) (int) (dbl)
## 1      Younis Khan         752    56     8   686
## 2     Shoaib Malik         669    61     4   595
## 3    Misbah-ul-Haq         619    49     6   550
## 4      Salman Butt         617    69     4   535
## 5  Mohammad Yousuf         458    37     2   432
## 6    Nasir Jamshed         473    41     4   408
## 7  Mohammad Hafeez         423    36     3   347
## 8    Shahid Afridi         187    16     7   235
## 9     Kamran Akmal         235    20     5   192
## 10      Umar Akmal         146     7     2   103
## ..             ...         ...   ...   ...   ...
df <-teamBattingDetailsAllOppn(matches,theTeam="Bangladesh")
## Total= 3761
df
## Source: local data frame [39 x 5]
## 
##              batsman ballsPlayed fours sixes  runs
##               (fctr)       (int) (int) (int) (dbl)
## 1    Mushfiqur Rahim         658    34    13   517
## 2        Tamim Iqbal         573    61     6   504
## 3    Shakib Al Hasan         591    42     5   493
## 4        Mahmudullah         310    27     1   269
## 5      Raqibul Hasan         262    11     3   202
## 6      Nasir Hossain         187    21     1   183
## 7  Mohammad Ashraful         235    17    NA   158
## 8      Soumya Sarkar         164    18     5   157
## 9        Imrul Kayes         183    21     1   155
## 10     Sabbir Rahman         142    16     1   136
## ..               ...         ...   ...   ...   ...

3. Top batting partnership report – India

The following functions show the top partnerships among Indian batsman in ODIs. Virat Kohli leads the way with 7023 runs followed by Mahendra Singh Dhoni with 6885 runs and Sures Raina in the 3rd pace.

The detailed report gives the breakup of the partnerships. It can be seen that Kohli has had the best partnership with Rohot Sharma and Suresh Raina. Dhoni best partnership is with Raina

a <- batsmanPartnershiAllOppn(matches,theTeam="India",report="summary")
a
## Source: local data frame [71 x 2]
## 
##         batsman totalRuns
##          (fctr)     (dbl)
## 1       V Kohli      7023
## 2      MS Dhoni      6885
## 3      SK Raina      4964
## 4     G Gambhir      4495
## 5     RG Sharma      4377
## 6  SR Tendulkar      4196
## 7  Yuvraj Singh      3976
## 8      V Sehwag      3679
## 9      S Dhawan      2694
## 10    AM Rahane      2005
## ..          ...       ...
b <- batsmanPartnershiAllOppn(matches,theTeam="India",report="detailed")
b[1:50,]
##     batsman      nonStriker partnershipRuns totalRuns
## 1   V Kohli        S Dhawan             657      7023
## 2   V Kohli       AM Rahane             502      7023
## 3   V Kohli       RG Sharma            1073      7023
## 4   V Kohli      KD Karthik             139      7023
## 5   V Kohli    SR Tendulkar             272      7023
## 6   V Kohli        R Dravid             132      7023
## 7   V Kohli        V Sehwag             255      7023
## 8   V Kohli    Yuvraj Singh             420      7023
## 9   V Kohli        SK Raina            1072      7023
## 10  V Kohli        MS Dhoni             534      7023
## 11  V Kohli Harbhajan Singh              13      7023
## 12  V Kohli       IK Pathan               1      7023
## 13  V Kohli               4               0      7023
## 14  V Kohli       G Gambhir             962      7023
## 15  V Kohli      RV Uthappa              10      7023
## 16  V Kohli       RA Jadeja              91      7023
## 17  V Kohli        R Ashwin              71      7023
## 18  V Kohli       AT Rayudu             345      7023
## 19  V Kohli Gurkeerat Singh               1      7023
## 20  V Kohli       YK Pathan              68      7023
## 21  V Kohli       STR Binny               4      7023
## 22  V Kohli       MK Tiwary             105      7023
## 23  V Kohli        AR Patel              39      7023
## 24  V Kohli        PA Patel             180      7023
## 25  V Kohli               6               0      7023
## 26  V Kohli         M Vijay              33      7023
## 27  V Kohli       KM Jadhav              10      7023
## 28  V Kohli        AM Nayar              25      7023
## 29  V Kohli     S Badrinath               9      7023
## 30 MS Dhoni        S Dhawan              49      6885
## 31 MS Dhoni       AM Rahane              50      6885
## 32 MS Dhoni       RG Sharma             300      6885
## 33 MS Dhoni      KD Karthik             158      6885
## 34 MS Dhoni    SR Tendulkar             325      6885
## 35 MS Dhoni        R Dravid             239      6885
## 36 MS Dhoni        V Sehwag             188      6885
## 37 MS Dhoni    Yuvraj Singh             837      6885
## 38 MS Dhoni        SK Raina            1423      6885
## 39 MS Dhoni          M Kaif              47      6885
## 40 MS Dhoni        D Mongia              47      6885
## 41 MS Dhoni      AB Agarkar               8      6885
## 42 MS Dhoni Harbhajan Singh              90      6885
## 43 MS Dhoni        RP Singh              95      6885
## 44 MS Dhoni        MM Patel               0      6885
## 45 MS Dhoni       IK Pathan             156      6885
## 46 MS Dhoni       G Gambhir             596      6885
## 47 MS Dhoni      RV Uthappa             137      6885
## 48 MS Dhoni     S Sreesanth              23      6885
## 49 MS Dhoni        I Sharma              67      6885
## 50 MS Dhoni         P Kumar              64      6885

4. Top batting partnership report – Other countries against India

Since matches already has selected all matches played by India with every other country calling the function with theTeam=“Australia” or “South Africa” will display those batsman who had the best partnerships in matches against India. It can be seen that Ponting, Hussey and Bailey lead against India while for the SOuth Africans it is De Villiers, Hashim Amla and Q De Kock.

a <- batsmanPartnershiAllOppn(matches,theTeam="Australia",report="summary")
a
## Source: local data frame [48 x 2]
## 
##       batsman totalRuns
##        (fctr)     (dbl)
## 1  RT Ponting       876
## 2  MEK Hussey       753
## 3   GJ Bailey       610
## 4   SR Watson       609
## 5   MJ Clarke       607
## 6   ML Hayden       573
## 7   A Symonds       536
## 8    AJ Finch       525
## 9   SPD Smith       467
## 10  DA Warner       391
## ..        ...       ...
b <- batsmanPartnershiAllOppn(matches,theTeam="South Africa",report="summary")
b
## Source: local data frame [36 x 2]
## 
##           batsman totalRuns
##            (fctr)     (dbl)
## 1  AB de Villiers      1179
## 2         HM Amla       704
## 3       Q de Kock       633
## 4       JH Kallis       554
## 5       JP Duminy       438
## 6    F du Plessis       421
## 7        GC Smith       252
## 8        HH Gibbs       242
## 9      MN van Wyk       202
## 10      DA Miller       193
## ..            ...       ...

5. Top batting partnership plots

The following plots display the above partnershi[p details graphically

batsmanPartnershipAllOppnPlot(matches,"India","All")

partnership-1-1

batsmanPartnershipAllOppnPlot(matches,"India","Australia")

partnership-1-2

batsmanPartnershipAllOppnPlot(matches,"India","South Africa")

partnership-1-3

dim(matches)
## [1] 140655     22

6. Batsman vs bowlers report

The reports below show how the Indian batsman fared against bowlers of other countries. Using rank=0 shows the top 10 batsman of India. Specificying a rank ‘i’ will show against which bowlers the batsman scored maximum runs. Kohli has made most runs against Perera, Kulasekara and Malinga.Dhoni against Muralidharan, Jayasuriya and Malinga. Surprisingly Tendulkars runs ODIs have come Mitchell Johnson, Brett Lee and James Anderson.

a <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=0)
a
## Source: local data frame [10 x 2]
## 
##         batsman runsScored
##          (fctr)      (dbl)
## 1       V Kohli       7023
## 2      MS Dhoni       6885
## 3      SK Raina       4964
## 4     G Gambhir       4495
## 5     RG Sharma       4377
## 6  SR Tendulkar       4196
## 7  Yuvraj Singh       3976
## 8      V Sehwag       3679
## 9      S Dhawan       2694
## 10    AM Rahane       2005
b <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=1)
b
## Source: local data frame [50 x 3]
## Groups: batsman [1]
## 
##    batsman          bowler  runs
##     (fctr)          (fctr) (dbl)
## 1  V Kohli     NLTC Perera   242
## 2  V Kohli KMDN Kulasekara   196
## 3  V Kohli      SL Malinga   175
## 4  V Kohli      AD Mathews   155
## 5  V Kohli      BAW Mendis   132
## 6  V Kohli       R Rampaul   127
## 7  V Kohli     JW Dernbach   121
## 8  V Kohli     JP Faulkner   118
## 9  V Kohli       DJG Sammy   116
## 10 V Kohli    HMRKB Herath   113
## ..     ...             ...   ...
b <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=2)
b
## Source: local data frame [50 x 3]
## Groups: batsman [1]
## 
##     batsman         bowler  runs
##      (fctr)         (fctr) (dbl)
## 1  MS Dhoni M Muralitharan   195
## 2  MS Dhoni  ST Jayasuriya   183
## 3  MS Dhoni     SL Malinga   144
## 4  MS Dhoni      SR Watson   135
## 5  MS Dhoni        ST Finn   130
## 6  MS Dhoni     MG Johnson   128
## 7  MS Dhoni    JP Faulkner   125
## 8  MS Dhoni  Shahid Afridi   120
## 9  MS Dhoni     TT Bresnan   111
## 10 MS Dhoni     AD Mathews   111
## ..      ...            ...   ...
b <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=3)
b
## Source: local data frame [50 x 3]
## Groups: batsman [1]
## 
##     batsman           bowler  runs
##      (fctr)           (fctr) (dbl)
## 1  SK Raina         S Randiv   124
## 2  SK Raina      NLTC Perera   124
## 3  SK Raina       TT Bresnan   113
## 4  SK Raina Mashrafe Mortaza   108
## 5  SK Raina  KMDN Kulasekara   104
## 6  SK Raina       SL Malinga    96
## 7  SK Raina      JW Dernbach    94
## 8  SK Raina          ST Finn    93
## 9  SK Raina      JC Tredwell    86
## 10 SK Raina       T Thushara    84
## ..      ...              ...   ...
b <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=6)
b
## Source: local data frame [50 x 3]
## Groups: batsman [1]
## 
##         batsman          bowler  runs
##          (fctr)          (fctr) (dbl)
## 1  SR Tendulkar      MG Johnson   178
## 2  SR Tendulkar           B Lee   137
## 3  SR Tendulkar     JM Anderson   133
## 4  SR Tendulkar      SL Malinga   133
## 5  SR Tendulkar KMDN Kulasekara   127
## 6  SR Tendulkar        JR Hopes    94
## 7  SR Tendulkar        Umar Gul    92
## 8  SR Tendulkar       SCJ Broad    89
## 9  SR Tendulkar    IDR Bradshaw    85
## 10 SR Tendulkar      BAW Mendis    80
## ..          ...             ...   ...

7.Batsman vs bowlers report – Bowlers of other countries against India

As before using another team for theTeam e.g. West Indies or Pakistan will show the batsman of those countries who made the most runs against India in ODIs. The reports below show the performances of batsmen from West Indies, Bangladesh and Zimbabwe.

a <- batsmanVsBowlersAllOppnRept(matches,theTeam="West Indies",rank=0)
a
## Source: local data frame [10 x 2]
## 
##        batsman runsScored
##         (fctr)      (dbl)
## 1    RR Sarwan        655
## 2   MN Samuels        653
## 3     DM Bravo        523
## 4  LMP Simmons        426
## 5     CH Gayle        414
## 6   KA Pollard        359
## 7    DJG Sammy        348
## 8   AD Russell        308
## 9     DJ Bravo        301
## 10     BC Lara        268
a <- batsmanVsBowlersAllOppnRept(matches,theTeam="Ireland",rank=0)
a
## Source: local data frame [10 x 2]
## 
##            batsman runsScored
##             (fctr)      (dbl)
## 1       NJ O'Brien        173
## 2  WTS Porterfield        158
## 3      DT Johnston         51
## 4      PR Stirling         42
## 5        AR Cusack         35
## 6      A Balbirnie         24
## 7        GC Wilson         19
## 8         DI Joyce         18
## 9        JF Mooney         17
## 10        AR White         13
a <- batsmanVsBowlersAllOppnRept(matches,theTeam="Zimbabwe",rank=0)
a
## Source: local data frame [10 x 2]
## 
##          batsman runsScored
##           (fctr)      (dbl)
## 1     BRM Taylor        328
## 2   E Chigumbura        322
## 3    H Masakadza        285
## 4  Sikandar Raza        202
## 5    SC Williams        186
## 6   CJ Chibhabha        158
## 7      V Sibanda        140
## 8      CR Ervine         94
## 9       P Utseya         71
## 10   R Mutumbami         61

8. Batsman vs bowlers plots

df <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=1)
batsmanVsBowlersAllOppnPlot(df)

batsmanvsbowler-1

df <- batsmanVsBowlersAllOppnRept(matches,theTeam="India",rank=2)
batsmanVsBowlersAllOppnPlot(df)

batsmanvsbowler-2

df <- batsmanVsBowlersAllOppnRept(matches,theTeam="South Africa",rank=1)
d <- complete.cases(df) # Remove NAs
df <- df[d,]
batsmanVsBowlersAllOppnPlot(df)

batsmanvsbowler-3

df <- batsmanVsBowlersAllOppnRept(matches,theTeam="Pakistan",rank=3)
d <- complete.cases(df) # Remove NAs
df <- df[d,]
batsmanVsBowlersAllOppnPlot(df)

batsmanvsbowler-4

9. Top ODI bowlers of India

The overall bowling performance of all Indian bowlers in all ODI matches played so far is computed in the function below. The top 5 Indian ODI bowlers with the best ODI performance are

  1. Ravindra Jadeja
  2. Ravichander Ashwin
  3. Zaheer Khan
  4. Harbhajan Singh
  5. Ishant Sharma
df <- teamBowlingDetailsAllOppnMain(matches,theTeam="India")
df
## Source: local data frame [59 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1        RA Jadeja    43       0  4743     153
## 2         R Ashwin    49       0  4209     146
## 3           Z Khan    47       0  3686     141
## 4  Harbhajan Singh    45       0  4032     123
## 5         I Sharma    51       0  3216     113
## 6         MM Patel    49       1  2392      92
## 7          P Kumar    50       2  2748      84
## 8         UT Yadav    51       0  2442      80
## 9   Mohammed Shami    43       0  1802      80
## 10    Yuvraj Singh    38       0  2588      77
## ..             ...   ...     ...   ...     ...

10. Top ODI bowlers of other countries against India

The tables below provide the details of the bowlers who have the best performances against India. This is obtained when theteam=“India”. Mitchell Johnson has a haul of 44 wicke taken at 1012 runs followed by Kulaseka who has 40 wickets for 1492 and then Mendis who has taken 34 wickets for 810 runs

df <- teamBowlingDetailsAllOppn(matches,theTeam="India")
df
## Source: local data frame [309 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1       MG Johnson    47       0  1012      44
## 2  KMDN Kulasekara    44       0  1492      40
## 3       BAW Mendis    37       0   810      34
## 4         DW Steyn    35       1   714      34
## 5       SL Malinga    48       1  1402      33
## 6      JM Anderson    31       0   991      33
## 7       AD Mathews    47       1   800      31
## 8      NLTC Perera    45       0   983      30
## 9          ST Finn    38       0   775      30
## 10       SCJ Broad    29       2   903      29
## ..             ...   ...     ...   ...     ...

11. Top ODI bowlers of other countries against India

The tables below give the performances of Indian bowlers against different opposition. Against Australia the top 3 bowlers are Ishant Sharma, Harbhajan Singh and Irfan Pathan. FOr ODI matches against England the top 3 are Jadeja, Ashwin and Munaf Patel. The tables are for matches against South Africa and Pakistan are also included

df <- teamBowlingDetailsAllOppn(matches,theTeam="Australia")
df
## Source: local data frame [37 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1         I Sharma    44       1   739      26
## 2  Harbhajan Singh    40       0   926      25
## 3        IK Pathan    42       1   702      22
## 4         UT Yadav    37       2   606      18
## 5      S Sreesanth    34       0   454      18
## 6        RA Jadeja    39       0   867      16
## 7           Z Khan    33       1   500      15
## 8         R Ashwin    43       0   680      14
## 9          P Kumar    27       0   501      14
## 10   R Vinay Kumar    31       1   380      14
## ..             ...   ...     ...   ...     ...
df <- teamBowlingDetailsAllOppn(matches,theTeam="England")
df
## Source: local data frame [32 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1        RA Jadeja    34       0   735      35
## 2         R Ashwin    32       0   792      34
## 3         MM Patel    16       0   478      18
## 4           Z Khan    26       1   518      17
## 5         RP Singh    19       1   438      12
## 6         I Sharma    32       1   418      12
## 7         RR Powar    22       0   259      11
## 8          B Kumar    17       1   367      10
## 9         SK Raina    17       0   238      10
## 10 Harbhajan Singh    15       0   293       9
## ..             ...   ...     ...   ...     ...
df <- teamBowlingDetailsAllOppn(matches,theTeam="South Africa")
df
## Source: local data frame [33 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1           Z Khan    19       1   552      25
## 2  Harbhajan Singh    31       0   580      15
## 3         MM Patel    19       0   310      15
## 4   Mohammed Shami     9       1   215      11
## 5     Yuvraj Singh    17       0   279       9
## 6        RA Jadeja    18       1   299       8
## 7          A Nehra    27       1   366       7
## 8        MM Sharma    16       0   307       7
## 9      S Sreesanth    18       0   266       7
## 10         B Kumar    11       0   374       6
## ..             ...   ...     ...   ...     ...
df <- teamBowlingDetailsAllOppn(matches,theTeam="Pakistan")
df
## Source: local data frame [28 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1         I Sharma    32       1   405      14
## 2           Z Khan    20       0   284      12
## 3        IK Pathan    30       3   504      10
## 4          P Kumar    24       0   387      10
## 5  Harbhajan Singh    29       0   339      10
## 6         RP Singh    25       1   319      10
## 7         R Ashwin    22       0   302      10
## 8        RA Jadeja    23       2   250      10
## 9          B Kumar    14       0   194       9
## 10    Yuvraj Singh    16       0   241       6
## ..             ...   ...     ...   ...     ...

12. Top Indian ODI bowlers vs batsman

The reports below give the performances of bowlers against opposition batsman 1.The 1st call with theteam=“India” and rank=0 gives the bowlers who have conceded the most runs against India 2. The 2nd call with rank=1 gives the names of Indian batsman who scored the most against India 3. The 3rd call gives the performance of Malinga who has conceded the 2nd most runs in ODIs against India and the batsman who made these runs

a <- bowlersVsBatsmanAllOppnRept(matches,theTeam="India",rank=0)
a
## Source: local data frame [10 x 2]
## 
##             bowler  runs
##             (fctr) (dbl)
## 1  KMDN Kulasekara  1448
## 2       SL Malinga  1319
## 3      NLTC Perera   959
## 4      JM Anderson   954
## 5       MG Johnson   931
## 6        SCJ Broad   877
## 7       BAW Mendis   783
## 8       AD Mathews   776
## 9          ST Finn   751
## 10        DJ Bravo   739
a <- bowlersVsBatsmanAllOppnRept(matches,theTeam="India",rank=1)
a
## Source: local data frame [31 x 3]
## Groups: bowler [1]
## 
##             bowler      batsman runsConceded
##             (fctr)       (fctr)        (dbl)
## 1  KMDN Kulasekara     V Sehwag          199
## 2  KMDN Kulasekara      V Kohli          196
## 3  KMDN Kulasekara    G Gambhir          157
## 4  KMDN Kulasekara SR Tendulkar          127
## 5  KMDN Kulasekara Yuvraj Singh          118
## 6  KMDN Kulasekara    RG Sharma          114
## 7  KMDN Kulasekara     SK Raina          104
## 8  KMDN Kulasekara     MS Dhoni           80
## 9  KMDN Kulasekara   KD Karthik           56
## 10 KMDN Kulasekara   SC Ganguly           51
## ..             ...          ...          ...
a <- bowlersVsBatsmanAllOppnRept(matches,theTeam="India",rank=2)
a
## Source: local data frame [31 x 3]
## Groups: bowler [1]
## 
##        bowler      batsman runsConceded
##        (fctr)       (fctr)        (dbl)
## 1  SL Malinga      V Kohli          175
## 2  SL Malinga    G Gambhir          170
## 3  SL Malinga     MS Dhoni          144
## 4  SL Malinga     V Sehwag          140
## 5  SL Malinga SR Tendulkar          133
## 6  SL Malinga     SK Raina           96
## 7  SL Malinga Yuvraj Singh           64
## 8  SL Malinga   KD Karthik           52
## 9  SL Malinga    RG Sharma           50
## 10 SL Malinga   RV Uthappa           47
## ..        ...          ...          ...

13. Top ODI bowlers of other countries vs batsman

When we use other teams in theTeam we get the names of Indian bowlers

a <- bowlersVsBatsmanAllOppnRept(matches,theTeam="Sri Lanka",rank=0)
a
## Source: local data frame [10 x 2]
## 
##             bowler  runs
##             (fctr) (dbl)
## 1           Z Khan  1141
## 2        RA Jadeja   882
## 3         I Sharma   855
## 4  Harbhajan Singh   805
## 5          P Kumar   758
## 6         R Ashwin   736
## 7        IK Pathan   674
## 8          A Nehra   584
## 9         UT Yadav   544
## 10        MM Patel   484
a <- bowlersVsBatsmanAllOppnRept(matches,theTeam="England",rank=0)
a
## Source: local data frame [10 x 2]
## 
##          bowler  runs
##          (fctr) (dbl)
## 1      R Ashwin   777
## 2     RA Jadeja   729
## 3        Z Khan   503
## 4      MM Patel   459
## 5      RP Singh   410
## 6      I Sharma   396
## 7     PP Chawla   375
## 8  Yuvraj Singh   370
## 9       B Kumar   353
## 10   AB Agarkar   336
a <- bowlersVsBatsmanAllOppnRept(matches,theTeam="New Zealand",rank=0)
a
## Source: local data frame [10 x 2]
## 
##            bowler  runs
##            (fctr) (dbl)
## 1        R Ashwin   456
## 2       RA Jadeja   363
## 3    Yuvraj Singh   320
## 4  Mohammed Shami   304
## 5         A Nehra   302
## 6         P Kumar   289
## 7        I Sharma   281
## 8          Z Khan   238
## 9         B Kumar   233
## 10       MM Patel   213

14. Top ODI bowlers vs batsman plots

The plots below give the the performances of bowlers against batsman. The logic is same as above

df <- bowlersVsBatsmanAllOppnRept(matches,theTeam="India",rank=1)
bowlerVsBatsmanAllOppnPlot(df,"India","India")

bowlerBatsman-1

df <- bowlersVsBatsmanAllOppnRept(matches,theTeam="England",rank=1)
bowlerVsBatsmanAllOppnPlot(df,"India","England")

bowlerBatsman-2

df <- bowlersVsBatsmanAllOppnRept(matches,theTeam="Australia",rank=1)
bowlerVsBatsmanAllOppnPlot(df,"India","England")

bowlerBatsman-3

15. Top ODI bowlers wicket kind

The following plots give the top 8 bowlers against India and the wicket kind taken

teamBowlingWicketKindAllOppn(matches,t1="India",t2="All")

wicketKind-1-1

The plots below give the top 8 Indian bowlers against different countries

teamBowlingWicketKindAllOppn(matches,t1="India",t2="Bangladesh")

wicketKind-2-1

teamBowlingWicketKindAllOppn(matches,t1="India",t2="New Zealand")

wicketKind-2-2

teamBowlingWicketKindAllOppn(matches,t1="India",t2="West Indies")

wicketKind-2-3

teamBowlingWicketKindAllOppn(matches,t1="India",t2="Sri Lanka")

wicketKind-2-4

16. Top ODI bowlers  wicket runs

The plot below gives the top 8 performances of bowlers against India with wickets taken and runs conceded. The maximum wickets is 44 (pink) and Mitchell Johnson has taken it conceding around 1000 runs. Kulasekara has 40 wickets (purple) conceding around 1400 runs

teamBowlingWicketRunsAllOppn(matches,t1="India",t2="All")

wicketRuns-1-1

The plots below give the top 8 Indian bowlers against different countries. The bar that is rightmost is the most wickets and the taller the bar more the runs conceded.

teamBowlingWicketRunsAllOppn(matches,t1="India",t2="Zimbabwe")

wicketRuns-2-1

teamBowlingWicketRunsAllOppn(matches,t1="India",t2="Australia")

wicketRuns-2-2

teamBowlingWicketRunsAllOppn(matches,t1="India",t2="Pakistan")

wicketRuns-2-3

teamBowlingWicketRunsAllOppn(matches,t1="India",t2="New Zealand")

wicketRuns-2-4

Conclusion

Here are some quick conclusions I have gleaned from the analysis

  1. Virat Kohli has the highest runs in ODI, followed by Mahendra Dhoni and then Suresh Raina.
  2. Though Kohli has the best strike rate, Dhoni and Raina have twice the number of 6’s as Kohli.
  3. Among batsmen from other countries that have to be feared are GJ Bailey, Younis Khan, AB Devillers etc
  4. Among Indian ODI bowlers Ravindra Jadeja, Ashwin and Zaheer Khan have the most wickets. 5.Ishant Sharma, Harbhajan Singh performed well against Australia and RA Jadeja,Ashwin against England and so on
  5. India has to be wary of Mitchell Johnson,Kulasekara, Malinga

Also see

  1. Cricket analytics with cricketr in paperback and Kindle versions
  2. Introducing cricketr! : An R package to analyze performances of cricketers
  3. Cricketr plays the ODIs
  4. Cricketr adapts to Twenty20 International

You may also like

  1. Revisiting crimes against women in India
  2. Literacy in India – A deepR dive
  3. Bend it like Bluemix,MongoDB using Autoscaling – Part 2
  4. A closer look at Robot Horse on a trot in Android
  5. Programming Zen and now – Sime essential tips
  6. Design principles of scalable distributed systems
  7. Sea shells on the sea shore

The making of cricket package yorkr – Part 1


Introduction

Here is a sneak preview of my latest package cricket package yorkr in R. My earlier package ‘cricketr’ (see Introducing cricketr: An R package for analyzing performances of cricketers) was based on data from ESPN Cricinfo Statsguru. My current package ‘yorkr’ is based on data from Cricsheet. The data for Test, ODI, Twenty20 matches in Cricheet are formatted as yaml files.

While the data available from ESPN Cricinfo Statsguru is a summary of the player’s performances, Cricsheet data is more detailed and granular. Cricsheet gives a ball-by-ball detail for each match as can be seen from the above website. Hence the type of analyses possible can be much more detailed and richer. Some cool functions in this package, include charts for batsman partnerships, performance of batsman against bowlers and how bowlers fared against batsman for a single ODI match or for all ODI matches between 2 opposing sides (for e.g Australia-India or West Indies-Sri Lanka)

This current post includes my first stab at analysing ODI data from Cricsheet. To do this I had to parse the Yaml files and flatten them out as data frames. That was a fairly involved task and I think I now have done it. I then perform analyses on these flattened 1000’s of data frames. This post contains my initial analyses of the ODI data from Cricsheet.

Since the package ‘yorkr’ is still work in progress. I will be adding more functions, refining existing functions and crossing t’s and dotting the i’s. I hope to have the yorkr package wrapped up in about 6-10 weeks time. The package and code should be available after that. Please ‘hold your horses’ till this time.

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

 

This report is also available at Rpubs at yorkr1 york1. The report can also be downloaded as a PDF document at yorkr-1.pdf

 

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

The current set of functions developed fall into 4 main categories

  • batsmen performance in match
  • bowlers performance in match
  • batsmen performance against opposition
  • bowlers performance against opposition

In the first part of the post I have taken an single Australia-India ODI match on 24 Feb 2008 at Sydney. (For details on this match look up Australia – India, Sydney)

The second part of the past looks at all ODI matches between Australia-India (there are 40 ODI matches between India and Australia)

While this post analyses 1 ODI match and all matches between 2 opposing sides (Australia vs India), the functions developed in yorkr(Part 1) can be used for any of 1000+ ODI matches and any combination of opposing countries!!!

So without much ado let me dive into the functions created

library(dplyr)
library(ggplot2)
library(yorkr)

Get the match details (Aus-Ind,24 Feb 2008,Sydney)

match <- getMatchDetails()

Team batting performances of the opposing teams

In this post I pick a ODI match played between India and Australia on 24 Feb 2008 at Sydney.

1. Team batting details (ODI Match)

This function gives the overall scores of the team for which the function is invoked

Team batting details (ODI Match)
This function gives the overall scores of the team for which the function is invoked

teamBattingDetailsMatch(match,"India")
## Total= 272
## Source: local data frame [11 x 5]
## 
##            batsman ballsPlayed fours sixes  runs
##             (fctr)       (int) (dbl) (dbl) (dbl)
## 1         V Sehwag          18     3     0    17
## 2     SR Tendulkar           3     0     0     2
## 3        G Gambhir         118     9     1   113
## 4        RG Sharma           3     0     0     1
## 5     Yuvraj Singh           3     1     0     5
## 6         MS Dhoni          64     4     0    36
## 7       RV Uthappa          40     4     1    51
## 8        IK Pathan          20     2     0    22
## 9  Harbhajan Singh          11     3     0    20
## 10     S Sreesanth           4     0     0     3
## 11        I Sharma           3     0     0     2
teamBattingDetailsMatch(match,"Australia")
## Total= 303
## Source: local data frame [7 x 5]
## 
##        batsman ballsPlayed fours sixes  runs
##         (fctr)       (int) (dbl) (dbl) (dbl)
## 1 AC Gilchrist           7     3     0    16
## 2    ML Hayden          61     5     1    54
## 3   RT Ponting         132     7     1   124
## 4    MJ Clarke          38     0     0    31
## 5    A Symonds          48     6     2    59
## 6   MEK Hussey          10     1     0    15
## 7     JR Hopes           3     0     0     4

2. Batsmen partnership (ODI Match)

The plot below shows the partnerships between batsman. Gautham Gambhir scored the highest followed by Uthappa. Gambhir had a good partnership with Sehway, Dhoni and Uthappa. On the Australian side Ponting had a good partnership with Hayden,Clarke and Symonds.

batsmenPartnershipMatch(match,"India")

partnershipmatch-1

batsmenPartnershipMatch(match,"Australia")

partnershipmatch-2

3. Batsmen vs Bowlers (ODI Match)

This chart shows how each batsman fared against the bowlers. Gambhir scored maximum from Hogg and Clarke. Ponting scores maximum from Pathan, Ishant Sharma, Sreesanth.

batsmenVsBowlersMatch(match,"India")

batsmenbowler-1

batsmenVsBowlersMatch(match,"Australia")

batsmenbowler-2

4. Team bowling details (ODI Match)

The table gives bowling details of each team

teamBowlingDetailsMatch(match,"India")
## Source: local data frame [6 x 5]
## 
##       bowler overs maidens  runs wickets
##       (fctr) (int)   (int) (dbl)   (dbl)
## 1      B Lee    10       2    58       5
## 2 NW Bracken    10       0    53       1
## 3   SR Clark    10       0    55       2
## 4   JR Hopes     6       0    27       1
## 5    GB Hogg     9       0    62       1
## 6  MJ Clarke     5       0    33       0
teamBowlingDetailsMatch(match,"Australia")
## Source: local data frame [6 x 5]
## 
##            bowler overs maidens  runs wickets
##            (fctr) (int)   (int) (dbl)   (dbl)
## 1     S Sreesanth     8       0    58       2
## 2        I Sharma    10       0    65       1
## 3       IK Pathan     9       0    73       0
## 4 Harbhajan Singh     9       0    50       2
## 5        V Sehwag     6       0    28       2
## 6    Yuvraj Singh     8       0    38       0

5. Wicket kind (ODI Match)

This chart gives the wicket kind or the type of wicket for the bowler vs the runs scored

teamBowlingWicketKindMatch(match,"India")

wicketKindmatch-1

teamBowlingWicketKindMatch(match,"Australia")

wicketKindmatch-2

6. Wickets Runs (ODI Match)l

This plot gives the number of wickets taken and the runs conceded by the bowler

teamBowlingWicketRunsMatch(match,"India")

wicketRunsMatch-1

teamBowlingWicketRunsMatch(match,"Australia")

wicketRunsMatch-2

7. Wicket (batsman) and total runs scored (ODI Match)

This plot gives the details of the wickets taken and the runs conceded. Brett Lee has the performance with 5 scalps. On the Indian side Sreesanth, Harbhajan and Sehwag have 2 wickets apiece. Sreesanth is the most expensive,

teamBowlingWicketMatch(match,"India")

wicketMatch-1

teamBowlingWicketMatch(match,"Australia")

wicketMatch-2

8. Bowler vs Batsman (ODI Match)

This plot below shows which of the batsman was most brutal against the bowler or who scored the most against the bowler. Ponting scores most against Pathan.

bowlersVsBatsmanMatch(match,"India")


batsmanMatch,-1

bowlersVsBatsmanMatch(match,"Australia")


batsmanMatch-2

9.

Worm graph (ODI Match) This chart gives the match worm of runs scored against the number deliveries.

matchWormGraph(match,team1="Australia",team2="India")

worm-1

The following charts show the performances of the batsmen and against the opposition. In this case I have chosen India and Australia. Hence the plots below show the best performers(batsmen and bowlers) of either team against their adversary. The below analyses are based on all ODI confrontations between Australia and India. There are a total of 40 head-on confrontations between Aus-India.

allMatches <- getOppositionDetails()

10.Batsman partnership against opposition (all ODI matches)

The report below gives the batsman who has had the best partnetship in Australia-India matches. On the Indian side the top 3 are Mahendra Singh Dhoni, Rohit Sharma followed by Tendulkar. Ponting, Hussey and Bailey are the top 3 for the Autralians. As far as ODI is concerned Dhoni towers over all others. Of course similar analyses can be done between India-Pakistan, India-South Africa etc. But at least against the Australians we need to have Dhoni and Rohit Sharma I think The report below gives a summary of the partnership runs

report <- batsmanPartnershipOppn(allMatches,"India",report="summary")
report
## Source: local data frame [44 x 2]
## 
##         batsman partnershipRuns
##          (fctr)           (dbl)
## 1      MS Dhoni            1156
## 2     RG Sharma             914
## 3  SR Tendulkar             910
## 4       V Kohli             902
## 5     G Gambhir             532
## 6  Yuvraj Singh             524
## 7      SK Raina             509
## 8      S Dhawan             471
## 9      V Sehwag             287
## 10   RV Uthappa             279
## ..          ...             ...
report <- batsmanPartnershipOppn(allMatches,"Australia",report="summary")
report
## Source: local data frame [48 x 2]
## 
##       batsman partnershipRuns
##        (fctr)           (dbl)
## 1  RT Ponting             876
## 2  MEK Hussey             753
## 3   GJ Bailey             610
## 4   SR Watson             609
## 5   MJ Clarke             607
## 6   ML Hayden             573
## 7   A Symonds             536
## 8    AJ Finch             525
## 9   SPD Smith             467
## 10  DA Warner             391
## ..        ...             ...

The report below gives a detailed breakup of the partnership runs

report <- batsmanPartnershipOppn(allMatches,"India",report="detailed")
report[1:40,]
##         batsman      nonStriker runs partnershipRuns
## 1      MS Dhoni    SR Tendulkar   71            1156
## 2      MS Dhoni        R Dravid   27            1156
## 3      MS Dhoni    Yuvraj Singh  128            1156
## 4      MS Dhoni        SK Raina  187            1156
## 5      MS Dhoni          M Kaif    6            1156
## 6      MS Dhoni        D Mongia   23            1156
## 7      MS Dhoni Harbhajan Singh   16            1156
## 8      MS Dhoni       IK Pathan   42            1156
## 9      MS Dhoni       G Gambhir  117            1156
## 10     MS Dhoni       RG Sharma   56            1156
## 11     MS Dhoni      RV Uthappa   51            1156
## 12     MS Dhoni     S Sreesanth   19            1156
## 13     MS Dhoni        I Sharma    4            1156
## 14     MS Dhoni         P Kumar    1            1156
## 15     MS Dhoni         V Kohli   78            1156
## 16     MS Dhoni       RA Jadeja  103            1156
## 17     MS Dhoni        R Ashwin   78            1156
## 18     MS Dhoni        R Sharma    2            1156
## 19     MS Dhoni   R Vinay Kumar   30            1156
## 20     MS Dhoni          Z Khan    6            1156
## 21     MS Dhoni       AM Rahane   47            1156
## 22     MS Dhoni       MK Pandey   34            1156
## 23     MS Dhoni Gurkeerat Singh    1            1156
## 24     MS Dhoni         B Kumar   26            1156
## 25     MS Dhoni        RR Powar    3            1156
## 26    RG Sharma    SR Tendulkar   66             914
## 27    RG Sharma    Yuvraj Singh    5             914
## 28    RG Sharma        SK Raina   69             914
## 29    RG Sharma        MS Dhoni   90             914
## 30    RG Sharma               4    0             914
## 31    RG Sharma       G Gambhir   35             914
## 32    RG Sharma         V Kohli  248             914
## 33    RG Sharma       RA Jadeja   13             914
## 34    RG Sharma        R Ashwin   11             914
## 35    RG Sharma        S Dhawan  247             914
## 36    RG Sharma       AM Rahane   77             914
## 37    RG Sharma       MK Pandey   53             914
## 38 SR Tendulkar        R Dravid   12             910
## 39 SR Tendulkar        V Sehwag  111             910
## 40 SR Tendulkar    Yuvraj Singh  173             910
report <- batsmanPartnershipOppn(allMatches,"Australia",report="detailed")
report[1:40,]
##       batsman   nonStriker runs partnershipRuns
## 1  RT Ponting    SR Watson  140             876
## 2  RT Ponting    DR Martyn   35             876
## 3  RT Ponting    MJ Clarke   63             876
## 4  RT Ponting    BJ Haddin   33             876
## 5  RT Ponting    ML Hayden  117             876
## 6  RT Ponting    A Symonds   41             876
## 7  RT Ponting   MEK Hussey   74             876
## 8  RT Ponting AC Gilchrist  113             876
## 9  RT Ponting     TD Paine   68             876
## 10 RT Ponting     CL White   84             876
## 11 RT Ponting    DA Warner    6             876
## 12 RT Ponting      MS Wade    9             876
## 13 RT Ponting    DJ Hussey   20             876
## 14 RT Ponting     SE Marsh   45             876
## 15 RT Ponting     BJ Hodge   28             876
## 16 MEK Hussey   RT Ponting   85             753
## 17 MEK Hussey    MJ Clarke   74             753
## 18 MEK Hussey    BJ Haddin   24             753
## 19 MEK Hussey      GB Hogg   19             753
## 20 MEK Hussey   MG Johnson   43             753
## 21 MEK Hussey     SR Clark    4             753
## 22 MEK Hussey    ML Hayden    5             753
## 23 MEK Hussey    A Symonds    5             753
## 24 MEK Hussey        B Lee   39             753
## 25 MEK Hussey   NW Bracken    3             753
## 26 MEK Hussey     JR Hopes   83             753
## 27 MEK Hussey     CL White  185             753
## 28 MEK Hussey    DA Warner   10             753
## 29 MEK Hussey      MS Wade   35             753
## 30 MEK Hussey    DJ Hussey   10             753
## 31 MEK Hussey   PJ Forrest   59             753
## 32 MEK Hussey     AC Voges   59             753
## 33 MEK Hussey MC Henriques   11             753
## 34  GJ Bailey    SR Watson   79             610
## 35  GJ Bailey    BJ Haddin    7             610
## 36  GJ Bailey            4    0             610
## 37  GJ Bailey    DA Warner    6             610
## 38  GJ Bailey     AJ Finch   22             610
## 39  GJ Bailey    SPD Smith  149             610
## 40  GJ Bailey   GJ Maxwell  133             610

11. Partnership runs against opposition (all ODI matches)

The chart below gives the overall partnership. It is graphical representation of the chart above.

batsmanPartnershipOppnChart(allMatches,"India")

partnershipOppnChart,-1

batsmanPartnershipOppnChart(allMatches,"Australia")

partnershipOppnChart,-2

12. Batsmen vs Bowlers against opposition (all ODI matches)

The chart below gives how the batsmen fared against the bowlers of the opposition.)

batsmanVsBowlersOppn(allMatches,"India")

batsmenVsBowlers,-1

batsmanVsBowlersOppn(allMatches,"Australia"

bowlersVsBatsmen,-2

13. Team batting details opposition (all ODI matches)

The table below gives the total runs scores by each batsman and is dsiplayed in descending order. Dhoni, Rohit Sharma and Tendulkar are the top 3 for India and Ponting, Hussey and Bailey lead for Australia

teamBattingDetailsOppn(allMatches,"India")
## Total= 8313
## Source: local data frame [44 x 5]
## 
##         batsman  runs fours sixes ballsPlayed
##          (fctr) (dbl) (int) (int)       (int)
## 1      MS Dhoni  1156    78    22        1406
## 2     RG Sharma   914    72    24        1015
## 3  SR Tendulkar   910   103     6        1157
## 4       V Kohli   902    87     6         961
## 5     G Gambhir   532    43     2         677
## 6  Yuvraj Singh   524    52    11         664
## 7      SK Raina   509    43    11         536
## 8      S Dhawan   471    55     6         470
## 9      V Sehwag   287    42     4         303
## 10   RV Uthappa   279    28     7         295
## ..          ...   ...   ...   ...         ...
teamBattingDetailsOppn(allMatches,"Australia")
## Total= 9993
## Source: local data frame [48 x 5]
## 
##       batsman  runs fours sixes ballsPlayed
##        (fctr) (dbl) (int) (int)       (int)
## 1  RT Ponting   876    86     8        1107
## 2  MEK Hussey   753    56     5         816
## 3   GJ Bailey   610    50    13         578
## 4   SR Watson   609    81    10         653
## 5   MJ Clarke   607    45     5         786
## 6   ML Hayden   573    72     8         660
## 7   A Symonds   536    43    15         543
## 8    AJ Finch   525    52     9         617
## 9   SPD Smith   467    44     7         431
## 10  DA Warner   391    40     6         385
## ..        ...   ...   ...   ...         ...

14. Bowler vs Batsman against opposition (all ODI matches)

The charts below give the performance of the bowlers against batsman

bowlersVsBatsmanOppn(allMatches,"India")

bowlersVsBatsmen,-1

bowlersVsBatsmanOppn(allMatches,"Australia")

bowlersVsBatsmen,-2

15. Bowling details against opposition (all ODI matches)

For matches between Australia and India the top 3 wicket takes for Australia are Mitchell Johnson, Brett Lee and JR Faulkner. For India it is Ishant Sharma, Harbhajan Singh and R A Jadeja.

teamBowlingDetailsOppn(allMatches,"India")
## Source: local data frame [39 x 5]
## 
##          bowler overs maidens  runs wickets
##          (fctr) (int)   (int) (dbl)   (dbl)
## 1    MG Johnson    40       0  1012      18
## 2         B Lee    21       1   667      15
## 3   JP Faulkner    33       0   598      13
## 4     SR Watson    24       0   532      12
## 5       GB Hogg    15       0   427      12
## 6      CJ McKay    17       0   403      12
## 7    NW Bracken    28       2   429      11
## 8      MA Starc    12       2   251      11
## 9      JR Hopes    18       0   346       8
## 10 DE Bollinger    11       4   174       8
## ..          ...   ...     ...   ...     ...
teamBowlingDetailsOppn(allMatches,"Australia")
## Source: local data frame [37 x 5]
## 
##             bowler overs maidens  runs wickets
##             (fctr) (int)   (int) (dbl)   (dbl)
## 1         I Sharma    44       1   739      20
## 2  Harbhajan Singh    40       0   926      15
## 3        RA Jadeja    39       0   867      14
## 4        IK Pathan    42       1   702      11
## 5         UT Yadav    37       2   606      10
## 6          P Kumar    27       0   501      10
## 7           Z Khan    33       1   500      10
## 8      S Sreesanth    34       0   454      10
## 9         R Ashwin    43       0   680       9
## 10   R Vinay Kumar    31       1   380       9
## ..             ...   ...     ...   ...     ...

16. Wicket kind against opposition (all ODI matches)

These charts give the wicket kind for each of the top 9 bowlers from each side.

teamBowlingWicketKindOppn(allMatches,"India")

wicketKindOppn-1

teamBowlingWicketKindOppn(allMatches,"Australia")

wicketKindOppn-2

17. Wicket runs against opposition (all ODI matches)

These given the runs conceded by the bowlers

teamBowlingWicketRunsOppn(allMatches,"India")

wicketRunsOppn-1

teamBowlingWicketRunsOppn(allMatches,"Australia")

wicketRunsOppn-2

18. Wickets against opposition (all ODI matches)

The charts below depict the wickets taken by each bowler. If you notice Mitchel Johnson has the most wickets.

teamBowlingWicketsOppn(allMatches,"India")

wicketOppn,-1

teamBowlingWicketsOppn(allMatches,"Australia")

wicketOppn,-2

Conclusion :

Some key findings

In the ODI confrontations between Australia and India the top 3 batsmen of India are

  1. Mahendra Dhoni 2.Rohit Sharma
  2. Sachin Tendulkar.

The best bowlers for India are

  1. Ishant Sharma
  2. Harbhajan Singh
  3. R A Jadeja

For the Australian side the top 3 batsmen are

  1. R A Ponting
  2. M Hussey
  3. G J Bailey

The top 3 bowlers are

1. Mitchell Johnson
2. Brett Lee
3. J P Faulkner

Note: This is the first part of my yorkr package. I will be adding more functions in the weeks to come. Clearly the data from Cricsheet is more granular and allows for more detailed analyses. I should have the next set of functions soon.

(Take a look at The making of cricket package yorkr – Part 2)

Watch this space!!!

Also see

  1. Cricket analytics with cricketr
  2. Introducing cricketr! : An R package to analyze performances of cricketers
  3. Sixer – R package cricketr’s new Shiny avatar
  4. Informed choices through Machine Learning – Analyzing Kohli, Tendulkar and Dravid

You may also like

  1. Natural language processing: What would Shakespeare say?
  2. Revisiting crimes against women in India
  3. Literacy in India – A deepR dive
  4. TWS-4: Gossip protocol: Epidemics and rumors to the rescue
  5. Singularity
  6. Simulating an Edge shape in Android
  7. Programming Zen and now – Sime essential tips
  8. Rock N’ Roll with Bluemix, Cloudant & NodeExpress
  9. Architecting a cloud based IP Multimedia System (IMS)

cricketr plays the ODIs!


Published in R bloggers: cricketr plays the ODIs

Introduction

In this post my package ‘cricketr’ takes a swing at One Day Internationals(ODIs). Like test batsman who adapt to ODIs with some innovative strokes, the cricketr package has some additional functions and some modified functions to handle the high strike and economy rates in ODIs. As before I have chosen my top 4 ODI batsmen and top 4 ODI bowlers.

Unititled2

If you are passionate about cricket, and love analyzing cricket performances, then check out my 2 racy books on cricket! In my books, I perform detailed yet compact analysis of performances of both batsmen, bowlers besides evaluating team & match performances in Tests , ODIs, T20s & IPL. You can buy my books on cricket from Amazon at $12.99 for the paperback and $4.99/$6.99 respectively for the kindle versions. The books can be accessed at Cricket analytics with cricketr  and Beaten by sheer pace-Cricket analytics with yorkr  A must read for any cricket lover! Check it out!!

1

d $4.99/Rs 320 and $6.99/Rs448 respectively

Important note: Do check out the python avatar of cricketr, ‘cricpy’ in my post ‘Introducing cricpy:A python package to analyze performances of cricketers

Do check out my interactive Shiny app implementation using the cricketr package – Sixer – R package cricketr’s new Shiny avatar

You can also read this post at Rpubs as odi-cricketr. Dowload this report as a PDF file from odi-cricketr.pdf

Note: If you would like to do a similar analysis for a different set of batsman and bowlers, you can clone/download my skeleton cricketr template from Github (which is the R Markdown file I have used for the analysis below). You will only need to make appropriate changes for the players you are interested in. Just a familiarity with R and R Markdown only is needed.
Batsmen

  1. Virendar Sehwag (Ind)
  2. AB Devilliers (SA)
  3. Chris Gayle (WI)
  4. Glenn Maxwell (Aus)

Bowlers

  1. Mitchell Johnson (Aus)
  2. Lasith Malinga (SL)
  3. Dale Steyn (SA)
  4. Tim Southee (NZ)

I have sprinkled the plots with a few of my comments. Feel free to draw your conclusions! The analysis is included below

The profile for Virender Sehwag is 35263. This can be used to get the ODI data for Sehwag. For a batsman the type should be “batting” and for a bowler the type should be “bowling” and the function is getPlayerDataOD()

The package can be installed directly from CRAN

if (!require("cricketr")){ 
    install.packages("cricketr",lib = "c:/test") 
} 
library(cricketr)

or from Github

library(devtools)
install_github("tvganesh/cricketr")
library(cricketr)

The One day data for a particular player can be obtained with the getPlayerDataOD() function. To do you will need to go to ESPN CricInfo Player and type in the name of the player for e.g Virendar Sehwag, etc. This will bring up a page which have the profile number for the player e.g. for Virendar Sehwag this would be http://www.espncricinfo.com/india/content/player/35263.html. Hence, Sehwag’s profile is 35263. This can be used to get the data for Virat Sehwag as shown below

sehwag <- getPlayerDataOD(35263,dir="..",file="sehwag.csv",type="batting")

Analyses of Batsmen

The following plots gives the analysis of the 4 ODI batsmen

  1. Virendar Sehwag (Ind) – Innings – 245, Runs = 8586, Average=35.05, Strike Rate= 104.33
  2. AB Devilliers (SA) – Innings – 179, Runs= 7941, Average=53.65, Strike Rate= 99.12
  3. Chris Gayle (WI) – Innings – 264, Runs= 9221, Average=37.65, Strike Rate= 85.11
  4. Glenn Maxwell (Aus) – Innings – 45, Runs= 1367, Average=35.02, Strike Rate= 126.69

Plot of 4s, 6s and the scoring rate in ODIs

The 3 charts below give the number of

  1. 4s vs Runs scored
  2. 6s vs Runs scored
  3. Balls faced vs Runs scored

A regression line is fitted in each of these plots for each of the ODI batsmen A. Virender Sehwag

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsman4s("./sehwag.csv","Sehwag")
batsman6s("./sehwag.csv","Sehwag")
batsmanScoringRateODTT("./sehwag.csv","Sehwag")

sehwag-4s6sSR-1

dev.off()
## null device 
##           1

B. AB Devilliers

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsman4s("./devilliers.csv","Devillier")
batsman6s("./devilliers.csv","Devillier")
batsmanScoringRateODTT("./devilliers.csv","Devillier")

devillier-4s6SR-1

dev.off()
## null device 
##           1

C. Chris Gayle

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsman4s("./gayle.csv","Gayle")
batsman6s("./gayle.csv","Gayle")
batsmanScoringRateODTT("./gayle.csv","Gayle")

gayle-4s6sSR-1

dev.off()
## null device 
##           1

D. Glenn Maxwell

par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsman4s("./maxwell.csv","Maxwell")
batsman6s("./maxwell.csv","Maxwell")
batsmanScoringRateODTT("./maxwell.csv","Maxwell")

maxwell-4s6sout-1

dev.off()
## null device 
##           1

Relative Mean Strike Rate

In this first plot I plot the Mean Strike Rate of the batsmen. It can be seen that Maxwell has a awesome strike rate in ODIs. However we need to keep in mind that Maxwell has relatively much fewer (only 45 innings) innings. He is followed by Sehwag who(most innings- 245) also has an excellent strike rate till 100 runs and then we have Devilliers who roars ahead. This is also seen in the overall strike rate in above

par(mar=c(4,4,2,2))
frames <- list("./sehwag.csv","./devilliers.csv","gayle.csv","maxwell.csv")
names <- list("Sehwag","Devilliers","Gayle","Maxwell")
relativeBatsmanSRODTT(frames,names)

plot-1-1

Relative Runs Frequency Percentage

Sehwag leads in the percentage of runs in 10 run ranges upto 50 runs. Maxwell and Devilliers lead in 55-66 & 66-85 respectively.

frames <- list("./sehwag.csv","./devilliers.csv","gayle.csv","maxwell.csv")
names <- list("Sehwag","Devilliers","Gayle","Maxwell")
relativeRunsFreqPerfODTT(frames,names)

plot-2-1

Percentage of 4s,6s in the runs scored

The plot below shows the percentage of runs made by the batsmen by ways of 1s,2s,3s, 4s and 6s. It can be seen that Sehwag has the higheest percent of 4s (33.36%) in his overall runs in ODIs. Maxwell has the highest percentage of 6s (13.36%) in his ODI career. If we take the overall 4s+6s then Sehwag leads with (33.36 +5.95 = 39.31%),followed by Gayle (27.80+10.15=37.95%)

Percent 4’s,6’s in total runs scored

The plot below shows the contrib

frames <- list("./sehwag.csv","./devilliers.csv","gayle.csv","maxwell.csv")
names <- list("Sehwag","Devilliers","Gayle","Maxwell")
runs4s6s <-batsman4s6s(frames,names)

plot-46s-1

print(runs4s6s)
##                Sehwag Devilliers Gayle Maxwell
## Runs(1s,2s,3s)  60.69      67.39 62.05   62.11
## 4s              33.36      24.28 27.80   24.53
## 6s               5.95       8.32 10.15   13.36
 

Runs forecast

The forecast for the batsman is shown below.

par(mfrow=c(2,2))
par(mar=c(4,4,2,2))
batsmanPerfForecast("./sehwag.csv","Sehwag")
batsmanPerfForecast("./devilliers.csv","Devilliers")
batsmanPerfForecast("./gayle.csv","Gayle")
batsmanPerfForecast("./maxwell.csv","Maxwell")

swcr-perf-1

dev.off()
## null device 
##           1

3D plot of Runs vs Balls Faced and Minutes at Crease

The plot is a scatter plot of Runs vs Balls faced and Minutes at Crease. A prediction plane is fitted

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
battingPerf3d("./sehwag.csv","V Sehwag")
battingPerf3d("./devilliers.csv","AB Devilliers")

plot-3-1

dev.off()
## null device 
##           1
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
battingPerf3d("./gayle.csv","C Gayle")
battingPerf3d("./maxwell.csv","G Maxwell")

plot-4-1

dev.off()
## null device 
##           1

Predicting Runs given Balls Faced and Minutes at Crease

A multi-variate regression plane is fitted between Runs and Balls faced +Minutes at crease.

BF <- seq( 10, 200,length=10)
Mins <- seq(30,220,length=10)
newDF <- data.frame(BF,Mins)

sehwag <- batsmanRunsPredict("./sehwag.csv","Sehwag",newdataframe=newDF)
devilliers <- batsmanRunsPredict("./devilliers.csv","Devilliers",newdataframe=newDF)
gayle <- batsmanRunsPredict("./gayle.csv","Gayle",newdataframe=newDF)
maxwell <- batsmanRunsPredict("./maxwell.csv","Maxwell",newdataframe=newDF)

The fitted model is then used to predict the runs that the batsmen will score for a hypotheticial Balls faced and Minutes at crease. It can be seen that Maxwell sets a searing pace in the predicted runs for a given Balls Faced and Minutes at crease followed by Sehwag. But we have to keep in mind that Maxwell has only around 1/5th of the innings of Sehwag (45 to Sehwag’s 245 innings). They are followed by Devilliers and then finally Gayle

batsmen <-cbind(round(sehwag$Runs),round(devilliers$Runs),round(gayle$Runs),round(maxwell$Runs))
colnames(batsmen) <- c("Sehwag","Devilliers","Gayle","Maxwell")
newDF <- data.frame(round(newDF$BF),round(newDF$Mins))
colnames(newDF) <- c("BallsFaced","MinsAtCrease")
predictedRuns <- cbind(newDF,batsmen)
predictedRuns
##    BallsFaced MinsAtCrease Sehwag Devilliers Gayle Maxwell
## 1          10           30     11         12    11      18
## 2          31           51     33         32    28      43
## 3          52           72     55         52    46      67
## 4          73           93     77         71    63      92
## 5          94          114    100         91    81     117
## 6         116          136    122        111    98     141
## 7         137          157    144        130   116     166
## 8         158          178    167        150   133     191
## 9         179          199    189        170   151     215
## 10        200          220    211        190   168     240

Highest runs likelihood

The plots below the runs likelihood of batsman. This uses K-Means It can be seen that Devilliers has almost 27.75% likelihood to make around 90+ runs. Gayle and Sehwag have 34% to make 40+ runs. A. Virender Sehwag

A. Virender Sehwag

batsmanRunsLikelihood("./sehwag.csv","Sehwag")

smith-1

## Summary of  Sehwag 's runs scoring likelihood
## **************************************************
## 
## There is a 35.22 % likelihood that Sehwag  will make  46 Runs in  44 balls over 67  Minutes 
## There is a 9.43 % likelihood that Sehwag  will make  119 Runs in  106 balls over  158  Minutes 
## There is a 55.35 % likelihood that Sehwag  will make  12 Runs in  13 balls over 18  Minutes

B. AB Devilliers

batsmanRunsLikelihood("./devilliers.csv","Devilliers")

warner-1

## Summary of  Devilliers 's runs scoring likelihood
## **************************************************
## 
## There is a 30.65 % likelihood that Devilliers  will make  44 Runs in  43 balls over 60  Minutes 
## There is a 29.84 % likelihood that Devilliers  will make  91 Runs in  88 balls over  124  Minutes 
## There is a 39.52 % likelihood that Devilliers  will make  11 Runs in  15 balls over 21  Minutes

C. Chris Gayle

batsmanRunsLikelihood("./gayle.csv","Gayle")

cook,cache-TRUE-1

## Summary of  Gayle 's runs scoring likelihood
## **************************************************
## 
## There is a 32.69 % likelihood that Gayle  will make  47 Runs in  51 balls over 72  Minutes 
## There is a 54.49 % likelihood that Gayle  will make  10 Runs in  15 balls over  20  Minutes 
## There is a 12.82 % likelihood that Gayle  will make  109 Runs in  119 balls over 172  Minutes

D. Glenn Maxwell

batsmanRunsLikelihood("./maxwell.csv","Maxwell")

oot-1

## Summary of  Maxwell 's runs scoring likelihood
## **************************************************
## 
## There is a 34.38 % likelihood that Maxwell  will make  39 Runs in  29 balls over 35  Minutes 
## There is a 15.62 % likelihood that Maxwell  will make  89 Runs in  55 balls over  69  Minutes 
## There is a 50 % likelihood that Maxwell  will make  6 Runs in  7 balls over 9  Minutes

Average runs at ground and against opposition

A. Virender Sehwag

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
batsmanAvgRunsGround("./sehwag.csv","Sehwag")
batsmanAvgRunsOpposition("./sehwag.csv","Sehwag")

avgrg-1-1

dev.off()
## null device 
##           1

B. AB Devilliers

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
batsmanAvgRunsGround("./devilliers.csv","Devilliers")
batsmanAvgRunsOpposition("./devilliers.csv","Devilliers")

avgrg-2-1

dev.off()
## null device 
##           1

C. Chris Gayle

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
batsmanAvgRunsGround("./gayle.csv","Gayle")
batsmanAvgRunsOpposition("./gayle.csv","Gayle")

avgrg-3-1

dev.off()
## null device 
##           1

D. Glenn Maxwell

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
batsmanAvgRunsGround("./maxwell.csv","Maxwell")
batsmanAvgRunsOpposition("./maxwell.csv","Maxwell")

avgrg-4-1

dev.off()
## null device 
##           1

Moving Average of runs over career

The moving average for the 4 batsmen indicate the following

1. The moving average of Devilliers and Maxwell is on the way up.
2. Sehwag shows a slight downward trend from his 2nd peak in 2011
3. Gayle maintains a consistent 45 runs for the last few years

par(mfrow=c(2,2))
par(mar=c(4,4,2,2))
batsmanMovingAverage("./sehwag.csv","Sehwag")
batsmanMovingAverage("./devilliers.csv","Devilliers")
batsmanMovingAverage("./gayle.csv","Gayle")
batsmanMovingAverage("./maxwell.csv","Maxwell")

sdgm-ma-1

dev.off()
## null device 
##           1

Check batsmen in-form, out-of-form

  1. Maxwell, Devilliers, Sehwag are in-form. This is also evident from the moving average plot
  2. Gayle is out-of-form
checkBatsmanInForm("./sehwag.csv","Sehwag")
## *******************************************************************************************
## 
## Population size: 143  Mean of population: 33.76 
## Sample size: 16  Mean of sample: 37.44 SD of sample: 55.15 
## 
## Null hypothesis H0 : Sehwag 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : Sehwag 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "Sehwag 's Form Status: In-Form because the p value: 0.603525  is greater than alpha=  0.05"
## *******************************************************************************************
checkBatsmanInForm("./devilliers.csv","Devilliers")
## *******************************************************************************************
## 
## Population size: 111  Mean of population: 43.5 
## Sample size: 13  Mean of sample: 57.62 SD of sample: 40.69 
## 
## Null hypothesis H0 : Devilliers 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : Devilliers 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "Devilliers 's Form Status: In-Form because the p value: 0.883541  is greater than alpha=  0.05"
## *******************************************************************************************
checkBatsmanInForm("./gayle.csv","Gayle")
## *******************************************************************************************
## 
## Population size: 140  Mean of population: 37.1 
## Sample size: 16  Mean of sample: 17.25 SD of sample: 20.25 
## 
## Null hypothesis H0 : Gayle 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : Gayle 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "Gayle 's Form Status: Out-of-Form because the p value: 0.000609  is less than alpha=  0.05"
## *******************************************************************************************
checkBatsmanInForm("./maxwell.csv","Maxwell")
## *******************************************************************************************
## 
## Population size: 28  Mean of population: 25.25 
## Sample size: 4  Mean of sample: 64.25 SD of sample: 36.97 
## 
## Null hypothesis H0 : Maxwell 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : Maxwell 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "Maxwell 's Form Status: In-Form because the p value: 0.948744  is greater than alpha=  0.05"
## *******************************************************************************************

Analysis of bowlers

  1. Mitchell Johnson (Aus) – Innings-150, Wickets – 239, Econ Rate : 4.83
  2. Lasith Malinga (SL)- Innings-182, Wickets – 287, Econ Rate : 5.26
  3. Dale Steyn (SA)- Innings-103, Wickets – 162, Econ Rate : 4.81
  4. Tim Southee (NZ)- Innings-96, Wickets – 135, Econ Rate : 5.33

Malinga has the highest number of innings and wickets followed closely by Mitchell. Steyn and Southee have relatively fewer innings.

To get the bowler’s data use

malinga <- getPlayerDataOD(49758,dir=".",file="malinga.csv",type="bowling")

Wicket Frequency percentage

This plot gives the percentage of wickets for each wickets (1,2,3…etc)

par(mfrow=c(1,4))
par(mar=c(4,4,2,2))
bowlerWktsFreqPercent("./mitchell.csv","J Mitchell")
bowlerWktsFreqPercent("./malinga.csv","Malinga")
bowlerWktsFreqPercent("./steyn.csv","Steyn")
bowlerWktsFreqPercent("./southee.csv","southee")

relBowlFP-1

dev.off()
## null device 
##           1

Wickets Runs plot

The plot below gives a boxplot of the runs ranges for each of the wickets taken by the bowlers. M Johnson and Steyn are more economical than Malinga and Southee corroborating the figures above

par(mfrow=c(1,4))
par(mar=c(4,4,2,2))

bowlerWktsRunsPlot("./mitchell.csv","J Mitchell")
bowlerWktsRunsPlot("./malinga.csv","Malinga")
bowlerWktsRunsPlot("./steyn.csv","Steyn")
bowlerWktsRunsPlot("./southee.csv","southee")

wktsrun-1

dev.off()
## null device 
##           1

Average wickets in different grounds and opposition

A. Mitchell Johnson

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerAvgWktsGround("./mitchell.csv","J Mitchell")
bowlerAvgWktsOpposition("./mitchell.csv","J Mitchell")

gr-1-1

dev.off()
## null device 
##           1

B. Lasith Malinga

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerAvgWktsGround("./malinga.csv","Malinga")
bowlerAvgWktsOpposition("./malinga.csv","Malinga")

gr-2-1

dev.off()
## null device 
##           1

C. Dale Steyn

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerAvgWktsGround("./steyn.csv","Steyn")
bowlerAvgWktsOpposition("./steyn.csv","Steyn")

gr-3-1

dev.off()
## null device 
##           1

D. Tim Southee

par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerAvgWktsGround("./southee.csv","southee")
bowlerAvgWktsOpposition("./southee.csv","southee")

avgrg-4-1

dev.off()
## null device 
##           1

Relative bowling performance

The plot below shows that Mitchell Johnson and Southee have more wickets in 3-4 wickets range while Steyn and Malinga in 1-2 wicket range

frames <- list("./mitchell.csv","./malinga.csv","steyn.csv","southee.csv")
names <- list("M Johnson","Malinga","Steyn","Southee")
relativeBowlingPerf(frames,names)

relBowlPerf-1

Relative Economy Rate against wickets taken

Steyn had the best economy rate followed by M Johnson. Malinga and Southee have a poorer economy rate

frames <- list("./mitchell.csv","./malinga.csv","steyn.csv","southee.csv")
names <- list("M Johnson","Malinga","Steyn","Southee")
relativeBowlingERODTT(frames,names)

relBowlER-1

Moving average of wickets over career

Johnson and Steyn career vs wicket graph is on the up-swing. Southee is maintaining a reasonable record while Malinga shows a decline in ODI performance

par(mfrow=c(2,2))
par(mar=c(4,4,2,2))
bowlerMovingAverage("./mitchell.csv","M Johnson")
bowlerMovingAverage("./malinga.csv","Malinga")
bowlerMovingAverage("./steyn.csv","Steyn")
bowlerMovingAverage("./southee.csv","Southee")

jmss-bowlma-1

dev.off()
## null device 
##           1

Wickets forecast

par(mfrow=c(2,2))
par(mar=c(4,4,2,2))
bowlerPerfForecast("./mitchell.csv","M Johnson")
bowlerPerfForecast("./malinga.csv","Malinga")
bowlerPerfForecast("./steyn.csv","Steyn")
bowlerPerfForecast("./southee.csv","southee")

jsba-pfcst-1

dev.off()
## null device 
##           1

Check bowler in-form, out-of-form

All the bowlers are shown to be still in-form

checkBowlerInForm("./mitchell.csv","J Mitchell")
## *******************************************************************************************
## 
## Population size: 135  Mean of population: 1.55 
## Sample size: 15  Mean of sample: 2 SD of sample: 1.07 
## 
## Null hypothesis H0 : J Mitchell 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : J Mitchell 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "J Mitchell 's Form Status: In-Form because the p value: 0.937917  is greater than alpha=  0.05"
## *******************************************************************************************
checkBowlerInForm("./malinga.csv","Malinga")
## *******************************************************************************************
## 
## Population size: 163  Mean of population: 1.58 
## Sample size: 19  Mean of sample: 1.58 SD of sample: 1.22 
## 
## Null hypothesis H0 : Malinga 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : Malinga 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "Malinga 's Form Status: In-Form because the p value: 0.5  is greater than alpha=  0.05"
## *******************************************************************************************
checkBowlerInForm("./steyn.csv","Steyn")
## *******************************************************************************************
## 
## Population size: 93  Mean of population: 1.59 
## Sample size: 11  Mean of sample: 1.45 SD of sample: 0.69 
## 
## Null hypothesis H0 : Steyn 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : Steyn 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "Steyn 's Form Status: In-Form because the p value: 0.257438  is greater than alpha=  0.05"
## *******************************************************************************************
checkBowlerInForm("./southee.csv","southee")
## *******************************************************************************************
## 
## Population size: 86  Mean of population: 1.48 
## Sample size: 10  Mean of sample: 0.8 SD of sample: 1.14 
## 
## Null hypothesis H0 : southee 's sample average is within 95% confidence interval 
##         of population average
## Alternative hypothesis Ha : southee 's sample average is below the 95% confidence
##         interval of population average
## 
## [1] "southee 's Form Status: Out-of-Form because the p value: 0.044302  is less than alpha=  0.05"
## *******************************************************************************************

***************

Key findings

Here are some key conclusions ODI batsmen

  1. AB Devilliers has high frequency of runs in the 60-120 range and the highest average
  2. Sehwag has the most number of innings and good strike rate
  3. Maxwell has the best strike rate but it should be kept in mind that he has 1/5 of the innings of Sehwag. We need to see how he progress further
  4. Sehwag has the highest percentage of 4s in the runs scored, while Maxwell has the most 6s
  5. For a hypothetical Balls Faced and Minutes at creases Maxwell will score the most runs followed by Sehwag
  6. The moving average of indicates that the best is yet to come for Devilliers and Maxwell. Sehwag has a few more years in him while Gayle shows a decline in ODI performance and an out of form is indicated.

ODI bowlers

  1. Malinga has the highest played the highest innings and also has the highest wickets though he has poor economy rate
  2. M Johnson is the most effective in the 3-4 wicket range followed by Southee
  3. M Johnson and Steyn has the best overall economy rate followed by Malinga and Steyn 4 M Johnson and Steyn’s career is on the up-swing,Southee maintains a steady consistent performance, while Malinga shows a downward trend

Hasta la vista! I’ll be back!
Watch this space!

Also see my other posts in R

  1. Introducing cricketr! : An R package to analyze performances of cricketers
  2. cricketr digs the Ashes!
  3. A peek into literacy in India: Statistical Learning with R
  4. A crime map of India in R – Crimes against women
  5. Analyzing cricket’s batting legends – Through the mirage with R
  6. Mirror, mirror . the best batsman of them all?

You may also like

  1. A closer look at “Robot Horse on a Trot” in Android
  2. What’s up Watson? Using IBM Watson’s QAAPI with Bluemix, NodeExpress – Part 1
  3. Bend it like Bluemix, MongoDB with autoscaling – Part 2
  4. Informed choices through Machine Learning : Analyzing Kohli, Tendulkar and Dravid
  5. TWS-4: Gossip protocol: Epidemics and rumors to the rescue
  6. Deblurring with OpenCV:Weiner filter reloadedhttp://www.r-bloggers.com/cricketr-plays-the-odis/