Anuj Sao
Anuj Sao

Reputation: 29

coxph : "**Error in if (any(infs)) warning(paste("Loglik converged before variable ", : missing value where TRUE/FALSE needed"**

I am doing a Multi-touch Attribution problem using coxph() function. Its a large dataset with around 1 million data but currently I am running a subset of ~100000. I have removed all the missing values from my data. I am getting an error

Error in if (any(infs)) warning(paste("Loglik converged before variable ", 
 :missing value where TRUE/FALSE needed

Here is the Cox Function :

SurvObj <- Surv(Final_Data$NormalizedStartTime,Final_Data$NormalizedEndTime,event = Final_Data$Converted)

model2 <- coxph(SurvObj ~  Clicks + RFR + Impressions + Other + `Site-ID` + `Creative-ID`, data = Final_Data1)

Thanks in Advance for the help :) The Error and the Summary of Final_Data

Upvotes: 2

Views: 2886

Answers (2)

Iyar Lin
Iyar Lin

Reputation: 631

I had this problem too. Turns out one of my variables had infinite values in it. Problem solved once I replaced these values

Upvotes: 1

Mi-Go
Mi-Go

Reputation: 41

The line above, "Loglik" and so on, is meant to give information about a dubious test, where loglik converges beforehandedly. The full line, when produced correctly, should be something akin to the following:

"Loglik converged before variable 100; beta may be infinite."

And it is produced by the following code in the agreg.Rnw https://r-forge.r-project.org/scm/viewvc.php/pkg/survival/noweb/agreg.Rnw?diff_format=c&sortdir=down&sortby=author&revision=11529&root=survival&view=markup

if (any(infs))
        warning(paste("Loglik converged before variable ",
                      paste((1:nvar)[infs],collapse=","),
                  "; beta may be infinite. "))

From here we can see that the any() would expect the infs to be a number. If infs is NaN, the function will not work.

The inner part functions like this:

paste("Loglik converged before variable ",
                      paste((1:1)[NaN],collapse=","),
                  "; beta may be infinite. ")
[1] "Loglik converged before variable  NA ; beta may be infinite. "

so this part of the function would run, if it could get to the inner part. But it does not, since evaluating

infs <- NaN
if (any(infs))
warning(paste("Loglik converged before variable ",
                      paste((1:nvar)[infs],collapse=","),
                  "; beta may be infinite. "))

Error in if (any(infs)) warning(paste("Loglik converged before variable ",  : 
missing value where TRUE/FALSE needed

the exact error you had. The infs variable is generated before, via infs <- abs(agfit$u %*% var). And the agfit is produced via .Call(Cagfit4.....), so the problem is in the underlying C code for the function.

For some of my data, both the agfit$u and agfit$imat are NaNs. The $u and $imat are generated from

u2 =    SET_VECTOR_ELT(rlist, 1, allocVector(REALSXP, nvar));
u = REAL(u2);

and

PROTECT(imat2 = allocVector(REALSXP, nvar*nvar));
nprotect =1;
if (NAMED(covar2)>0) {
    PROTECT(covar2 = duplicate(covar2)); 
    nprotect++;
    }
covar= dmatrix(REAL(covar2), nused, nvar);
imat = dmatrix(REAL(imat2),  nvar, nvar);

respectively, in the agfit4 C code. I am not that good in C so I cannot say what the problem is in the C code area. It could be a bug or then the Cox function is not usable for your data or both. Nevertheless, something should be done to this, since I've seen others asking about this error too. But unfortunately I am not skilled enough to fix this, I only can point to the problem and holler "hey! somebody else pls take care of this" :-).

My possible solutions would be:

1) check if your data is usable with the Cox function at all (e.g. if you have 2000 cases of 0 and 2 cases of 1, the Cox function may not be suitable anyway, and the error is suggesting you find another way for the analysis :-) )

2) modify the code to do the any(infs) evaluation via removing the NAs, resulting in FALSE and skipping the error via the following: if (any(infs, na.rm=T)) (could screw up the code, tho)

3) fix the C code so that the agfit4 does not produce NaNs in the output object. (only for the skilled, not me)

Upvotes: 4

Related Questions