Learn R Programming

LogisticDx (version 0.3)

OR: Odds ratio for binary regression models fit with glm

Description

Odds ratio for binary regression models fit with glm

Usage

OR(x, ...)

# S3 method for default OR(x, ...)

# S3 method for glm OR( x, ..., newdata = rep(1L, length(stats::coef(x))), ci = TRUE, alpha = 0.95, what = c("model", "all", "data") )

Arguments

x

A numeric object containing probabilities \(P\).

I.e. the range of \(P\) must be \(0\) to \(1\).

The odds ratio \(OR\) is given by: $$OR_i = \frac{P_i}{1-P_i} = \frac{\frac{P_1}{1-P_1}}{\frac{P_0}{1-P_0}} = \frac{\mathrm{odds_1}}{\mathrm{odds_0}}$$

There is a method for regression models with class(x)==glm and x$family$family == "binomial".

...

Not used.

newdata

A vector of new variables to use.

There should be one value, in sequence, for each coefficient in the model.

By default, values are calculated for a change in the value of the coefficient for the predictor from \(0\) to \(1\).

For continuous predictors changes of \(> 1\) unit may have more practical significance.

ci

If ci=TRUE (the default), include a confidence interval for \(P_i\) and \(OR_i\) in the returned values.

alpha

Used to cacluate the confidence interval, which is: $$\mathrm{CI} = x \pm Z_{1 - \alpha} \sigma$$ where the normal distribution \(Z \sim N (0,1)\) and \(\sigma\) is the standard deviation.

what

See Value below.

Value

A data.table. Columns give the model, the value of the link function and the associated probability \(P_i\) and odds ratio \(OR_i\). If ci=TRUE, will also give upper and lower bounds of the confidence intervals for these values. Rows are determined by what:

what="model"

The value of the link function is given for the full model. If an intercept term is included, the value if given with and without the intercept.

what="all"

The value of the link function is given for each combination of coefficients in the model.

what="data"

The value of the link function is given for each set of predictors in the data with which the model was fit. This option will ignore the argument newdata.

See Also

?stats::predict.glm

Examples

Run this code
# NOT RUN {
if(require("graphics")){
    plot(x <- seq(from=0.1, to=0.9, by=0.05), y=OR(x))}
# }
# NOT RUN {
## H&L 2nd ed. Table 1.3. Page 10.
data(ageChd)
summary(g1 <- glm(chd ~ age, data=ageChd, family=binomial))
OR(g1)
attributes(OR(g1))
## Table 1.4. Page 20.
stats::vcov(g1)
## Table 2.3. Page 38.
data(lbw)
summary(g1 <- glm(LOW ~ LWT + RACE, data=lbw, family=binomial))
## Table 2.4. Page 42.
vcov(g1)
ageChd$gr54 <- ageChd$age > 54
OR(glm(chd ~ gr54, data=ageChd, family=binomial))

# }

Run the code above in your browser using DataLab