Category Archives: Soccer er Football

Usually related to some EPL statistics. Often for more detailed analysis than provided by main site

Craig Bellamy – quite dplyr

This weekend brought a couple of firsts in Cardiff’s winner against Norwich

After a wretched time at Manchester United, Wilfried Zaha recorded his first Premiership assist, whilst, more interestingly, Craig Bellamy became the first player in history to score for seven different Premier League clubs

To celebrate, I thought it was worth taking a quick data dip with the new dplyr package for R, a souped up version of plyr for data.frames.

A main advantage of dplyr is that is way faster than plyr but it also offers the option to chain operations, utilizing %.%. This encourages the good discipline of planning logically ahead of coding, something I am not naturally inclined to, and should make the code more readable

I have loaded into R a largish, (270,000 row) data.frame, playerGames, of players’ appearances in the English Premier League

My target is a graph showing for each the players who have scored for the most different clubs how many games it has taken them to score their first goal for each of these teams.

The process uses several of the dplyr functions. Firstly, I want to tidy up the data, reduce the data to variables of interest and then add some required columns. I then want to find out who these itinerant players are and ascertain when they got off the mark with each club Finally I will knock out a ggplot

?View Code RSPLUS
# load packages - make sure plyr is not running as this may cause issues
library(dplyr)
library(ggplot2)
library(scales)
 
# convert the data.frame to a tbl_df: 
#this is a wrapper around a data frame that won't accidentally print a lot of data# to screen
playerGames_df <- tbl_df(playerGames) 
 
# start the munging
allGames <-playerGames_df %.%
 
# omit rows which exclude players not appearing in game
filter(playerID!="OWNGOAL"&(START+subOn)>0) %.%
# rename columns to standard format
?View Code RSPLUS
# set to required columns
select(playerID,teamID,goals,gameDate) %.%
 
# sort on game date
arrange(gameDate) %.%
 
# group each player by team
group_by(playerID,teamID) %.%
 
# so that we can set a game order and cumulate goals for each #player/team
mutate(
game = 1:NROW(Goals),
cumGoals = cumsum(Goals)
)
 
# example row
tail(allGames,1)
       playerID teamID goals   gameDate game cumGoals
222249    OSCAR    CHL     0 2014-02-03   56       10
 
# now we need to find these players
topPlayers0) %.%
 
# and sum the number of clubs by player
group_by(playerID) %.%
summarise(teams=n()) %.%
 
# now just show Bellamy and the others who were also on six teams
filter(teams==max(teams)|teams==max(teams)-1))$playerID
 
topPlayers
#[1] "BARMBYN" "COLEA1" "BENTD" "BELLAMC" "KEANER2" #"CROUCHP" "ANELKAN" "FERDINL"
 
# now for these players calculate the debut goal data
firstGoal0) %.%
 
# and then select first row for each player/club
group_by(playerID,teamID) %.%
summarise(first=min(game))
 
head(firstGoal,1)
#  playerID teamID first
#1    BENTD    ASV     1

 

At this point, my computer, WordPress and the coding wrapper decided to screw up. The rest of the code just replaces playerID with real names and uses ggplot to create a chart

bellamy

A few football points to note

  • Bellamy took 13 appearances to score his first Premiership goal fro Cardiff, although he had scored plenty for them in the division below. This is the longest due in part to many sub appearances, playing with a weak team and old age
  • Darren Bent  scored on his debut on four occasions. Anelka never managed it before game 4
  • Out of roughly 4,000 players who have appeared in the Premiership, both with surname, Bent, figure. One of the two A Coles and one of the two R Keanes also appear in the list of nine
  • Liverpool and Tottenham figure the most with five stops. Crouch, Keane and Bellamy have each appeared for both clubs
  • All five Spurs players scored in their first four appearances. By contrast, none of the Liverpool five got off the mark before game 7 (Bellamy) with all the other is the 10-12 range

Shiny App for Polling Forums

In 2010, Crystal Palace FC were in administration and had 10 points deducted during the year. They only survived in the Championship on the last day of the season

A year ago, they started the league with three consecutive losses and were relegation favourites.

Fast forward 12 months and they are again strong tips for the drop but this time from the Premier League. Last weekend, a player who was playing non-league football not so long ago bagged the winner for their first three points of the new season

It has been quite a ride for their supporters, including myself, and has led to a significant increase in volume on the forums the supporters website, holmesdale.net

As a Shiny developer, I thought it would be useful to have a web app which regularly polls the forums, thus saving on many link clicks to find the latest coverage – which admittedly is the usual mixture of interesting comment, lame banter and swear words

For me, the most interesting aspects as far as development is concerned are

  • Application of ‘invalidateLater’ which reactivates the function that scrapes the web pages on a proscribed time basis e.g 30 minutes, alterable by the user
  • Enactment of the progress bar, a new feature of the shiny-incubator package
  • Use of the dataTables component of the rCharts package, which allows sorting and searches

I will probably add a couple of extra features but a working version can be found here

I would definitely be interested in doing similar work for items of more general usage
so any suggestions are very welcome

Rooney on the wane?

British journalists have been waiting a dozen years to be able to use the above pun and there have recently been a number of comments on Rooney’s perceived decline

A recent column by Martin Samuel in in the Daily Mail quotes several random stats disputing this but then goes on to argue that
“Yet by all purely intuitive reckonings, something is not right.”

That may well be so, but let us look a bit more closely at the data. Here is a graph showing the creative contribution in terms of goals and assists that Rooney has made by EPL game
rooneyPoints

The first thing to note is how consistent he has been. Since he turned 20 he has pretty much averaged a point(goal+assist) per game each season and adapted to being either more of a provider – to the likes of Ronaldo or van Persie – or striker e.g 27 goals last year

This season, although his appearances are down, has been no different with 23 points in 23 games. And there is precious little suggestion from the figures that he was much better in the earlier going this year. He has snatched 10 goals in his past 13 appearances (in one of which he was subbed after 8 minutes), including only goals in two 1-0 victories. And this at a time when van Persie has struggled to find the net

So, although the argument fits the narrative that the aggressive character is burnt out after starting so young, I’m not buying it yet.
It seems to me this is to some extent journalists supporting the Man U party line, which is still irritated at being out-smarted by Rooney and his agent on his last contract and are looking to a lower pay-packet if his demands for a new one are true

Rooney as Fall Guy

The press is awash with rumours that Wayne Rooney and his massive salary are out of Old Trafford this summer, provided there are takers at 20 million
His failure to make the starting lineup for the game against Real Madrid and whispers of poor training practices and conditioning only fuel the speculation

However, I am wondering if he is taking the heat for a poor decision not to start him over Danny Welbeck, a player who has just one goal in twenty league appearances this season and who missed a couple of opportunities in the game which would have put United into the lead.

Rooney’s stats on the face of it show no decline in ability. He has been very consistent over the years, more of a provider with Ronaldo or van Persie in the team but stepping up his goalscoring in their absence. Indeed, taking into account the time he has spent on the pitch, this season he has been as good as ever as an attacking force in the league
Apologies for graph but red is goals, assists is green and y axis is per game-equivalent

Over his career, Rooney matches up very well with the all-time EPL greats

Of the leading current players, he is by far the youngest. Already, sixth on the all-time EPL scoring list and ninth in assists, he has every chance to become the most prolific player in EPL history by the end of his career. However, there are some warning signs. Although he has eleven leaue goals this season, only two have been winners compared with nine last year and a best of ten two years prior. In addition, although, at 27, he should still be in his prime his first appearance was more than a decade ago and wear and tear do appear to have affected his physical abilities.

So where might he end up? He doesn’t strike me as an obvious candidate to move abroad. Spurs might be the best bet as they have question marks over several front players in Bale(potential massive transfer), Defoe(age/injuries) an Adebayor(poor value for money)