【问题标题】:Issue with Predictor Variables in BradleyTerry2 packageBradleyTerry2 包中的预测变量问题
【发布时间】:2016-08-19 09:00:08
【问题描述】:

我正在尝试使用 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

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

我做错了什么?

【问题讨论】:

    标签: r bradleyterry2


    【解决方案1】:

    CEMS$schools 的行应与school1school2 因子的级别匹配(CEMS$schools 的行名实际上并未在代码中使用;第一行应与第一级别匹配等)。所以需要更新school1school2的等级:

    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
    

    【讨论】:

    • 太好了,效果很好,现在效果好多了。我还意识到,同样的方法也必须应用于其他协变量矩阵(CEMS 示例中的“学生”矩阵)。
    猜你喜欢
    • 2016-08-23
    • 2018-10-25
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    相关资源
    最近更新 更多