项目作者: youjin1207

项目描述 :
Deriving adjusted relative risk from logistic regression
高级语言: R
项目地址: git://github.com/youjin1207/logisticRR.git
创建时间: 2018-08-15T19:06:56Z
项目社区:https://github.com/youjin1207/logisticRR

开源协议:GNU General Public License v3.0

下载


Travis-CI Build Status
DOI
![Downloads badge](http://cranlogs.r-pkg.org/badges/logisticRR)

![version badge](http://www.r-pkg.org/badges/version-last-release/logisticRR)

Overview

Package information

Installation

You can download the package by:

  1. install.packages("logisticRR")
  2. library(logisticRR)

or you can directly download the development version from author’s Github

  1. install.packages("devtools")
  2. library(devtools)
  3. install_github("youjin1207/logisticRR")

Usage

Here is a R vignettes for guidance. Or you can access to vignettes via:

  1. install_github("youjin1207/logisticRR", build_vignettes = TRUE)
  2. library(logisticRR)
  3. vignette("logisticRR", package = "logisticRR")

Example

generate hypothetical data

  1. n <- 500
  2. set.seed(1234)
  3. X <- rbinom(n, 1, 0.3)
  4. W <- rbinom(n, 1, 0.3); W[sample(1:n, n/3)] = 2
  5. Z <- rep(0, n)
  6. Z[sample(1:n, n/2)] <- "female"; Z <- ifelse(Z == 0, "male", Z)
  7. dummyZ <- ifelse(Z == "female", 1, 0)
  8. Y <- rbinom(n, 1, plogis(X - W + 2*dummyZ))
  9. dat <- as.data.frame(cbind(Y, X, W, Z))
  10. dat$X <- as.numeric(dat$X); dat$X <- ifelse(dat$X == 2, 1, 0)
  11. dat$Y <- as.numeric(dat$Y); dat$Y <- ifelse(dat$Y == 2, 1, 0)
  12. dat$W <- as.factor(dat$W)
  13. dat$Z <- as.factor(dat$Z)
  1. simresult <- logisticRR(Y ~ X + W + Z, data = dat, boot = TRUE, n.boot = 200)
  2. var(simresult$boot.rr)
  3. simresult$delta.var
  4. simresult$RR
  1. nominalresult <- logisticRR(Y ~ W + X + Z, data = dat, boot = TRUE, n.boot = 200)
  2. var(nominalresult$boot.rr)
  3. nominalresult$delta.var
  4. nominalresult$RR

multivariate logistic regression

When reponse variable takes more than two values, multinomial logistic regression is widely used to reveal association between the response variable and exposure variable. In that case, relative risk of each category compared to the reference category can be considered, conditional on other fixed covariates. Other than (adjusted) relative risk, relative risks ratio (RRR) is often of interest in multinomial logistic regression.

  1. dat$multiY <- ifelse(dat$X == 1, rbinom(n, 1, 0.8) + dat$Y, rbinom(n, 1, 0.2) + dat$Y)
  2. multiresult <- multiRR(multiY ~ X + W + Z, data = dat, boot = TRUE, n.boot = 1000)
  3. apply(multiresult$boot.rr, 2, sd)
  4. sqrt(multiresult$delta.var)
  5. multiresult$RRR
  6. multiresult$RR

Similar to the binary reponse, in multinomial logistic regression model, categorical exposure variable can be introduced; in this case, baseline value and comparative value of exposure variable should be specified.

  1. multinresult <- multinRR(multiY ~ W + X + Z, data = dat, basecov = 0, comparecov = 1, boot = TRUE, n.boot = 1000)
  2. apply(multinresult$boot.rr, 2, sd)
  3. sqrt(multinresult$delta.var)
  4. multinresult$RRR
  5. multinresult$RR