足球成绩模型

时间:2014-10-31 15:43:49

标签: r winbugs jags

我有附加的模型(由RasmusBååth提供),我正在努力改进以增加我对MCMC和R的理解。美联储进入该模型的是足球比赛,每一行包含(HomeTeam,AwayTeam,Season,HomeGoals, AwayGoals,MatchResult,HomeForm,AwayForm)。该模型用于预测两个团队之间的游戏中的足球结果,其中HomeGoals和AwayGoals被建模为泊松分布。我过去几天试图完成的是使用关于模型中团队当前形式的数据,但我想不出实现它的方法。我希望能提出一些建议。

一些澄清:

  • 赛季是比赛的赛季
  • 如果客场球队获胜,则MatchResult为-1,如果平局,则为0,如果主队获胜,则为1。
  • HomeForm和AwayForm是量化当前形式的值 主场和客场球队分别(-1比1,滚动平均比赛结果 球队最后一场比赛有五个窗口,如果球队在客场边打球,则会出现负面比赛结果。)
  • 文本中的列在传递给模型(因子)之前会转换为整数。

谢谢!

MODEL:

model {
  for(game_i in 1:n_games) {
    HomeGoals[game_i] ~ dpois(lambda_home[Season[game_i], HomeTeam[game_i], AwayTeam[game_i]])
    AwayGoals[game_i] ~ dpois(lambda_away[Season[game_i], HomeTeam[game_i], AwayTeam[game_i]])
  }

  for(season_i in 1:n_seasons) {
    for(home_i in 1:n_teams) {
      for(away_i in 1:n_teams) {
        lambda_home[season_i, home_i, away_i] <- exp(home_baseline[season_i] + skill[season_i, home_i] - skill[season_i, away_i])
        lambda_away[season_i, home_i, away_i] <- exp(away_baseline[season_i] + skill[season_i, away_i] - skill[season_i, home_i])
      }
    }
  }

  skill[1, 1] <- 0 
  for(j in 2:n_teams) {
    skill[1, j] ~ dnorm(group_skill, group_tau)
  }

  group_skill ~ dnorm(0, 0.0625)
  group_tau <- 1/pow(group_sigma, 2)
  group_sigma ~ dunif(0, 3)

  home_baseline[1] ~ dnorm(0, 0.0625)
  away_baseline[1] ~ dnorm(0, 0.0625)

  for(season_i in 2:n_seasons) {
    skill[season_i, 1] <- 0 
    for(j in 2:n_teams) {
      skill[season_i, j] ~ dnorm(skill[season_i - 1, j], season_tau)
    }
    home_baseline[season_i] ~ dnorm(home_baseline[season_i - 1], season_tau)
    away_baseline[season_i] ~ dnorm(away_baseline[season_i - 1], season_tau)
  }

  season_tau <- 1/pow(season_sigma, 2) 
  season_sigma ~ dunif(0, 3) 
}

DATA(部分内容):

No. HomeTeam           AwayTeam       Season HomeGoals AwayGoals HomeForm  AwayForm MatchResult
41  Betis              Real Madrid    0809   1         2         -0.6      0.6      -1
42  Espanol            Barcelona      0809   1         2         0.0       0.4      -1
43  Sp Gijon           Villarreal     0809   0         1         -1.0      0.8      -1
44  Almeria            Recreativo     0809   1         0         0.4       -0.4     1
45  Ath Bilbao         Getafe         0809   0         1         -0.2      0.2      -1
46  Ath Madrid         Sevilla        0809   0         1         0.2       0.6      -1
47  Malaga             Valladolid     0809   2         1         -0.4      -0.2     1
48  Numancia           Osasuna        0809   0         0         -0.4      -0.2     0
49  Santander          Mallorca       0809   1         2         -0.6      0.2      -1
50  Valencia           La Coruna      0809   4         2         0.8       -0.2     1
51  Barcelona          Ath Madrid     0809   6         1         0.8      -0.2      1
52  Villarreal         Betis          0809   2         1         1.0      -0.6      1

0 个答案:

没有答案