jgellar / pcox

Penalized Cox regression models
1 stars 0 forks source link

time varying nonlinear effects of scalars seem to work rather badly #43

Open fabian-s opened 7 years ago

fabian-s commented 7 years ago
>   fit <- pcox(Surv(time, event) ~ p(z, linear=FALSE, tv=T), data=dat)
Error in coxph(formula = Surv(time, event) ~ tt(s(t, z)), data = pcoxdata,  : 
  (converted from warning) X matrix deemed to be singular; variable 28

Enter a frame number, or 0 to exit   

1: pcox(Surv(time, event) ~ p(z, linear = FALSE, tv = T), data = dat)
2: pcox.R#321: eval(newcall)
3: eval(expr, envir, enclos)
4: coxph(formula = Surv(time, event) ~ tt(s(t, z)), data = pcoxdata, x = TRUE, tt = tt.funcs, na.acti
5: warning(msg)
set.seed(12354)
N <- 5000 #!!!
J <- 200
x <- runif(N, 0, 2*pi)
z <- rnorm(N)
male <- rbinom(N, size = 1, prob=.5)
somefactor <- factor(sample(1:3, N, replace = TRUE))
sind <- seq(0,1,length=J)
X <- genX(N, sind)
K <- 100
Z <- genX(N, seq(0,1,length=K))
L <- 100
set.seed(121212)
eta <- matrix(sin(2 * pi*(1:J)/J) %x% (pnorm(z) - .5), nrow=N, ncol=J)
dat <- simTVSurv(eta, data.frame(z=z, male = male, fmale=factor(male)))
fit <- pcox(Surv(time, event) ~ p(z, linear=FALSE, tv=T), data=dat)
est <- coef(fit)
pred <- predict(fit)
cor(as.vector(pred),
      as.vector(eta[, sort(unique(Surv(dat$time, dat$event)[dat$event == 1]))]), 
      use = "pairwise")
#[1] 0.450189
range(eta, na.rm=T)
# [1] -0.4997849  0.4997849
range(pred, na.rm=T)
# [1] -0.939554  1.095675
jgellar commented 7 years ago

Were there tests for this type of model in the testing document already, or did you add these? If there were already tests, I would have expected them to run fine at some point, meaning that we changed something at some point to cause the bug.

fabian-s commented 7 years ago

I added those because it seemed like an obvious thing to try. I'll add a check for this type of term saying they are not implemented yet.