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

dena

GitHub issues GitHub All Releases

dena is an R package that aids in preprocessing, modeling, and visualization of categorical time-to-event data and egocentric social network dynamics. This readme file will show you

  1. how to install and load the dena package
  2. examples of how denacan be used for preprocessing nested time-to-event data
  3. how to use dena's wrapper functions to estimate competing multistate models
  4. examples of how denacan be used to visualize data and model results, for example:
library(dena)
data(simdat2)
fit <- cmm(Surv(time, type) ~ Covariate2 + Covariate3 + (1 | id), dat = simdat2, verbose = F)
plot.cmm(fit[[1]])

1. Installation

You can install the development version of dena from GitHub with:

# install.packages("devtools")
devtools::install_github("timonelmer/dena")

dena can be loaded with the following function

library(dena)

2. Preprocessing functions

When analyzing (categorical) time-to-event data of multiple participants, we enounter often data of the following format:

data(simdat2) # loading the example dataset

head(simdat2[,c(1,2,3,7,5)])

with the meanCenteringNested function, we can mean center variables up to three nesting layers (e.g., within participants, within burst, within week).

simdat2 <- meanCenteringNested(dat = simdat2, 
                               vars = c("Covariate1","Covariate2"), 
                               nestVars = "id", 
                               verbose = F) 

head(simdat2[,c("id","Covariate1","Covariate1_id_MeanC","Covariate1_id_Mean")])

or we can lag variables:

simdat2 <- lagVarsNested(dat = simdat2, 
                         lags = 1,
                         vars = c("Covariate1","Covariate2"), 
                         nestVars = "id", 
                         verbose = F) 

head(simdat2[,c("id","Covariate1","Covariate1Lag1")])

3. Estimation functions

The cmm function, for example, is a wrapper function for fitting multiple coxme functions with multiple categorical target states (a so-called competing risk model)

fit <- cmm(formula = Surv(time, type) ~ Covariate2 + Covariate3 + (1  |id), dat = simdat2, 
           catVar = "type", from = NULL, verbose = F)

fit[[1]] # summary of fixed effects estimates

4. Visualization functions

4.1 Describing the data visually

data(simdat)
survivalFunction(simdat, "time")

Visualizing the transitions between (interaction) states

plotTransitionNetwork(dat = simdat2, title = "ID = all", type ="sum",catVar = "type")

4.2 Visualizing model results

Visualizing coxme and coxph model estimates:

model1 <- coxme(Surv(time, event) ~ Covariate1 + Covariate2 + (1 | id), dat = simdat2)
plot.coxme(model1)

Visualizing multistate model results:

fit <- cmm(Surv(time, type) ~ Covariate2 + Covariate3 + (1 | id), dat = simdat2)
plot.cmm(fit[[1]])


timonelmer/dena documentation built on April 15, 2023, 11:51 p.m.