Last active
August 29, 2015 14:25
-
-
Save seanjtaylor/2a1c3a5b0fa1576148ec to your computer and use it in GitHub Desktop.
How to estimate a BTL model in R.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df <- data.frame(higher = c('US', 'CA', 'MX'), | |
lower = c('CA', 'MX', 'MX')) | |
levels <- c('US', 'CA', 'MX') | |
X.l <- model.matrix(~ 0 + factor(higher, levels = levels), data = df) | |
X.r <- model.matrix(~ 0 + factor(lower, levels = levels), data = df) | |
X <- X.l - X.r | |
colnames(X) <- levels # makes it easier to interpret regression output | |
# The higher one is always better than the lower one. | |
y <- rep(1, nrow(X)) | |
library(arm) | |
## Use a slight prior to stabilize estimates. | |
m <- bayesglm(y ~ 0 + X, family = binomial, prior.scale = 1) | |
summary(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment