Drawing discrete data based on probabilities or latent traits is a common task that can be cumbersome. Each function in our discrete drawing set creates a different type of discrete data: `draw_binary` creates binary 0/1 data, `draw_binomial` creates binomial data (repeated trial binary data), `draw_categorical` creates categorical data, `draw_ordered` transforms latent data into observed ordered categories, `draw_count` creates count data (poisson-distributed)

draw_binomial(probs, trials = 1, N = length(probs), link = "identity")

draw_categorical(probs, N = NULL, link = "identity")

draw_ordered(x, breaks = c(-1, 0, 1), break_labels = NULL, N = length(x),
  link = "identity")

draw_count(means, N = length(means), link = "identity")

draw_binary(probs, N = length(probs), link = "identity")

Arguments

probs

A number or vector of numbers representing the probability for binary or binomial outcomes; or a number, vector, or matrix of numbers representing probabilities for categorical outcomes. If you supply a link function, these underlying probabilities will be transformed.

trials

for `draw_binomial`, the number of trials for each observation

N

number of units to draw. Defaults to the length of the vector of probabilities or latent data you provided

link

link function between the latent variable and the probability of a postiive outcome, i.e. "logit", "probit", or "identity". For the "identity" link, the latent variable must be a probability.

x

for `draw_ordered`, the latent data for each observation.

breaks

vector of breaks to cut a latent outcome into ordered categories

break_labels

vector of labels for the breaks to cut a latent outcome into ordered categories.

means

for `draw_count`, the mean number of count units for each observation

Examples

fabricate(N = 3, p = c(0, .5, 1), binary = draw_binary(probs = p))
#> ID p binary #> 1 1 0.0 0 #> 2 2 0.5 1 #> 3 3 1.0 1
fabricate(N = 3, x = 10 * rnorm(N), binary = draw_binary(probs = x, link = "probit"))
#> ID x binary #> 1 1 -18.815811 0 #> 2 2 4.662434 1 #> 3 3 3.840727 1
fabricate(N = 3, p = c(0, .5, 1), binomial = draw_binomial(probs = p, trials = 10))
#> ID p binomial #> 1 1 0.0 0 #> 2 2 0.5 3 #> 3 3 1.0 10
fabricate(N = 3, x = 5 * rnorm(N), ordered = draw_ordered(x=x, breaks = c(-Inf, -1, 1, Inf)))
#> ID x ordered #> 1 1 4.825444 3 #> 2 2 2.810337 3 #> 3 3 -5.814528 1
fabricate(N = 3, x = c(0,5,100), count = draw_count(means=x))
#> ID x count #> 1 1 0 0 #> 2 2 5 4 #> 3 3 100 89
# Categorical fabricate(N = 6, p1 = runif(N), p2 = runif(N), p3 = runif(N), cat = draw_categorical(cbind(p1, p2, p3)))
#> ID p1 p2 p3 cat #> 1 1 0.4702427 0.2739955 0.9234934 1 #> 2 2 0.7910454 0.4308361 0.6137436 1 #> 3 3 0.3129833 0.4168978 0.3156294 3 #> 4 4 0.3087645 0.1343122 0.8097331 3 #> 5 5 0.3451553 0.6863414 0.9023741 3 #> 6 6 0.8284433 0.1720781 0.1252978 1