
R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(BradleyTerry2)
> 
> ##  This reproduces the analysis in Sec 10.6 of Agresti (2002).
> 
> data(baseball, package = "BradleyTerry2")
> 
> ##  Simple Bradley-Terry model, ignoring home advantage:
> baseballModel1 <- BTm(cbind(home.wins, away.wins), home.team, away.team,
+                       data = baseball, id = "team")
> summary(baseballModel1)

Call:
BTm(outcome = cbind(home.wins, away.wins), player1 = home.team, 
    player2 = away.team, id = "team", data = baseball)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.6539  -0.0508   0.4133   0.9736   2.5509  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)    
teamBoston      1.1077     0.3339   3.318 0.000908 ***
teamCleveland   0.6839     0.3319   2.061 0.039345 *  
teamDetroit     1.4364     0.3396   4.230 2.34e-05 ***
teamMilwaukee   1.5814     0.3433   4.607 4.09e-06 ***
teamNew York    1.2476     0.3359   3.715 0.000203 ***
teamToronto     1.2945     0.3367   3.845 0.000121 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 78.015  on 42  degrees of freedom
Residual deviance: 44.053  on 36  degrees of freedom
AIC: 140.52

Number of Fisher Scoring iterations: 4

> 
> ##  Now incorporate the "home advantage" effect
> baseball$home.team <- data.frame(team = baseball$home.team, at.home = 1)
> baseball$away.team <- data.frame(team = baseball$away.team, at.home = 0)
> baseballModel2 <- update(baseballModel1, formula = ~ team + at.home)
> summary(baseballModel2)

Call:
BTm(outcome = cbind(home.wins, away.wins), player1 = home.team, 
    player2 = away.team, formula = ~team + at.home, id = "team", 
    data = baseball)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.03819  -0.40577   0.04326   0.61163   2.26001  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)    
teamBoston      1.1438     0.3378   3.386 0.000710 ***
teamCleveland   0.7047     0.3350   2.104 0.035417 *  
teamDetroit     1.4754     0.3446   4.282 1.85e-05 ***
teamMilwaukee   1.6196     0.3474   4.662 3.13e-06 ***
teamNew York    1.2813     0.3404   3.764 0.000167 ***
teamToronto     1.3271     0.3403   3.900 9.64e-05 ***
at.home         0.3023     0.1309   2.308 0.020981 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 78.015  on 42  degrees of freedom
Residual deviance: 38.643  on 35  degrees of freedom
AIC: 137.11

Number of Fisher Scoring iterations: 4

> 
> ##  Compare the fit of these two models:
> anova(baseballModel1, baseballModel2)
Analysis of Deviance Table

Response: cbind(home.wins, away.wins)

Model 1: ~team
Model 2: ~team + at.home
  Resid. Df Resid. Dev Df Deviance
1        36     44.053            
2        35     38.643  1   5.4106
> 
