I'm doing stratified cox regression in R with the survival package:
cox <- coxph(response~strata(x), data=data)
This works fine, but when using the sampling package the strata function from the survival package is hidden and cannot be used directly.
However, calling it with the explicit namespace survival::strata
does not create a stratified analysis:
library(survival)
# sample data
mort28day <- c(1,0,1,0,0,0,0,1,0,0,0,1,1,0,1,0,0,1,0,1,1,1,1,0,1,1,1,0,0,1)
daysurv <- c(4,29,24,29,29,29,29,19,29,29,29,3,9,29,15,29,29,11,29,5,13,20,22,29,16,21,9,29,29,15)
levo <- c(0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0)
acbi30 <- data.frame(mort28day, daysurv, levo)
# create survival object
test.Surv <- Surv(acbi30$daysurv, acbi30$mort28day)
test.surv_fit_1 <- survfit(coxph(test.Surv~strata(levo), data=acbi30))
test.surv_fit_2 <- survfit(coxph(test.Surv~survival::strata(levo), data=acbi30))
So,
test.surv_fit_1$strata
# levo=0 levo=1
# 12 3
test.surv_fit_2$strata
# NULL
Why is this the case and how can I access this function when it is hidden by sampling::strata
(apart from detaching the sampling package ;-)
I'm using R version 2.15.2
Thanks, DeltaKappa
Update:
As a workaround to using survival::strata together with the sampling package I did
library(survival)
library(sampling, pos="package:base")
which loads the sampling package with a low search priority right above the base package. Then I can do
coxph(test.Surv~strata(levo), data=acbi30)
while calling sampling::strata
explicitly.