# NOT RUN {
#############################################################################
# EXAMPLE 1: Bradley-Terry model | data.pw01
#############################################################################
data(data.pw01)
dat <- data.pw01
dat <- dat[, c("home_team", "away_team", "result") ]
# recode results according to needed input
dat$result[ dat$result==0 ] <- 1/2 # code for ties
dat$result[ dat$result==2 ] <- 0 # code for victory of away team
#********************
# Model 1: Estimation with ties and home advantage
mod1 <- sirt::btm( dat)
summary(mod1)
# }
# NOT RUN {
#*** Model 2: Estimation with ties, no epsilon adjustment
mod2 <- sirt::btm( dat, eps=0)
summary(mod2)
#*** Model 3: Estimation with ties, no epsilon adjustment, weight for ties of .333 which
# corresponds to the rule of 3 points for a victory and 1 point of a draw in football
mod3 <- sirt::btm( dat, eps=0, wgt.ties=1/3)
summary(mod3)
#*** Model 4: Some fixed abilities
fix.theta <- c("Anhalt Dessau"=-1 )
mod4 <- sirt::btm( dat, eps=0, fix.theta=fix.theta)
summary(mod4)
#*** Model 5: Ignoring ties, no home advantage effect
mod5 <- sirt::btm( dat, ignore.ties=TRUE, fix.eta=0)
summary(mod5)
#*** Model 6: Ignoring ties, no home advantage effect (JML approach and eps=0)
mod6 <- sirt::btm( dat, ignore.ties=TRUE, fix.eta=0, eps=0)
summary(mod5)
#############################################################################
# EXAMPLE 2: Venice chess data
#############################################################################
# See http://www.rasch.org/rmt/rmt113o.htm
# Linacre, J. M. (1997). Paired Comparisons with Standard Rasch Software.
# Rasch Measurement Transactions, 11:3, 584-585.
# dataset with chess games -> "D" denotes a draw (tie)
chessdata <- scan( what="character")
1D.0..1...1....1.....1......D.......D........1.........1.......... Browne
0.1.D..0...1....1.....1......D.......1........D.........1......... Mariotti
.D0..0..1...D....D.....1......1.......1........1.........D........ Tatai
...1D1...D...D....1.....D......D.......D........1.........0....... Hort
......010D....D....D.....1......D.......1........1.........D...... Kavalek
..........00DDD.....D.....D......D.......1........D.........1..... Damjanovic
...............00D0DD......D......1.......1........1.........0.... Gligoric
.....................000D0DD.......D.......1........D.........1... Radulov
............................DD0DDD0D........0........0.........1.. Bobotsov
....................................D00D00001.........1.........1. Cosulich
.............................................0D000D0D10..........1 Westerinen
.......................................................00D1D010000 Zichichi
L <- length(chessdata) / 2
games <- matrix( chessdata, nrow=L, ncol=2, byrow=TRUE )
G <- nchar(games[1,1])
# create matrix with results
results <- matrix( NA, nrow=G, ncol=3 )
for (gg in 1:G){
games.gg <- substring( games[,1], gg, gg )
ind.gg <- which( games.gg !="." )
results[gg, 1:2 ] <- games[ ind.gg, 2]
results[gg, 3 ] <- games.gg[ ind.gg[1] ]
}
results <- as.data.frame(results)
results[,3] <- paste(results[,3] )
results[ results[,3]=="D", 3] <- 1/2
results[,3] <- as.numeric( results[,3] )
# fit model ignoring draws
mod1 <- sirt::btm( results, ignore.ties=TRUE, fix.eta=0, eps=0 )
summary(mod1)
# fit model with draws
mod2 <- sirt::btm( results, fix.eta=0, eps=0 )
summary(mod2)
#############################################################################
# EXAMPLE 3: Simulated data from the Bradley-Terry model
#############################################################################
set.seed(9098)
N <- 22
theta <- seq(2,-2, len=N)
#** simulate and estimate data without repeated dyads
dat1 <- sirt::btm_sim(theta=theta)
mod1 <- sirt::btm( dat1, ignore.ties=TRUE, fix.delta=-99, fix.eta=0)
summary(mod1)
#*** simulate data with home advantage effect and ties
dat2 <- sirt::btm_sim(theta=theta, eta=.8, delta=-.6, repeated=TRUE)
mod2 <- sirt::btm(dat2)
summary(mod2)
#############################################################################
# EXAMPLE 4: Estimating the Bradley-Terry model with multiple judges
#############################################################################
#*** simulating data with multiple judges
set.seed(987)
N <- 26 # number of objects to be rated
theta <- seq(2,-2, len=N)
s1 <- stats::sd(theta)
dat <- NULL
# judge discriminations which define tendency to provide reliable ratings
discrim <- c( rep(.9,10), rep(.5,2), rep(0,2) )
#=> last four raters provide less reliable ratings
RR <- length(discrim)
for (rr in 1:RR){
theta1 <- discrim[rr]*theta + stats::rnorm(N, mean=0, sd=s1*sqrt(1-discrim[rr]))
dat1 <- sirt::btm_sim(theta1)
dat1$judge <- rr
dat <- rbind(dat, dat1)
}
#** estimate the Bradley-Terry model and compute judge-specific fit statistics
mod <- sirt::btm( dat[,1:3], judge=paste0("J",100+dat[,4]), fix.eta=0, ignore.ties=TRUE)
summary(mod)
# }
Run the code above in your browser using DataLab