goalmodel: Fitting models for goals

View source: R/goalmodel_fit.R

goalmodelR Documentation

Fitting models for goals

Description

goalmodel is used to fit models of goals scored in sports competitions. At a minimum this function estimates 'attack' and 'defence' ratings for all teams, but other covariates can be included, as well as other adjustments. The underlying statistical model can be either a Poisson, Negative Binomial, or Gaussian model.

Usage

goalmodel(
  goals1,
  goals2,
  team1,
  team2,
  x1 = NULL,
  x2 = NULL,
  hfa = TRUE,
  dc = FALSE,
  rs = FALSE,
  hurdle = FALSE,
  fixed_params = NULL,
  weights = NULL,
  model = "poisson",
  optim_method = "BFGS"
)

Arguments

goals1

Numeric, non-negative integer. The number of goals scored by team 1.

goals2

Numeric, non-negative integer. The number of goals scored by team 2.

team1

Vector of team names.

team2

Vector of team names.

x1

Matrix of additional covariates associated with team 1.

x2

Matrix of additional covariates associated with team 2.

hfa

Logical (TRUE by default). Include a (home field) advantage for team 1.

dc

Logical (FALSE by default). If TRUE an adjustment for low scoring goals is included in the model.

rs

Logical (FALSE by default). If TRUE an adjustment for teams to over and under estimate the opponent.

hurdle

Logical (FALSE by default). If TRUE, 0-0 results will be modeled using a separate parameter (a hurdle model).

fixed_params

A list with parameters that should be kept constant while the other parameters are estimated from data.

weights

Numeric vector of weigths that determine the influence of each match on the final parameter estimates.

model

String indicating whether the goals follow a 'poisson' model (default), a Negative Binomial ('negbin'), Conway-Maxwell-Poisson ('cmp') or a Gaussian ('gaussian') model.

optim_method

String indicating which optimization method to use in case the model can't be fitted with gml.fit(). See optim for more details.

Details

Fixed parameters must be given as a list that is similar as the one returned from this function. See the 'value' section.

Value

A list of class 'goalmodel'. The list contains the following components:

  • parameters - A list of parameters.

  • loglikelihood - The value of the log-likelihood at the maximum.

  • npar_est - Number of parameters that has been estimated.

  • npar_fixed - Number of parameter that was fixed to a constant value during model fitting.

  • aic - Akaike's Information Criterium.

  • r_squared - A pseudo r-squared; The proportion of variability in the observed goals that the model explains.

  • all_teams - A character vector with the names of all the teams in the data.

  • ngames - Number of games in the data.

  • est_time - The time it took to fit the model.

  • model = A string indicating whether a Poisson or Negative Binomial model was used.

  • fixed_params - A list with the parameters that was kept constant during model fitting.

  • converged - Logical indicating if the model fitting converged.

  • maxgoal - The greatest number of goals seen in the data. Used by the prediction functions.

  • fitter - String indicating wether the model was fitted with the built-in glm.fit() function.

The parameters list contain both the fixed and estimated parameters. It contains the following compnents:

  • attack - A named mumeric of the attack parameters.

  • defense - A named mumeric of the attack parameters.

  • intercept - A length 1 numeric with the intercept.

The following parameter components are optional, and depends on what kind of model is fitted.

  • hfa - If hfa=TRUE, an unnamd length 1 numeric with the home field advantage.

  • rho - If dc=TRUE, an unnamd length 1 numeric with the Dixon-Coles adjustment.

  • gamma - If rs=TRUE, an unnamd length 1 numeric with the Rue-Salvesen adjustment.

  • beta - If additional covarites are used, this is a named mumeric of the regression coefficients.

  • dispersion - The dispersion parameter in the Negative Binomial model or the Conway-Maxwell-Poisson model.

  • sigma - The standard deviation in a Gaussian model.

  • hurdle - The hurdle parameter.

Examples


# See the vignette for examples.


opisthokonta/goalmodel documentation built on April 3, 2024, 1:32 a.m.