/** This is likelihood ratio test function: mr is the number of cases within the risk period, nr is the total within the risk period, msr is the number of cases outside the risk period, nsr is the total outside the risk period, ms and ns are the cases across the whole index period. */ function lr(mr, nr, msr, nsr, ms, ns) { if (plusp(mr) && plusp(nr) && plusp(ms) && plusp(ns) && plusp(msr) && plusp(nsr) && mr < nr && ms < ns && msr < nsr) { var tmp1 = mr / nr / 1.0; var tmp2 = msr / nsr / 1.0; var tmp3 = ms / ns / 1.0; return tmp1 > tmp2 ? the(singleFloat, (mr * (Math.log(mr) - Math.log(nr)) + (nr - mr) * the(singleFloat, Math.log(1 - tmp1)) + msr * (Math.log(msr) - Math.log(nsr)) + (nsr - msr) * the(singleFloat, Math.log(1 - tmp2))) - (ms * (Math.log(ms) - Math.log(ns)) + (ns - ms) * the(singleFloat, Math.log(1 - tmp3)))) : 0.0; } else { return -100.0; }; };