1
$\begingroup$

I want to fit a linear model for goal differences of ice hockey matches with regressor - difference in forms of teams. So my model has form:

$y_{ijt} = \mu + \alpha_i - \alpha_j + \varepsilon_{ijt}, (ij) = 1, \ldots,n$

where $\alpha$ denotes categorical variable with levels teams and $\mu$ home advantage. Notice that $(ij)$ determines only one match (two different teams). Is there an efficient way how to estimate $\alpha$ with contrasts "contr.sum" in R?

I have achieved it only in a very clumsy way using model.matrix. Suppose we have 3 teams a, b and c and the following data:

n <- 5
testFrame <- data.frame(home = rep(letters[1:3], 
                            each = n),
              guest =rep(letters[1:3][c(2, 3, 
                       1)], 
              each = n), 
              y = c(rnorm(n), rnorm(n, 1), 
                           rnorm(n))) 

I have fitted lm model with the last form set to 0 and then recalculated it to get $\alpha$.

dmatrix <- model.matrix(~ -1 + testFrame[, 1]) - 
               model.matrix(~ -1 + 
                     testFrame[, 2])
colnames(dmatrix) <- letters[1:3]

d2 <- dmatrix[ , 1:2]
f <- lm(testFrame$y ~ d2)

coef(f)[-1]%*%c(2,-1)/3
coef(f)[-1]%*%c(-1,2)/3
coef(f)[-1]%*%c(-1,-1)/3  
$\endgroup$
2
  • $\begingroup$ Although framed in terms of R code, this seems like it is actually a statistical question. I'm voting to leave open. $\endgroup$ Commented Feb 23, 2015 at 0:57
  • $\begingroup$ You may want to look into some of the introductory material on Bradley-Terry models, which relate to a a similar issue. It may help you identify approaches to your problem. $\endgroup$
    – Glen_b
    Commented Feb 23, 2015 at 1:34

1 Answer 1

0
$\begingroup$

Are you trying to follow the papers published by Clarke and Norman in 1995 or Harville 1980? On the first paper they arrive to formulas to calculate the ability and the home advantage. The individual home advantages for each club can be calculated as: $\mu_i=\frac{HGD_i-AGD_i-HGD/(n-1)}{n-2}$ where $HGD=\sum_i HGD_i$ is the home goal difference, AGD id the away goal difference and n is the number of teams you are studying. For the $\alpha$ they arrive to the following formula: $\alpha_i=\frac{HGD_i-(n-1)\mu_i}{n}$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.