As suspected by OP and @SchaunW, the problem lies in the C code. "A bit" of digging revealed a quite subtle problem (see the source code, not the newest version though):
All the sampling in ideal.c appears in the part of commence iterations, i.e. where functions updatex
, updatey
and others are used. However, the problem is with one of the arguments of these functions - the matrix ok
(ironic, right?). It is used by updatex
and updateb
and only the positions where ok == 1
are important (in crosscheck
, crosscheckx
).
Before that, some values of ok
are assigned to be 1 in check(y,ok,n,m)
.
However, at the very beginning the initial values of ok
are denoted by
ok = imatrix(n,m);
which allocates a integer matrix (see util.c for imatrix
). The problem is that then ok
contains various numbers, i.e. not only zeros and sometimes ones. It seems that they are not related to RNG state of R, which explains the behaviour noted by @SchaunW: all.equal(run1@result$xbar, run2@result$xbar)
returns TRUE
if !any(ok == 1)
and vice versa. Also, different number of ones explains different lastState
.
I am not an expert in C and I am not sure whether there is a logic error in the code or if the imatrix
function should be corrected, but a straightforward fix could be to fill ok
with zeros right after initialisation:
ok = imatrix(n,m);
for(a=0; a<n; a++) {
for(aa=0; aa<m; aa++) {
ok[a][aa] = 0;
}
}
Finally, there is also a fix that does not include modifying the C code (it might not be right for your applications though). Functions crossxyi
, crossxyj
are used instead of crosscheck
, crosscheckx
(the bad ones) when impute = TRUE
for ideal
.