mclements / rstpm2

An R package for generalised survival models
28 stars 11 forks source link

Minor typo and request for new feature for rpstm2 - predict smooth derivatives #23

Closed StephenKay67 closed 1 month ago

StephenKay67 commented 2 years ago

Great package - many thanks (wish I had your maths/programming brain). There is a small typo in the Cran manual - for both nsx and nsxD help pages, the description for argument "derivs" contains the line,

"an order of 1 constrains the zero, first and second derivatives to zero (f(x)=f’(x)=f”(x)=0)"
Pretty sure this should be, "an order of 0 constrains the ..."

Real purpose is to request that in the predict command for rpstm2 objects there is an option to predict the equivalent of what is held in rpstm2Object@xd, for new data values entered in the predict command. This will complement the "lpmatrix" type for predict. This will facilitate manual computation of the hazard function (not relying on predict) - great to have for facilitating computing confidence intervals under the method used in Chris Jackson's flexsurv.

Thanks also for creating "splines2" for Julia - I'm trying to decipher that code to understand creating natural splines via B-splines (hopefully easier than going through mix of R and C/C++ code). Doubt I'll understand underlying theory - can't locate anything on it (especially using QR decomposition) hence part of my admiration of your abilities. Best, Steve

mclements commented 1 month ago

Stephen,

Belatedly, I have now (a) corrected the two typos and (b) added type="lpmatrixD" to the predict methods.

Thank you for this -- and apologies for the slow reply.

Sincerely, Mark.

mclements commented 1 month ago

As an example of (b):

library(rstpm2)
fit = stpm2(Surv(rectime,censrec==1)~hormon,data=brcancer)
m = predict(fit, newdata=data.frame(hormon=1), grid=TRUE, type="lpmatrix")
m2 = predict(fit, newdata=data.frame(hormon=1), grid=TRUE, type="lpmatrixD")
stekay commented 3 weeks ago

Great - thanks Mark - appreciate your work. Best, Steve