Re: John t whelan ranking simulator

KRACH code in MATA: [wvec is a 59x1 matrix of wins+.5ties for each team;games is a 59x59 matrix of games played]

krach = 100*gamma/max(gamma)

do {

lastkrach = krach

krach = wvec :/ rowsum(games :/ ((krach :* J(59,59,1)) :+ krach'))

} while (mreldif(krach, lastkrach)>1e-10)

Here's KRACH adjusted for ties and home ice in STATA:

capture program drop bttieh

program define bttieh

args lnf g1 g2 theta hf

tempvar num denom

quietly gen double `denom' = ln(exp(`g1'+`hf') + exp(`g2') + exp(`theta')*((exp(`g1'+`hf')*exp(`g2'))^(.5)))

quietly gen double `num' = `g1'+`hf' if $ML_y1==1

quietly replace `num' = `g2' if $ML_y1==0

quietly replace `num' = (`theta' + .5*(`g1'+`hf'+`g2')) if $ML_y1==.5

quietly replace `lnf' = `num' - `denom'

end

forvalues i=1/59 {

constraint define `i' _b[home:`i'.teamid] = _b[away:`i'.oppid]

}

ml model lf bttieh (home: twin = i.teamid,nocons) (away:i.oppid,nocons) (theta: ) (hf: home,nocons),constraints(2-59)

ml max,nocnsr

matrix adjkrach = e(b)

teamid and oppid are index variables for the home team and road team (arbitrary in the case of neutral ice), home is an indicator variable for the home team not on neutral ice, twin is a vector giving the result {0,.5,1} for the team denoted by teamid

Not nearly as neat, huh?

KRACH code in MATA: [wvec is a 59x1 matrix of wins+.5ties for each team;games is a 59x59 matrix of games played]

krach = 100*gamma/max(gamma)

do {

lastkrach = krach

krach = wvec :/ rowsum(games :/ ((krach :* J(59,59,1)) :+ krach'))

} while (mreldif(krach, lastkrach)>1e-10)

Here's KRACH adjusted for ties and home ice in STATA:

capture program drop bttieh

program define bttieh

args lnf g1 g2 theta hf

tempvar num denom

quietly gen double `denom' = ln(exp(`g1'+`hf') + exp(`g2') + exp(`theta')*((exp(`g1'+`hf')*exp(`g2'))^(.5)))

quietly gen double `num' = `g1'+`hf' if $ML_y1==1

quietly replace `num' = `g2' if $ML_y1==0

quietly replace `num' = (`theta' + .5*(`g1'+`hf'+`g2')) if $ML_y1==.5

quietly replace `lnf' = `num' - `denom'

end

forvalues i=1/59 {

constraint define `i' _b[home:`i'.teamid] = _b[away:`i'.oppid]

}

ml model lf bttieh (home: twin = i.teamid,nocons) (away:i.oppid,nocons) (theta: ) (hf: home,nocons),constraints(2-59)

ml max,nocnsr

matrix adjkrach = e(b)

teamid and oppid are index variables for the home team and road team (arbitrary in the case of neutral ice), home is an indicator variable for the home team not on neutral ice, twin is a vector giving the result {0,.5,1} for the team denoted by teamid

Not nearly as neat, huh?

## Comment