更新了数据:差异中的错误...必须是相同水平的因素 [英] Updated with data: Error in Diff...must be factors with the same levels

查看:87
本文介绍了更新了数据:差异中的错误...必须是相同水平的因素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望大家能帮助我。

我有一个包含两个数据框的列表-比赛 expvar。在数据框比赛中,每一行都是比赛,第一列是比赛的获胜者,第二列是比赛的输家。在数据框 expvar 中,我有玩家特定的预测变量。这些都是数字。我正在尝试使用BradleyTerry2软件包来分析我的数据。这是我正在使用的代码:

I have a list with two data frames -- contests and expvar. In the data frame contests, each row is a match with the first column being the winner of the match, and the second column being the loser of the match. In the data frame expvar I have player-specific predictor variables. These are all numbers. I am trying to use the BradleyTerry2 package to analyze my data. Here is the code I am using:

a <- data.frame(read.csv(file.choose()))
b <- data.frame(read.csv(file.choose()))
ablist <- list(contests=a, expvar=b)  
Model <- BTm(1, winner, loser, ~level2[..]+(1|..), data=ablist)

这是我得到的错误:

Error in Diff(player1, player2, formula, id, data, separate.ability, refcat,  : 
'player1$..' and 'player2$..' must be factors with the same levels

我的问题是,我做错了什么?我尝试了很多事情,但是我不确定这个错误是什么意思。我应该将变量更改为因子吗?为什么/如何?失败者都有相同类别的预测变量。

My question is, what am I doing wrong? I have tried many things, but I am not sure what this error means. Should I change my variables into factors? Why/how? The winners and losers all have the same categories of predictor variables.

这是我的 dput(a)

Here is my output for dput(a)

structure(list(winner = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 
11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 
14L, 14L, 14L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 
19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 
22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 
26L, 27L, 27L, 27L, 27L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L, 
29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 
30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 23L, 13L, 
20L, 20L), .Label = c("Arizona Cardinals", "Atlanta Falcons", 
"Baltimore Ravens", "Buffalo Bills", "Carolina Panthers", "Chicago Bears", 
"Cincinnati Bengals", "Cleveland Browns", "Dallas Cowboys", "Denver Broncos", 
"Green Bay Packers", "Houston Texans", "Indianapolis Colts", 
"Jacksonville Jaguars", "Kansas City Chiefs", "Miami Dolphins", 
"Minnesota Vikings", "New England Patriots", "New Orleans Saints", 
"New York Giants", "New York Jets", "Oakland Raiders", "Philadelphia Eagles", 
"Pittsburgh Steelers", "San Diego Chargers", "San Francisco 49ers", 
"Seattle Seahawks", "St. Louis Rams", "Tampa Bay Buccaneers", 
"Tennessee Titans", "Washington Redskins"), class = "factor"), 
    loser = structure(c(4L, 9L, 17L, 27L, 27L, 28L, 28L, 29L, 
    29L, 5L, 6L, 11L, 12L, 16L, 18L, 20L, 23L, 26L, 29L, 30L, 
    7L, 7L, 8L, 8L, 9L, 13L, 15L, 17L, 23L, 24L, 32L, 10L, 15L, 
    16L, 23L, 26L, 28L, 29L, 1L, 2L, 6L, 10L, 11L, 12L, 16L, 
    20L, 20L, 23L, 26L, 30L, 11L, 11L, 12L, 14L, 15L, 18L, 20L, 
    24L, 29L, 8L, 15L, 16L, 32L, 4L, 7L, 15L, 21L, 7L, 8L, 12L, 
    21L, 24L, 27L, 28L, 30L, 32L, 2L, 8L, 16L, 20L, 22L, 23L, 
    26L, 30L, 6L, 11L, 11L, 14L, 18L, 28L, 6L, 7L, 8L, 11L, 12L, 
    15L, 17L, 31L, 3L, 7L, 8L, 11L, 13L, 13L, 15L, 19L, 25L, 
    26L, 31L, 10L, 11L, 12L, 13L, 14L, 10L, 23L, 4L, 4L, 10L, 
    16L, 19L, 22L, 23L, 26L, 27L, 28L, 29L, 1L, 5L, 6L, 11L, 
    11L, 12L, 13L, 15L, 20L, 21L, 1L, 4L, 4L, 10L, 16L, 17L, 
    22L, 23L, 27L, 28L, 29L, 2L, 11L, 12L, 16L, 23L, 26L, 27L, 
    30L, 1L, 3L, 5L, 7L, 9L, 24L, 25L, 27L, 28L, 32L, 1L, 4L, 
    4L, 7L, 16L, 17L, 19L, 29L, 31L, 10L, 13L, 16L, 22L, 30L, 
    1L, 2L, 8L, 9L, 21L, 25L, 27L, 28L, 29L, 3L, 3L, 7L, 7L, 
    8L, 8L, 9L, 13L, 15L, 19L, 26L, 32L, 10L, 16L, 16L, 19L, 
    22L, 23L, 23L, 30L, 4L, 11L, 22L, 28L, 29L, 29L, 32L, 22L, 
    27L, 29L, 29L, 9L, 32L, 2L, 5L, 6L, 11L, 12L, 16L, 18L, 20L, 
    28L, 3L, 6L, 7L, 8L, 11L, 12L, 13L, 14L, 15L, 15L, 16L, 18L, 
    25L, 1L, 8L, 9L, 11L, 20L, 24L, 24L, 28L, 7L, 18L, 29L, 32L
    ), .Label = c("Arizona Cardinals", "Atlanta Falcons", "Baltimore Ravens", 
    "Buffalo Bills", "Carolina Panthers", "Chicago Bears", "Cincinnati Bengals", 
    "Cleveland Browns", "Dallas Cowboys", "Denver Broncos", "Detroit Lions", 
    "Green Bay Packers", "Houston Texans", "Indianapolis Colts", 
    "Jacksonville Jaguars", "Kansas City Chiefs", "Miami Dolphins", 
    "Minnesota Vikings", "New England Patriots", "New Orleans Saints", 
    "New York Giants", "New York Jets", "Oakland Raiders", "Philadelphia Eagles", 
    "Pittsburgh Steelers", "San Diego Chargers", "San Francisco 49ers", 
    "Seattle Seahawks", "St. Louis Rams", "Tampa Bay Buccaneers", 
    "Tennessee Titans", "Washington Redskins"), class = "factor")), .Names = c("winner", 
"loser"), row.names = c(NA, -256L), class = "data.frame")

这里是 dput(b)

structure(list(X = structure(1:32, .Label = c("Arizona Cardinals", 
"Atlanta Falcons", "Baltimore Ravens", "Buffalo Bills", "Carolina Panthers", 
"Chicago Bears", "Cincinnati Bengals", "Cleveland Browns", "Dallas Cowboys", 
"Denver Broncos", "Detroit Lions", "Green Bay Packers", "Houston Texans", 
"Indianapolis Colts", "Jacksonville Jaguars", "Kansas City Chiefs", 
"Miami Dolphins", "Minnesota Vikings", "New England Patriots", 
"New Orleans Saints", "New York Giants", "New York Jets", "Oakland Raiders", 
"Philadelphia Eagles", "Pittsburgh Steelers", "San Diego Chargers", 
"San Francisco 49ers", "Seattle Seahawks", "St. Louis Rams", 
"Tampa Bay Buccaneers", "Tennessee Titans", "Washington Redskins"
), class = "factor"), id = 1:32, high = c(0L, 0L, 0L, 0L, 0L, 
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), level2 = c(0, 0.67, 
0, 0.33, 0.25, 0, 0, 0.25, 0.33, 0, 0.25, 0, 0, 0.5, 0, 0, 0.25, 
0.33, 0, 0, 0, 0, 0, 0, 0, 0.67, 0.25, 0, 0.2, 0, 0, 0.6), level3 = c(0.25, 
0.4, 0.36, 0.3, 0.11, 0.56, 0.38, 0.5, 0.22, 0.33, 0.6, 0.3, 
0.57, 0.38, 0.29, 0.43, 0.3, 0.33, 0.29, 0.14, 0.2, 0.22, 0.33, 
0.22, 0.5, 0.27, 0.4, 0.2, 0.43, 0.43, 0.33, 0.44)), .Names = c("X", 
"id", "high", "level2", "level3"), row.names = c(NA, -32L), class = "data.frame"

谢谢

推荐答案

我也对 BTm功能的此错误消息感到困惑。通过定义级别可以解决该问题。 (级别是类型因子函数的可定义属性)。尝试设置player1和amp;的级别玩家2:

I also got stuck with this error message for the 'BTm' function. The problem can be resolved by defining the levels. (levels are a definable attribute for functions of type factor). Try setting levels for player1 & player2:

    levels(contests[,1]) <- unique(c(contests[,1], contests[,2]))
    levels(contests[,2]) <- unique(c(contests[,1], contests[,2]))

抱歉3年前我帮不上忙;)

Sorry I couldn't help 3 years ago ;)

这篇关于更新了数据:差异中的错误...必须是相同水平的因素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆