blogits | R Documentation |
This function calculates the log odds and log odds ratio for two binary responses classified by one or more stratifying variables.
It is useful for plotting the results of bivariate logistic regression
models, such as those fit using vglm
in the
VGAM.
blogits(Y, add, colnames, row.vars, rev=FALSE)
Y |
A four-column matrix or data frame whose columns correspond to the 2 x 2 combinations of two binary responses. |
add |
Constant added to all cells to allow for zero frequencies. The default
is 0.5 if |
colnames |
Names for the columns of the results. The default is
|
row.vars |
A data frame or matrix giving the factor levels of one or more factors
corresponding to the rows of |
rev |
A logical, indicating whether the order of the columns in |
For two binary variables with levels 0,1 the logits are calculated
assuming the columns in Y
are given in the order
11, 10, 01, 00, so the logits give the log odds of the 1 response
compared to 0.
If this is not the case, either use rev=TRUE
or supply
Y[,4:1]
as the first argument.
A data frame with nrow(Y)
rows and 3 + ncol(row.vars)
columns
Michael Friendly
Friendly, M. and Meyer, D. (2016). Discrete Data Analysis with R: Visualization and Modeling Techniques for Categorical and Count Data. Boca Raton, FL: Chapman & Hall/CRC. http://ddar.datavis.ca.
vglm
data(Toxaemia)
tox.tab <- xtabs(Freq~class + smoke + hyper + urea, Toxaemia)
# reshape to 4-column matrix
toxaemia <- t(matrix(aperm(tox.tab), 4, 15))
colnames(toxaemia) <- c("hu", "hU", "Hu", "HU")
rowlabs <- expand.grid(smoke=c("0", "1-19", "20+"), class=factor(1:5))
toxaemia <- cbind(toxaemia, rowlabs)
# logits for H and U
logitsTox <- blogits(toxaemia[,4:1],
add=0.5,
colnames=c("logitH", "logitW"),
row.vars=rowlabs)
logitsTox
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.