| Binom2.rho {VGAM} | R Documentation |
Density and random generation for a bivariate probit model. The correlation parameter rho is the measure of dependency.
rbinom2.rho(n, mu1,
mu2=if(exchangeable) mu1 else stop("'mu2' not specified"),
rho=0, exchangeable=FALSE, twoCols=TRUE,
colnames=if(twoCols) c("y1","y2") else c("00", "01", "10", "11"),
ErrorCheck=TRUE)
dbinom2.rho(mu1,
mu2=if(exchangeable) mu1 else stop("'mu2' not specified"),
rho=0, exchangeable=FALSE,
colnames=c("00", "01", "10", "11"), ErrorCheck=TRUE)
n |
number of observations. Must be a single positive integer.
The arguments mu1, mu2, rho are recycled to
length n.
|
mu1, mu2 |
The marginal probabilities.
Only mu1 is needed if exchangeable=TRUE.
Values should be between 0 and 1.
|
rho |
The correlation parameter.
Must be numeric and lie between -1 and 1.
The default value of zero means the responses are uncorrelated.
|
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).
|
ErrorCheck |
Logical. Do some error checking of the input parameters?
|
The function rbinom2.rho generates data coming from a bivariate
probit model.
The data might be fitted with the VGAM family function
binom2.rho.
The function dbinom2.rho does not really compute the density
(because that does not make sense here) but rather returns the
four joint probabilities.
The function rbinom2.rho returns
either a 2 or 4 column matrix of 1s and 0s, depending on the argument
twoCols.
The function dbinom2.rho returns
a 4 column matrix of joint probabilities; each row adds up to unity.
T. W. Yee
# Example 1
nn = 2000
(myrho <- rhobit(2, inverse=TRUE))
ymat = rbinom2.rho(n=nn, mu1=0.8, rho=myrho, exch=TRUE)
(mytab <- table(ymat[,1], ymat[,2]))
fit = vglm(ymat ~ 1, binom2.rho(exch=TRUE))
coef(fit, matrix=TRUE)
# Example 2
x = sort(runif(nn))
mu1 = probit(-2+4*x, inverse=TRUE)
mu2 = probit(-1+3*x, inverse=TRUE)
dmat = dbinom2.rho(mu1=mu1, mu2=mu2, rho=myrho)
ymat = rbinom2.rho(n=nn, mu1=mu1, mu2=mu2, rho=myrho)
fit2 = vglm(ymat ~ x, binom2.rho)
coef(fit2, matrix=TRUE)
## Not run:
matplot(x, dmat, lty=1:4, col=1:4, type="l", main="Joint probabilities",
ylim=0:1, lwd=2, ylab="Probability")
legend(x=0.25, y=0.9, lty=1:4, col=1:4, lwd=2,
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)