jgellar / pcox

Penalized Cox regression models
1 stars 0 forks source link

Errors in `pcox.testing2.R` #27

Closed fabian-s closed 9 years ago

fabian-s commented 9 years ago
d> # TIME-VARYING MODEL
d> fit2.2 <- pcox(Surv(time, event) ~ p(x, linear=FALSE, tv=T) +
+                  male, data=data2)
 Error in create.tt.func(limits, linear, tv, basistype, sind, integration,  : 
  Unrecognized input for limits argument 
6 stop("Unrecognized input for limits argument") at create.tt.func.R#38
5 create.tt.func(limits, linear, tv, basistype, sind, integration, 
    standardize, s.transform, t.transform, basisargs, method, 
    eps, map) at p.R#144
4 p(x, linear = FALSE, tv = T, method = "aic", eps = 1e-06) 
3 eval(expr, envir, enclos) 
2 eval(terms[[i]], envir = evalenv, enclos = frmlenv) at pcox.R#165
1 pcox(Surv(time, event) ~ p(x, linear = FALSE, tv = T) + male, 
    data = data2) 
d> fit3.1 <- pcox(Surv(time,event) ~ bf(myX, bs="ps", sind=sind) + male, data=data3)
 Error in pcoxTerm(x, limits = limits, linear = linear, tv = FALSE, basistype = basistype,  : 
  argument "s0" is missing, with no default 
3 pcoxTerm(x, limits = limits, linear = linear, tv = FALSE, basistype = basistype, 
    sind = sind, integration = integration, standardize = standardize, 
    s.transform = s.transform, t.transform = t.transform, basisargs = basisargs, 
    method = method, eps = eps, smooth = smooth) at create.xt.func.R#35
2 xt.i(trm$x) at pcox.R#186
1 pcox(Surv(time, event) ~ bf(myX, bs = "ps", sind = sind) + male, 
    data = data3) 
d> fit5.1c <- pcox(Surv(time,event) ~ male +
+                   hf(myX, sind = sind2, s.transform = "s/t", dbug=TRUE,
+                      bs="pb", xt="linear"),
+                 data=data5)
 Error in UseMethod("smooth.construct") : 
  no applicable method for 'smooth.construct' applied to an object of class "pb.smooth.spec" 
9 smooth.construct(object, dk$data, dk$knots) 
8 smooth.construct3(object, data, knots) 
7 smoothCon(eval(as.call(newcall)), data = evaldat, knots = NULL, 
    absorb.cons = TRUE) at pcoxTerm.R#135
6 pcoxTerm(data, limits, linear, tv, basistype, sind, integration, 
    standardize, s.transform, t.transform, basisargs, method, 
    eps, smooth, s0, t0, t) at create.tt.func.R#136
5 (tt[[i]])(mf[[timetrans$var[i]]], Y[, 1], strats, weights) 
4 coxph(formula = Surv(time, event) ~ male + tt(s(myX.smat, myX.tmat, 
    by = myX.LX)), data = pcoxdata, x = TRUE, tt = tt.funcs, 
    na.action = function (object, ...) 
    object, iter.max = 100, outer.max = 50) 
3 eval(expr, envir, enclos) 
2 eval(newcall) at pcox.R#252
1 pcox(Surv(time, event) ~ male + hf(myX, sind = sind2, s.transform = "s/t", 
    dbug = TRUE, bs = "pb", xt = "linear"), data = data5) 
jgellar commented 9 years ago

I think I fixed the problem with frmlenv/newfrmlenv, could you take a look at the latest commit and confirm that what I did fixes the problem? My tests are running fine, but I'd like confirmation there is nothing I'm missing.

fabian-s commented 9 years ago

I still get a lot of errors running pcox.testing2.R, which makes it really hard for me to get back into this. Could you split this into topic or issue-specific development files with all the stuff that's currently not working and a proper testing file that does not produce any errors and only includes working examples?

I know this is a hassle, but I believe it will make it easier for you going forward as well: whenever you make any changes you can then just run the test file and see whether your changes introduced errors into stuff that was already working, and move new features that get implemented from the development files into the tests....

> est2.1 <- coef(fit2.1)
Error in ifelse(is.null(n), default_n(sdat.i[[smooth.i$term[[1]]]]), n) : 
  could not find function "default_n"

Same error occurs for all other coef-calls for examples where I managed to create the model object.

More:


# VARIABLE-DOMAIN SCALAR TERMS
> tmp <- pcox(Surv(time,event) ~ p(male, by=x, linear=TRUE, tv=FALSE),
+             data=data2)
Error in model.frame.default(formula = Surv(time, event) ~ male, data = pcoxdata,  : 
  invalid type (list) for variable 'male'

> bhat3.1v1 <- PredictMat(fit3.1$pcox$smooth[[1]][[1]], pdata.3) %*%
  fit3.1$coef[-11]
Error: $ operator is invalid for atomic vectors
> traceback()
3: ExtractData(object, data, NULL)
2: Predict.matrix3(object, data)
1: PredictMat(fit3.1$pcox$smooth[[1]][[1]], pdata.3)
> bhat3.1 <- fit3.1$pcox$t.funcs[[1]](pdata.3) %*% fit3.1$coef[-11]
Error in matrix(sind, nrow = n, ncol = J, byrow = TRUE) : 
  non-numeric matrix extent
> traceback()
3: ExtractData(object, data, NULL)
2: Predict.matrix3(object, data)
1: PredictMat(fit3.1$pcox$smooth[[1]][[1]], pdata.3)

> fit5.1c <- pcox(Surv(time,event) ~ male +
+                   hf(myX, sind = sind2, s.transform = "s/t", dbug=TRUE,
+                      bs="pb", xt="linear"),
+                 data=data5)
 Error in UseMethod("smooth.construct") : 
  no applicable method for 'smooth.construct' applied to an object of class "pb.smooth.spec" 
jgellar commented 9 years ago

I will try to formalize the testing process. There are a couple of reasons that I've been reluctant to do this:

  1. Some of the "tests" I've been doing involve plotting the output and looking at the results (against the truth) to make sure they look alike, and this is hard to do in an automatic test
  2. Most of the new tests I've been doing involve first running one of our "stable" models, and then trying out some new feature on top of it (e.g., a new method). So the informal/in-progress testing requires me to run the stable tests all over again.

That said I agree that it's worth the effort, and that the pcox.testing2.R file has gotten a bit out of control.

jgellar commented 9 years ago

See e65ace5ad1b95846bdccf707ebc47190303766fa.

Let me know if you like the testing procedures. I have begun to write some unit tests using testthat but I'm not sure that it's worth doing?

fabian-s commented 9 years ago

Nice! Agree on the testthat part -- the important thing for me is that there's a clear separation between stuff under development and stuff that's supposed to work (and keep working whenever we make a change).

On Mon, Jun 1, 2015 at 7:40 PM, jgellar notifications@github.com wrote:

See e65ace5 https://github.com/jgellar/pcox/commit/e65ace5ad1b95846bdccf707ebc47190303766fa .

Let me know if you like the testing procedures. I have begun to write some unit tests using testthat but I'm not sure that it's worth doing?

— Reply to this email directly or view it on GitHub https://github.com/jgellar/pcox/issues/27#issuecomment-107650813.