This function simulates one or more pseudo-random datasets from a specified Bradley-Terry model. Counts are simulated from independent binomial distributions, with the binomial probabilities and totals specified through the function arguments.

simulate_BT(pi, N, nsim = 1, seed = NULL, result_class = c("sparseMatrix",
  "btdata"))

# S3 method for btfit
simulate(object, nsim = 1, seed = NULL,
  result_class = c("sparseMatrix", "btdata"), ...)

Arguments

pi

a numeric vector, with all values finite and positive. The vector of item strengths in the Bradley-Terry model.

N

a symmetric, numeric matrix with dimensions the same as length(pi). The elements should be numeric representations of non-negative integers. These are the binomial totals to use for the simulated data.

nsim

a scalar integer, the number of datasets to be generated.

seed

an object specifying if and how the random number generator should be initialized (‘seeded’). For details see simulate.

result_class

a character vector specifying whether the generated datasets should be of class "sparseMatrix" or of class "btdata". If not specified, the first match among those alternatives is used.

object

An object of class "btfit", typically the result of ob of ob <- btfit(..). This object must only have one component, i.e. length(object$pi) == 1.

...

Other arguments

Value

a list of length nsim of simulated datasets. If result_class = "sparseMatrix", the datasets are sparse matrices with the same dimensions as N. If result_class = "btdata" then the datasets are "btdata" objects. See btdata

See also

btfit, btdata

Examples

set.seed(1) n <- 6 N <- matrix(rpois(n ^ 2, lambda = 1), n, n) N <- N + t(N) ; diag(N) <- 0 p <- exp(rnorm(n)/4) names(p) <- rownames(N) <- colnames(N) <- letters[1:6] simulate_BT(p, N, seed = 6)
#> $sim_1 #> 6 x 6 sparse Matrix of class "dgCMatrix" #> a b c d e f #> a . 2 2 2 . 2 #> b 2 . 2 2 0 0 #> c 0 0 . 2 1 3 #> d 1 0 2 . 0 . #> e . 1 0 2 . 2 #> f 1 1 2 . 0 . #> #> attr(,"seed") #> [1] 6 #> attr(,"seed")attr(,"kind") #> attr(,"seed")attr(,"kind")[[1]] #> [1] "Mersenne-Twister" #> #> attr(,"seed")attr(,"kind")[[2]] #> [1] "Inversion" #>
citations_btdata <- btdata(BradleyTerryScalable::citations) fit1 <- btfit(citations_btdata, 1) simulate(fit1, nsim = 2, seed = 1)
#> $sim_1 #> 4 x 4 sparse Matrix of class "dgCMatrix" #> citing #> cited JRSS-B Biometrika JASA Comm Statist #> JRSS-B . 286 316 285 #> Biometrika 219 . 495 725 #> JASA 151 323 . 817 #> Comm Statist 8 38 64 . #> #> $sim_2 #> 4 x 4 sparse Matrix of class "dgCMatrix" #> citing #> cited JRSS-B Biometrika JASA Comm Statist #> JRSS-B . 291 315 273 #> Biometrika 214 . 511 723 #> JASA 152 307 . 811 #> Comm Statist 20 40 70 . #> #> attr(,"seed") #> [1] 1 #> attr(,"seed")attr(,"kind") #> attr(,"seed")attr(,"kind")[[1]] #> [1] "Mersenne-Twister" #> #> attr(,"seed")attr(,"kind")[[2]] #> [1] "Inversion" #>
toy_df_4col <- codes_to_counts(BradleyTerryScalable::toy_data, c("W1", "W2", "D")) toy_btdata <- btdata(toy_df_4col) fit2 <- btfit(toy_btdata, 1, subset = function(x) "Amy" %in% x) fit2_sim <- simulate(fit2, nsim = 3, result_class = "btdata") fit2_sim$sim_1
#> $wins #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Cyd Amy Ben Dan #> Cyd . 1 . 1 #> Amy 1 . 1 0 #> Ben . 0 . 1 #> Dan 0 2 1 . #> #> $components #> $components$`1` #> [1] "Cyd" "Amy" "Ben" "Dan" #> #> #> attr(,"class") #> [1] "btdata" "list"
purrr::map(fit2_sim, "wins")
#> $sim_1 #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Cyd Amy Ben Dan #> Cyd . 1 . 1 #> Amy 1 . 1 0 #> Ben . 0 . 1 #> Dan 0 2 1 . #> #> $sim_2 #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Cyd Amy Ben Dan #> Cyd . 2 . 1 #> Amy 0 . 1 2 #> Ben . 0 . 1 #> Dan 0 0 1 . #> #> $sim_3 #> 4 x 4 sparse Matrix of class "dgCMatrix" #> player2 #> player1 Cyd Amy Ben Dan #> Cyd . 1 . 1 #> Amy 1 . 0 2 #> Ben . 1 . 1 #> Dan 0 0 1 . #>