Running examples in ‘greyzoneSurv-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: greyzone.funcs
> ### Title: Fit a Grey-Zone Model with Survival Data
> ### Aliases: em.func cov.func greyzone.func
> 
> ### ** Examples
> 
> #use the package data "mydata" to fit the grey-zone model in 3 steps
> data(mydata)
> dim(mydata)
[1] 300   4
> head(mydata)
  time event           x xhigh
1 1451     0 -0.44577826     0
2  920     1 -1.20585657     0
3 1607     0  0.04112631     0
4  490     1  0.63938841     0
5 1315     0 -0.78655436     0
6 1641     0 -0.38548930     0
> 
> #~step 1: extract information needed for fitting the model and 
> #make some initial guesses of some parameter values 
> n=nrow(mydata)
> y=mydata$time/365.25
> delta=mydata$event
> score=mydata$x
> x=cbind(rep(1, n), score)
> 
> #~step 2: get EM estimates and variance-covariance matrix
> results.em=em.func(initial.values=NULL, y=y, delta=delta, x=x)

....calculating parameter estimates using EMWarning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
Warning in log(lam) : NaNs produced
> is.na(results.em$em.error)
[1] TRUE
> #only if above is true, you should proceed; otherwise try a different set 
> #of intial values and try calling em.func again
> names(results.em)
[1] "em.iterations" "estimates.p"   "nQ.vcov"       "em.error"     
> #after you successfully get an EM solution proceed to get the variance-covariance matrix
> results.cov=cov.func(results.em, y=y, delta=delta, x=x)

....calculating covariance matrix using Lous method and simulations> names(results.cov)
[1] "par.est"    "final.vcov" "final.se"   "par.est.ll" "par.est.ul"
[6] "pvalue"     "exp.p"     
> 
> #~step 3: when there are no errors above proceed to calculate the grey zone
> results=greyzone.func(results.cov, y, delta, x, plot.logistic=FALSE)

....finding grey zone in logistic curves
> names(results)
[1] "greyzone.ll"   "greyzone.ul"   "score"         "score.sim"    
[5] "pi.est.sim"    "exp.p"         "pi.est.ul.sim" "pi.est.ll.sim"
> !is.na(results$greyzone.ll) & !is.na(results$greyzone.ul)
[1] TRUE
> #only when above is true, you have a grey-zone solution and you can proceed
> #sometimes there is not a grey-zone solution even if the EM fitting is successful.
> #In that case, it means the grey-zone model is not a good fit for the data.
> score3=rep(0, n)
> score3[score>=results$greyzone.ll & score<results$greyzone.ul]=1
> score3[score>=results$greyzone.ul]=2
> #if you get through steps 1-3, you are done fitting the grey-zone model!
> 
> #now you may want to compare with a 2-group model, so fit a 2-group model 
> res=bestcut2(data=mydata, stime='time', sind='event', var='x')

Looking for best cutoff to divide subjects into 2 groups...
best cutoff = 1.660847
There are p values significant after Bonferroni correction: TRUE
P-value at best cutoff:  0 

> score2=res[,'bestcut2']
> 
> #then compare the 2-group and grey-zone models, but note here we compare on the training data
> #ideally we want to compare them on a test data set
> cox.2group=cox.summary(stime=mydata$time, sind=mydata$event, var=score2)
Error in model.frame.default(Surv(stime, sind) ~ var, data = NULL, subset = NULL,  : 
  'data' must be a data.frame, environment, or list
Calls: cox.summary ... biVar -> do.call -> model.frame -> model.frame.default
Execution halted