Drawing discrete data based on probabilities or latent traits is a common
task that can be cumbersome. draw_binary
is an alias for
draw_discrete(type = "binary")
that allows you to draw binary
outcomes more easily.
draw_discrete(x, N = length(x), type = "binary", link = "identity", breaks = c(Inf, 0, Inf), break_labels = NULL, k = 1) draw_binary(x, N = length(x), link = "identity")
x  vector representing either the latent variable used to draw the count outcome (if link is "logit" or "probit") or the probability for the count outcome (if link is "identity"). For cartegorical distributions x is a matrix with as many columns as possible outcomes. 

N  number of units to draw. Defaults to the length of the vector

type  type of discrete outcome to draw, one of 'binary' (or 'bernoulli'), 'binomial', 'categorical', 'ordered' or 'count' 
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. 
breaks  vector of breaks to cut an ordered latent outcome 
break_labels  vector of labels for the breaks for an ordered latent outcome (must be the same length as breaks) 
k  the number of trials (zero or more) 
#> ID p binary #> 1 1 0.0 0 #> 2 2 0.5 0 #> 3 3 1.0 1#> ID p binary #> 1 1 0.0 0 #> 2 2 0.5 1 #> 3 3 1.0 1#> ID x binary #> 1 1 5.6 0 #> 2 2 5.4 0 #> 3 3 2.3 1#> ID p binomial #> 1 1 0.0 0 #> 2 2 0.5 3 #> 3 3 1.0 10fabricate(N = 3, x = 5*rnorm(N), ordered = draw_discrete(x, type = "ordered", breaks = c(Inf, 1, 1, Inf)))#> ID x ordered #> 1 1 7.0 1 #> 2 2 1.3 3 #> 3 3 2.2 1#> ID x count #> 1 1 0 0 #> 2 2 5 6 #> 3 3 100 111# Categorical fabricate(N = 6, p1 = runif(N), p2 = runif(N), p3 = runif(N), cat = draw_discrete(cbind(p1, p2, p3), type = "categorical"))#> ID p1 p2 p3 cat #> 1 1 0.219 0.407 0.37 2 #> 2 2 0.665 0.858 0.92 2 #> 3 3 0.390 0.518 0.68 3 #> 4 4 0.046 0.979 0.67 3 #> 5 5 0.617 0.017 0.76 1 #> 6 6 0.598 0.673 0.54 1