1

我正在尝试使用 R.3.3.1 中的 BradleyTerry2 包在我的数据分析中包含特定于比赛的变量(我还尝试使用 R.2.11.1 与旧版本的 BradleyTerry2 进行比较)。我面临的问题是我的预测变量没有得到适当的考虑。下面的示例向您展示了我的问题,使用 CEMS 数据来说明我的观点。

    CEMS.BTmodel_01 <- BTm(outcome = cbind(win1.adj, win2.adj),
        player1 = school1, 
        player2 = school2, 
        formula = ~ .. + WOR[student] * LAT[..], 
        refcat = "Stockholm", 
        data = CEMS)
    summary(CEMS.BTmodel_01)

使用此模型,我们得到 AIC = 5837.4,交互作用估计为 LAT[..] * WOR[student] = 0.85771

现在,如果我在列表顶部添加一所新学校(图卢兹,LAT = 1)

    Toulouse <- c(1,0,0,0,0,0,0)
    Barcelona <- c(0,1,0,0,0,0,0)
    London <- c(0,0,1,0,0,0,0)
    Milano <- c(0,0,0,1,0,0,0)
    Paris <- c(0,0,0,0,1,0,0)
    St.Gallen <- c(0,0,0,0,0,1,0)
    Stockholm <- c(0,0,0,0,0,0,1)
    LAT <- c(1,1,0,1,1,0,0)
    schools <- data.frame(Toulouse, Barcelona, London, Milano, Paris, St.Gallen, Stockholm, LAT)
    rownames(schools) <- c("Toulouse", "Barcelona", "London", "Milano", "Paris", "St.Gallen", "Stockholm")
    CEMS$schools <- schools

我希望从分析中得到相同的结果,因为新学校没有出现在数据集中。但我实际上得到 AIC = 5855.8,一个交互 LAT[..] * WOR[student] = 0.13199

使用数据,看起来我的预测变量的名称(这里是学校的名称)没有得到适当的考虑,并且与我的比较数据(这里是欧洲学生的成对比较)相匹配。相反,重要的是他们的顺序。

我做错了什么?

4

1 回答 1

0

的行CEMS$schools应该与school1school2因子的级别相匹配(行名CEMS$schools实际上并未在代码中使用;第一行应该与第一级匹配等)。因此,您需要更新 和 的school1级别school2

CEMS$preferences <-
within(CEMS$preferences, {
    school1 <- factor(school1, rownames(CEMS$schools))
    school2 <- factor(school2, rownames(CEMS$schools))
    })

CEMS.BTmodel_02 <- BTm(outcome = cbind(win1.adj, win2.adj),
                   player1 = school1, 
                   player2 = school2, 
                   formula = ~ .. + WOR[student] * LAT[..], 
                   refcat = "Stockholm", 
                   data = CEMS)

现在模型与预期的一样:

> CEMS.BTmodel_01
Bradley Terry model fit by glm.fit 

Call:  BTm(outcome = cbind(win1.adj, win2.adj), player1 = school1, player2 = school2, 
    formula = ~.. + WOR[student] * LAT[..], refcat = "Stockholm", 
    data = CEMS)

Coefficients  [contrasts:  ..=contr.treatment ]:
        ..Barcelona                 ..London                 ..Milano  
             0.5044                   1.6037                   0.3538  
            ..Paris              ..St.Gallen          WOR[student]yes  
             0.8741                   0.5268                       NA  
            LAT[..]  WOR[student]yes:LAT[..]  
                 NA                   0.8577  
Degrees of Freedom: 4454 Total (i.e. Null);  4448 Residual
  (91 observations deleted due to missingness)
Null Deviance:      5499 
Residual Deviance: 4912     AIC: 5837

> CEMS.BTmodel_02
Bradley Terry model fit by glm.fit 

Call:  BTm(outcome = cbind(win1.adj, win2.adj), player1 = school1, player2 = school2, 
    formula = ~.. + WOR[student] * LAT[..], refcat = "Stockholm", 
    data = CEMS)

Coefficients  [contrasts:  ..=contr.treatment ]:
         ..Toulouse              ..Barcelona                 ..London  
                 NA                   0.5044                   1.6037  
           ..Milano                  ..Paris              ..St.Gallen  
             0.3538                   0.8741                   0.5268  
    WOR[student]yes                  LAT[..]  WOR[student]yes:LAT[..]  
                 NA                       NA                   0.8577 
Degrees of Freedom: 4454 Total (i.e. Null);  4448 Residual
  (91 observations deleted due to missingness)
Null Deviance:      5499 
Residual Deviance: 4912     AIC: 5837
于 2016-08-29T08:20:24.770 回答