Introducing the goalmodel R package

I have written a lot about different models for forecasting football results, and provided a lot of R code along the way. Especially popular are my posts about the Dixon-Coles model, where people still post comments, four years since I first wrote them. Because of the interest in them, and the interest in some of the other models I have written about, I decided to tidy up my code and functions a bit, and make an R package out of it. The result is the goalmodel R package. The package let you fit the ordinary Poisson model, which was one of the first models I wrote about, the Dixon-Coles model, The Negative-Binomial model, and you can also use the adjustment I wrote about in my previous update.

The package contains a function to fit the different models, and you can even combine different aspects of the different models into the same model. You can for instance use the Dixon-Coles adjustment together with a negative binomial model. There is also a range of different methods for making prediction of different kinds, such as expected goals and over/under.

The package can be downloaded from github. It is still just the initial version, so there are probably some bugs and stuff to be sorted out, but go and try it out and let me know what you think!

4 thoughts on “Introducing the goalmodel R package

  1. Thanks for making this work public. I’m new to both sports betting and R, but I did science in uni back in the day, so I will knock the rust off and try my hand at modeling. 🙂

    Would the package be useful for predicting other sports like hockey and basket?

  2. Playing around with the goalmodel package for English championship. Can we make a weighted Rue Salvesen model with weights from the weights_dc function, like this?

    #
    # Weighted Rue-Salvesen model (rsw)
    #
    my_weights <- weights_dc(championship$Date, xi=0.0019)
    length(my_weights)
    plot(championship$Date, my_weights)

    gm_res_rsw <- goalmodel(goals1 = championship$hgoal, goals2 = championship$vgoal,
    team1 = championship$home, team2=championship$visitor,
    rs=TRUE, weights = my_weights)

    summary(gm_res_rsw)

    • Yes, you can use weights for all types of models. However, read my blog post about the Rue-Salvesen adjustment, and how it might not be a good idea to actually fit the model with the adjustment. Also take a look at the github page about how you can set the RS adjustment parameter after you have fit the default (or Dixon-Coles) model.

    • Thanks! I have now read up on parameter setting and tested it.

      Forgive me for being an R newb, but how would you filter for matches between two dates?

      I take it that we load up multiple seasons like this (let’s do 2011-2015):

      # Load data from English Premier League, 2011/2012 to
      # 2015/2016 season.

      england %>%
      filter(Season %in% c(2011):c(2015),
      tier==c(1)) %>%
      mutate(Date = as.Date(Date)) -> england_2011_2015

      Let’s say we want to predict a match within this dataset, using all matches played up to that point. How do we specify a sub-dataset between two dates? Specifically, between the 1st game of 2011/2012 season and some date before the end of the 2015/2016 season?

      Thanks in advance and sorry for the nag. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *