Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ranBin2

Sample pairs of correlated binary events


Description

This function is reproduced from the binarySimCLF package on CRAN. The original package appears no longer to be maintained. View the original source at: https://github.com/cran/binarySimCLF/blob/master/R/ranBin2.R

Usage

ranBin2(nRep, u, psi)

Arguments

nRep

Number of simulated event pairs, positive integer.

u

Mean event probabilities, expressed as a vector of length 2. E.g. to simulate associated bivariate events with probabilities 80 u = c(0.8, 0.3).

psi

Odds ratio, number. This parameter controls the strength of association. Use psi = 1 for no association. Values greater than 1 correspond to increasingly positive association between the two events, and vice-versa.

Value

Matrix of events represented as 0s and 1s, with nRep rows and 2 columns. The first column is the incidence of event 1.

Examples

probs <- c(0.8, 0.3)
s <- ranBin2(1000, probs, psi=0.2)  # 1000 pairs of outcomes
cor(s)  # Negatively correlated because psi < 1
colMeans(s)  # Event rates as expected

trialr

Clinical Trial Designs in 'rstan'

v0.1.5
GPL (>= 3)
Authors
Kristian Brock [aut, cre] (<https://orcid.org/0000-0002-3921-0166>), Trustees of Columbia University [cph]
Initial release
2020-10-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.