Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I am trying to use the package BradleyTerry2 in R to assess sports teams. I am using the paper "Bradley-Terry Models in R: The BradleyTerry2 Package" written by Turner and Firth to guide me. I have gotten the model to work, but now would like to include player-specific predictor variables.

Currently, my data is set up as such: First column is the winning team, second column is the losing team, third column is the frequency. I am not sure how to insert the predictor variables. I tried including a fourth column with the winning team's variables and a fifth column with the losing team's variables, but have not gotten this to work. I am not sure if I am just not setting the data up correctly, or if my code is wrong.

So, one step at a time. I guess for now, my question is--I am setting up the data correctly? If not, how should it be set up?

share|improve this question
2  
Did you read the vignette ? cran.r-project.org/web/packages/BradleyTerry2/vignettes/… – Robert Long Jul 31 '12 at 6:33
Oh yes, this is the paper I am using to guide me. I just don't quite understand the wording (and maybe the terminology) if you would be willing to clarify--p 5-6 "The values of this factor are given by 'winner' for the winning lizard and 'loser' for the losing lizard in each contest. These factors are provided in the data frame 'contests' that is the first element of the list object 'flatlizards'. The second element of 'flatlizards' is another data frame 'predictors' containing measurements on the observed lizzards." Im assuming different columns? Not sure about the term data frame. – Eva Jul 31 '12 at 14:47
Type ?data.frame to find out about data frames. – conjugateprior Jul 31 '12 at 19:09

1 Answer

up vote 3 down vote accepted

The general advice is to start with a working example from the package, play with it enough to understand it, then adjust it to your problem.

So, first take a look at the structure of the flatlizards data. (Load it with data(flatlizards)) This is the data for the BTm model fitting function, but unlike usual it's a list not a data.frame. It has two components inside which are data.frames, and they have canonical names: 'contests' and 'predictors'. Looking now at the first one of these, flatlizards$contests, you'll see that it has two column names 'winner' and 'loser' and that in the columns are lizard identifiers. These identifiers are the row labels in the other data.frame, flatlizards$predictors. Together these two data.frames tell you who won each match and provide each player's attributes. This gives you a picture of what you need, viz. a list with two appropriately named data.frames with row and column labels as above but with your data in.

One small difference from the example in the paper is that since you have apparently already aggregated wins and losses by pairs, your first argument to BTm is probably not simply 1 as it is in the example but rather the number of times the particular contest between two individuals turned out this way.

Hope that's enough to get you going.

share|improve this answer
Thank you for your help! – Eva Aug 1 '12 at 6:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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