Generates pairwise outcomes among n_agent agents using the Davidson model with ties.
(See https://link.springer.com/article/10.3758/s13428-021-01714-2).
Returns one row per comparison with agent_a, agent_b, and winner.
Usage
irw_simdata_comp(
n_agent = 100,
n_pairs = 10000,
nu = 0,
theta = NULL,
theta_mean = 0,
theta_sd = 1,
seed = NULL,
return_params = FALSE
)Arguments
- n_agent
Integer. Number of agents (ignored if
thetaprovided). Default 100.- n_pairs
Integer. Number of pairwise comparisons to sample. Default 10000.
- nu
Numeric. Tie propensity in the Davidson model. Larger values yield more ties. Default 0.
- theta
Optional numeric vector of length
n_agentwith agent abilities. If provided, overridesn_agent. If NULL, sampled from N(0,1).- theta_mean
Mean of the theta distribution (used if
thetais NULL). Default 0.- theta_sd
SD of the theta distribution (used if
thetais NULL). Default 1.- seed
Optional integer for reproducibility.
- return_params
Logical. If TRUE, return a list with
data,theta, andnu. Default FALSE.
Value
A data.frame with columns:
agent_a(int): index of first agentagent_b(int): index of second agentwinner(chr): one of "agent_a","agent_b", or "draw".
If return_params = TRUE, returns a list with:
data: the simulated data frame.theta: vector of simulated thetas usednu: tie parameter
Examples
if (FALSE) { # \dontrun{
# --- Basic usage ---
d <- irw_simdata_comp(n_agent = 100, n_pairs = 10000, nu = 0)
head(d)
# Simulate pairwise comparison data and recover abilities with a Davidson model
th <- rnorm(n = 50, mean = 0.5, sd = 3)
pairs <- irw_simdata_comp(
n_agent = 50, n_pairs = 3000, nu = 0.1,
theta = th, seed = 1, return_params = TRUE
)
x <- pairs$data
x$winner <- ifelse(x$winner == "agent_b", -1, 1)
x$winner <- ifelse(x$winner == "draw", 0, x$winner)
x$agent_a <- as.factor(x$agent_a)
x$agent_b <- as.factor(x$agent_b)
x$pair <- seq_len(nrow(x)) # add pair id for expandCategorical
library(gnm)
library(BradleyTerry2)
pairs.tri <- expandCategorical(x, "winner", idvar = "pair")
dav <- gnm(
count ~ GenDavidson(
winner == 1, winner == 0, winner == -1,
player1 = agent_a,
player2 = agent_b
) - 1,
eliminate = pair,
family = poisson,
data = pairs.tri
)
plot(
pairs$theta, coef(dav)[-1],
xlab = "True theta",
ylab = "Estimated ability (shifted)",
main = "Davidson recovery using gnm"
)
abline(lm(coef(dav)[-1] ~ pairs$theta), lty = 2)
} # }