This error appears on Windows since the release of optimx
version 2018-7.10. The issue was raised on Stackoverflow, see https://stackoverflow.com/questions/52927399/renewalcount-function-in-countr.
A workaround for users is to do xtimes <- 1
before calling renewalCount()
. Another, more drastic, option is to go back to the previous release of optmix
.
I am opening the issue here for easy reference. The example below is from the Stackoverflow link above (I prepended an option()
command for debugging).
options(error = recover)
library("Countr")
library("dplyr")
library("xtable")
D=matrix(c(1:9))
Numb=matrix(c(15, 4, 5, 3, 1, 2, 1, 1, 1))
Number=data.frame(Numb)
a_weib <- renewalCount(formula = D ~ 1, data = Number, dist = "weibull",
computeHessian = FALSE, control = renewal.control(trace = 0))
Running the above code (under Windows) gives:
Error in order(-value, xtimes) : object 'xtimes' not found
xtimes
is documented to be part of the result of 'optimx' and fitCount_
is the object returned by optimx()
. Printing it gives:
Browse[2]> fitCount_
scale_ shape_ value fevals gevals niter convcode kkt1 kkt2
nlminb 1.343784 -0.2194413 -21.21925 12 21 9 0 NA NA
xtime
nlminb 0.34
We see that there is a column xtime
, not xtimes
. Indeed,
Browse[3]> names(fitCount_)
[1] "scale_" "shape_" "value" "fevals" "gevals" "niter"
[7] "convcode" "kkt1" "kkt2" "xtime"
The problem may be ocuring in optimx:::optimx.run()
. It assigns ans$xtimes <- time
on line 736 of optimx.run.R
but later assembles another object from ans
and other stuff, without explicitly mentioning column names.
The line of code in Countr
where the error occurs needs to be replaced in any case by a more robust version.