Closed yfyang86 closed 2 years ago
After revision, in this case, lambda should meet the following requirements:
therefore, for the rootSolve(.)
function. we need to check the root that:
0
sum(RMSTfun(time) * prob) == 1
An older version checks this, but the newer one fails.
The next version will fix this.
library(KMsurv)
library(emplik)
library(kmc)
library(rootSolve)
data(kidney)
kmc.clean <- function(kmc.time,delta){
n <- length(kmc.time)
dataOrder <- order(kmc.time, -delta)
kmc.time <- kmc.time[dataOrder]
delta <- delta[dataOrder]
FirstUnCenLocation<-which(delta==1)[1];
if (FirstUnCenLocation==n) {stop('Only one uncensored point.');}
if (FirstUnCenLocation!=1){
delta=delta[FirstUnCenLocation:n];
kmc.time=kmc.time[FirstUnCenLocation:n];
}
delta[length(kmc.time)]=1;
return (list(kmc.time=kmc.time,delta=delta));
}
RMSTfun <- function(x) {pmin(x,20) - 15}
x = kidney$time
d = kidney$delta
inputData = kmc.clean(x, d)
Gmat = RMSTfun(inputData$kmc.time)
## `kmc_native` is the KMC Solver (1-dim) which returns `prob`
fun.C <- Vectorize(
function(lam){
return(sum(Gmat*kmc_native(inputData$delta, lam*Gmat)));
}
)
All = uniroot.all(fun.C, c(-3, 2), tol = 1e-8)
s = el.cen.EM2( x = kidney$time, d = kidney$delta, fun = RMSTfun, mu = 0, maxit = 50)
curve(fun.C(x), -3, 5,main = "uniroot.all", ylim=c(-10,10))
points(All, y = rep(0, length(All)), pch = 16, cex = 2, col='steelblue')
points(-s$lam, y = 0, pch = 16, cex = 2, col='red')
Verison: 0.2+ BUG: root solving procedure causes -2LLR to be negative.
The potential issue is that
rootSolve
package changes in the past.emplik
results:kmc
results