Learn R Programming

VGAM (version 1.0-2)

binom2.or: Bivariate Binary Regression with an Odds Ratio

Description

Density and random generation for a bivariate binary regression model using an odds ratio as the measure of dependency.

Usage

rbinom2.or(n, mu1, mu2 = if (exchangeable) mu1 else stop("argument 'mu2' not specified"), oratio = 1, exchangeable = FALSE, tol = 0.001, twoCols = TRUE, colnames = if (twoCols) c("y1","y2") else c("00", "01", "10", "11"), ErrorCheck = TRUE) dbinom2.or(mu1, mu2 = if (exchangeable) mu1 else stop("'mu2' not specified"), oratio = 1, exchangeable = FALSE, tol = 0.001, colnames = c("00", "01", "10", "11"), ErrorCheck = TRUE)

Arguments

lmu
Link function applied to the two marginal probabilities. See Links for more choices. See the note below.

lmu1, lmu2
Link function applied to the first and second of the two marginal probabilities.

loratio
Link function applied to the odds ratio. See Links for more choices.

imu1, imu2, ioratio
Optional initial values for the marginal probabilities and odds ratio. See CommonVGAMffArguments for more details. In general good initial values are often required so use these arguments if convergence failure occurs.

zero
Which linear/additive predictor is modelled as an intercept only? The default is for the odds ratio. A NULL means none. See CommonVGAMffArguments for more details.

exchangeable
Logical. If TRUE, the two marginal probabilities are constrained to be equal.

tol
Tolerance for testing independence. Should be some small positive numerical value.

more.robust
Logical. If TRUE then some measures are taken to compute the derivatives and working weights more robustly, i.e., in an attempt to avoid numerical problems. Currently this feature is not debugged if set TRUE.

n
number of observations. Same as in runif. The arguments mu1, mu2, oratio are recycled to this value.

mu1, mu2
The marginal probabilities. Only mu1 is needed if exchangeable = TRUE. Values should be between 0 and 1.

oratio
Odds ratio. Must be numeric and positive. The default value of unity means the responses are statistically independent.

exchangeable
Logical. If TRUE, the two marginal probabilities are constrained to be equal.

twoCols
Logical. If TRUE, then a $n$ $*$ $2$ matrix of 1s and 0s is returned. If FALSE, then a $n$ $*$ $4$ matrix of 1s and 0s is returned.

colnames
The dimnames argument of matrix is assigned list(NULL, colnames).

tol
Tolerance for testing independence. Should be some small positive numerical value.

ErrorCheck
Logical. Do some error checking of the input parameters?

Value

The function rbinom2.or returns either a 2 or 4 column matrix of 1s and 0s, depending on the argument twoCols.The function dbinom2.or returns a 4 column matrix of joint probabilities; each row adds up to unity.

Details

The function rbinom2.or generates data coming from a bivariate binary response model. The data might be fitted with the VGAM family function binom2.or.

The function dbinom2.or does not really compute the density (because that does not make sense here) but rather returns the four joint probabilities.

See Also

binom2.or.

Examples

Run this code
nn <- 1000  # Example 1
ymat <- rbinom2.or(nn, mu1 = logit(1, inv = TRUE), oratio = exp(2), exch = TRUE)
(mytab <- table(ymat[, 1], ymat[, 2], dnn = c("Y1", "Y2")))
(myor <- mytab["0","0"] * mytab["1","1"] / (mytab["1","0"] * mytab["0","1"]))
fit <- vglm(ymat ~ 1, binom2.or(exch = TRUE))
coef(fit, matrix = TRUE)

bdata <- data.frame(x2 = sort(runif(nn)))  # Example 2
bdata <- transform(bdata, mu1 = logit(-2 + 4 * x2, inverse = TRUE),
                          mu2 = logit(-1 + 3 * x2, inverse = TRUE))
dmat <- with(bdata, dbinom2.or(mu1 = mu1, mu2 = mu2, oratio = exp(2)))
ymat <- with(bdata, rbinom2.or(n = nn, mu1 = mu1, mu2 = mu2, oratio = exp(2)))
fit2 <- vglm(ymat ~ x2, binom2.or, data = bdata)
coef(fit2, matrix = TRUE)
## Not run: 
# matplot(with(bdata, x2), dmat, lty = 1:4, col = 1:4, type = "l",
#         main = "Joint probabilities", ylim = 0:1,
#         ylab = "Probabilities", xlab = "x2", las = 1)
# legend("top", lty = 1:4, col = 1:4,
#        legend = c("1 = (y1=0, y2=0)", "2 = (y1=0, y2=1)",
#                   "3 = (y1=1, y2=0)", "4 = (y1=1, y2=1)"))
# ## End(Not run)

Run the code above in your browser using DataLab