R: Bivariate Logits and Log Odds Ratio

blogits {vcdExtra} | R Documentation

## Bivariate Logits and Log Odds Ratio

### Description

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.

### Usage

    blogits(Y, add, colnames, row.vars, rev=FALSE)

### Arguments

`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 `any(Y)==0` and 0 otherwise.
`colnames` | Names for the columns of the results. The default is `c("logit1", "logit2", "logOR")`. If less than three names are supplied, the remaining ones are filled in from the default.
`row.vars` | A data frame or matrix giving the factor levels of one or more factors corresponding to the rows of `Y`
`rev` | A logical, indicating whether the order of the columns in `Y` should be reversed.

### Details

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.

### Value

A data frame with `nrow(Y)` rows and `3 + ncol(row.vars)` columns

### Author(s)

Michael Friendly

### References

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.

### See Also

`vglm`

### Examples

    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

[Package vcdExtra version 0.7-1 Index]