Title: | Adjusted Relative Risk from Logistic Regression |
---|---|
Description: | Adjusted odds ratio conditional on potential confounders can be directly obtained from logistic regression. However, those adjusted odds ratios have been widely incorrectly interpreted as a relative risk. As relative risk is often of interest in public health, we provide a simple code to return adjusted relative risks from logistic regression model under potential confounders. |
Authors: | Youjin Lee |
Maintainer: | Youjin Lee <[email protected]> |
License: | GPL (>=3) | file LICENSE |
Version: | 0.3.0 |
Built: | 2024-11-01 03:54:16 UTC |
Source: | https://github.com/youjin1207/logisticrr |
When response variable is binary and exposure variable is binary or continuous, this function derives adjusted relative risks conditional on fixed other confounders' value from logistic regression.
logisticRR(formula, basecov = 0, fixcov = NULL, data, boot = FALSE, n.boot = 100)
logisticRR(formula, basecov = 0, fixcov = NULL, data, boot = FALSE, n.boot = 100)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than an exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
boot |
a logical value whether bootstrap samples are generated or not. Defaults to |
n.boot |
if |
fit |
an object of class |
RR |
(conditional) relative risk in response under exposure at baseline ( |
delta.var |
estimated variance of relative risk ( |
boot.rr |
if |
boot.var |
estimated sampled variance using bootstraps if |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- logisticRR(Y ~ X + W, basecov = 0, data = dat, boot = TRUE, n.boot = 200)
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- logisticRR(Y ~ X + W, basecov = 0, data = dat, boot = TRUE, n.boot = 200)
Inference on relative risk under multinomial logistic regression
multinRR(formula, basecov, comparecov, fixcov = NULL, data, boot = FALSE, n.boot = 100)
multinRR(formula, basecov, comparecov, fixcov = NULL, data, boot = FALSE, n.boot = 100)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to |
comparecov |
a value of exposure variable for comparison. Defaults to the first level. |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than the exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
boot |
a logical value whether bootstrap samples are generated or not. Defaults to |
n.boot |
if |
fit |
an object of class |
RRR |
(adjusted) relative risk ratio of |
RR |
(adjusted) relative risk of |
delta.var |
estimated variance of relative risk ( |
boot.rr |
if |
boot.rrr |
if |
boot.var |
estimated sampled variance using bootstraps if |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) multiY <- ifelse(X == 1 , rbinom(n, 1, 0.7) + Y, rbinom(n, 1, 0.2) + Y) print(table(multiY)) dat <- as.data.frame(cbind(multiY, X, W)) dat$W <- as.factor(dat$W) result <- multinRR(multiY ~ W + X, basecov = 0, comparecov = 1, data = dat, boot = TRUE) print(apply(result$boot.rr, 2, sd)) # estimated standard errors using Delta method print(sqrt(result$delta.var)) # estimated standard errors using bootstrap
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) multiY <- ifelse(X == 1 , rbinom(n, 1, 0.7) + Y, rbinom(n, 1, 0.2) + Y) print(table(multiY)) dat <- as.data.frame(cbind(multiY, X, W)) dat$W <- as.factor(dat$W) result <- multinRR(multiY ~ W + X, basecov = 0, comparecov = 1, data = dat, boot = TRUE) print(apply(result$boot.rr, 2, sd)) # estimated standard errors using Delta method print(sqrt(result$delta.var)) # estimated standard errors using bootstrap
Inference on relative risk under multinomial logistic regression
multiRR(formula, basecov = 0, fixcov = NULL, data, boot = FALSE, n.boot = 100)
multiRR(formula, basecov = 0, fixcov = NULL, data, boot = FALSE, n.boot = 100)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than the exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
boot |
a logical value whether bootstrap samples are generated or not. Defaults to |
n.boot |
if |
fit |
an object of class |
RRR |
(adjusted) relative risk ratio of |
RR |
(adjusted) relative risk of |
delta.var |
estimated variance of relative risk ( |
boot.rr |
if |
boot.rrr |
if |
boot.var |
estimated sampled variance using bootstraps if |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- multiRR(W ~ X + Y, basecov = 0, data = dat, boot = TRUE, n.boot = 100) print(apply(result$boot.rr, 2, sd)) # estimated standard errors using Delta method print(sqrt(result$delta.var)) # estimated standard errors using bootstrap
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- multiRR(W ~ X + Y, basecov = 0, data = dat, boot = TRUE, n.boot = 100) print(apply(result$boot.rr, 2, sd)) # estimated standard errors using Delta method print(sqrt(result$delta.var)) # estimated standard errors using bootstrap
When response variable is binary and exposure variable is categorical this function derives adjusted relative risks conditional on fixed other confounders' value from logistic regression.
nominalRR(formula, basecov = NULL, comparecov = NULL, fixcov = NULL, data, boot = FALSE, n.boot = 100)
nominalRR(formula, basecov = NULL, comparecov = NULL, fixcov = NULL, data, boot = FALSE, n.boot = 100)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to the first level. |
comparecov |
a value of exposure variable for comparison. Defaults to the first level. |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than an exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
boot |
a logical value whether bootstrap samples are generated or not. Defaults to |
n.boot |
if |
fit |
an object of class |
RR |
(conditional) relative risk in response under exposure at baseline ( |
delta.var |
estimated variance of relative risk ( |
boot.rr |
if |
boot.var |
estimated sampled variance using bootstraps if |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2 dat <- as.data.frame(W) dat$X <- sample( c("low", "medium", "high"), size = n, replace = TRUE) dat$Y <- ifelse(dat$X == "low", rbinom(n, 1, plogis(W + 0.5)), ifelse(dat$X == "medium", rbinom(n, 1, plogis(W + 0.2)), rbinom(n, 1, plogis(W - 0.4)) )) dat$X <- as.factor(dat$X) result <- nominalRR(Y ~ X + W, basecov = "low", comparecov = "high", data = dat, boot = TRUE, n.boot = 200)
n <- 500 set.seed(1234) W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2 dat <- as.data.frame(W) dat$X <- sample( c("low", "medium", "high"), size = n, replace = TRUE) dat$Y <- ifelse(dat$X == "low", rbinom(n, 1, plogis(W + 0.5)), ifelse(dat$X == "medium", rbinom(n, 1, plogis(W + 0.2)), rbinom(n, 1, plogis(W - 0.4)) )) dat$X <- as.factor(dat$X) result <- nominalRR(Y ~ X + W, basecov = "low", comparecov = "high", data = dat, boot = TRUE, n.boot = 200)
Print adjusted relative risk using multinomial logistic regression under nominal exposure variable.
printmnRR(formula, basecov, comparecov, fixcov = NULL, data)
printmnRR(formula, basecov, comparecov, fixcov = NULL, data)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to |
comparecov |
a value of exposure variable for comparison. Defaults to the first level. |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than the exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
fit |
an object of class |
RRR |
(adjusted) relative risk ratio of |
RR |
(adjusted) relative risk of |
delta.var |
estimated variance of relative risk ( |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) multiY <- ifelse(X == 1 , rbinom(n, 1, 0.7) + Y, rbinom(n, 1, 0.2) + Y) print(table(multiY)) dat <- as.data.frame(cbind(multiY, X, W)) dat$W <- as.factor(dat$W) result <- printmnRR(multiY ~ W + X, basecov = 0, comparecov = 1, data = dat)
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) multiY <- ifelse(X == 1 , rbinom(n, 1, 0.7) + Y, rbinom(n, 1, 0.2) + Y) print(table(multiY)) dat <- as.data.frame(cbind(multiY, X, W)) dat$W <- as.factor(dat$W) result <- printmnRR(multiY ~ W + X, basecov = 0, comparecov = 1, data = dat)
Print adjusted relative risk using multinomial logistic regression under binary or ordinal exposure variable.
printmRR(formula, basecov = 0, fixcov = NULL, data)
printmRR(formula, basecov = 0, fixcov = NULL, data)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than the exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
fit |
an object of class |
RRR |
(adjusted) relative risk ratio of |
RR |
(adjusted) relative risk of |
delta.var |
estimated variance of relative risk ( |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- printmRR(W ~ X + Y, basecov = 0, data = dat)
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- printmRR(W ~ X + Y, basecov = 0, data = dat)
Print adjusted relative risk under nominal exposure variable.
printnRR(formula, basecov, comparecov, fixcov = NULL, data)
printnRR(formula, basecov, comparecov, fixcov = NULL, data)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to the first level. |
comparecov |
a value of exposure variable for comparison. Defaults to the first level. |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than an exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
fit |
an object of class |
RR |
(adjusted) relative risk in response under exposure at baseline ( |
delta.var |
estimated variance of relative risk ( |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
Youjin Lee
n <- 500 set.seed(1234) W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2 dat <- as.data.frame(W) dat$X <- sample( c("low", "medium", "high"), size = n, replace = TRUE) dat$Y <- ifelse(dat$X == "low", rbinom(n, 1, plogis(W + 0.5)), ifelse(dat$X == "medium", rbinom(n, 1, plogis(W + 0.2)), rbinom(n, 1, plogis(W - 0.4)) )) dat$X <- as.factor(dat$X) result <- printnRR(Y ~ X + W, basecov = "high", comparecov = "low", data = dat)
n <- 500 set.seed(1234) W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2 dat <- as.data.frame(W) dat$X <- sample( c("low", "medium", "high"), size = n, replace = TRUE) dat$Y <- ifelse(dat$X == "low", rbinom(n, 1, plogis(W + 0.5)), ifelse(dat$X == "medium", rbinom(n, 1, plogis(W + 0.2)), rbinom(n, 1, plogis(W - 0.4)) )) dat$X <- as.factor(dat$X) result <- printnRR(Y ~ X + W, basecov = "high", comparecov = "low", data = dat)
Print adjusted relative risk under binary or ordinal exposure variable.
printRR(formula, basecov = 0, fixcov = NULL, data)
printRR(formula, basecov = 0, fixcov = NULL, data)
formula |
a formula term that is passed into |
basecov |
a baseline value of exposure variable. Defaults to |
fixcov |
a data frame of fixed value for each of adjusted confounders. If there is no confounder other than an exposure variable of interest, |
data |
a data frame containing response variable and all the terms used in |
fit |
an object of class |
RR |
(adjusted) relative risk in response under exposure at baseline ( |
delta.var |
estimated variance of relative risk ( |
fix.cov |
a data frame of fixed value for each of adjsuted confounders. |
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- printRR(Y ~ X + W, basecov = 0, data = dat)
n <- 500 set.seed(1234) X <- rbinom(n, 1, 0.3) W <- rbinom(n, 1, 0.3) W[sample(1:n, n/3)] = 2 Y <- rbinom(n, 1, plogis(X - W)) dat <- as.data.frame(cbind(Y, X, W)) result <- printRR(Y ~ X + W, basecov = 0, data = dat)