simulate_BT: This function simulates one or more pseudo-random datasets...

Description Usage Arguments Value Author(s) See Also Examples

Description

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.

Usage

1
2
3
4
5
6
simulate_BT(pi, N, nsim = 1, seed = NULL, result_class = c("sparseMatrix",
  "btdata"))

## S3 method for class '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

Author(s)

David Firth

See Also

btfit, btdata

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)
citations_btdata <- btdata(BradleyTerryScalable::citations)
fit1 <- btfit(citations_btdata, 1)
simulate(fit1, nsim = 2, seed = 1)
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
purrr::map(fit2_sim, "wins")

BradleyTerryScalable documentation built on May 1, 2019, 8:23 p.m.