# R/getComparisons.R In riskRegression: Risk Regression Models and Prediction Scores for Survival Analysis with Competing Risks

#### Defines functions getComparisons

```### getComparisons.R ---
#----------------------------------------------------------------------
## author: Thomas Alexander Gerds
## created: Jan  3 2016 (13:30)
## Version:
## last-updated: Jun 15 2020 (10:33)
##           By: Thomas Alexander Gerds
##     Update #: 50
#----------------------------------------------------------------------
##
### Commentary:
##
### Change Log:
#----------------------------------------------------------------------
##
### Code:
getComparisons <- function(dt,NF,N,alpha,dolist=NF:1,multi.split.test=FALSE,se.fit){
## IMPORTANT: this function assumes that the
##            data are ordered according to model,times
x=model=IF=NULL
if (length(dolist)>0){
Qnorm <- qnorm(1 - alpha/2)
data.table::rbindlist(lapply(dolist,function(g){
theta <- dt[,list(x=x[1]),by=model]
delta <- theta[model%in%g[-1]][["x"]]-theta[model==g[1]][["x"]]
if (!is.null(dt\$IF)){
se.delta <- dt[model%in%g[-1],list(se=sd(dt[model==g[1]][["IF"]]-IF)/sqrt(N)),by=model][["se"]]
p <-2*pnorm(abs(delta)/se.delta,lower.tail=FALSE)
}else{
p <- NA
}
if (se.fit==TRUE){
lower <- delta - Qnorm * se.delta
upper <- delta + Qnorm * se.delta
data.table(model=theta[model%in%g[-1]][["model"]],
reference=g[1],
delta=delta,
se=se.delta,
lower=lower,
upper=upper,
p=p)
}else{ ## only multisplit test
out <- data.table(model=theta[model%in%g[-1]][["model"]],
reference=g[1],
delta=delta)
if (multi.split.test==TRUE) out[,p:=p]
out
}
}))
} else {
NULL
}
}
#----------------------------------------------------------------------
### getComparisons.R ends here
```

## Try the riskRegression package in your browser

Any scripts or data that you put into this service are public.

riskRegression documentation built on Jan. 13, 2021, 11:12 a.m.