knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "90%",
  dpi = 150
)

bicopula

R build status Codecov test coverage

Installation

You can install the development version of {bicopula} from GitHub with:

# install.packages("devtools")
devtools::install_github("ellessenne/bicopula")

Example

This is a basic example. Simulating some bivariate data:

library(bicopula)

set.seed(42)
N <- 500
df <- data.frame(
  age = runif(N, 20, 40),
  sex = rbinom(N, size = 1, prob = 0.5),
  biomarker = runif(N, 0, 120)
)

simdata <- simulate_bisurv(
  dist1 = Exponential$new(lambda = 0.1),
  dist2 = Weibull$new(lambda = 0.1, gamma = 1.5),
  formula1 = ~ age + sex,
  formula2 = ~ age + biomarker,
  data = df,
  beta1 = c(age = 0.01, sex = 0.5),
  beta2 = c(age = 0.01, biomarker = 0.005),
  copula = copula::frankCopula(param = 5)
)

head(simdata)

with(simdata, plot(eventtime1, eventtime2))

Then, fitting a bivariate survival model:

df <- cbind(df, simdata)

bisurvreg(
  formula1 = Surv(eventtime1, status1) ~ age + sex,
  distribution1 = "exponential",
  formula2 = Surv(eventtime2, status2) ~ age + biomarker,
  distribution2 = "weibull",
  copula = "frank",
  data = df
)

Lots of work needs to be done to make this pretty, but as a proof-of-concept it doesn't feel too bad!



ellessenne/bicopula documentation built on Dec. 20, 2021, 4:19 a.m.