int tmp = i;
i = j;
j = tmp;
}
Tally tallyi = get (i);
Tally tallyj = get (j);
if (tallyi == null || tallyj == null)
return Double.NaN;
int n = tallyi.numberObs();
if (n != tallyj.numberObs()) {
log.logp (Level.WARNING, "ListOfTalliesWithCovariance", "covariance",
"Tally " + i + ", with name " + tallyi.getName() + ", contains "
+ n + " observations while " +
"tally " + j + ", with name " + tallyj.getName() + ", contains " + tallyj.numberObs() + "observations");
return Double.NaN;
}
if (n < 2) {
log.logp (Level.WARNING, "ListOfTalliesWithCovariance", "covariance",
"Tally " + i + ", with name " + tallyi.getName() + ", contains " + n + " observation");
return Double.NaN;
}
if (tallyi instanceof TallyStore && tallyj instanceof TallyStore)
return ((TallyStore) tallyi).covariance ((TallyStore) tallyj);
else if (isStable)
return curSum2[i][j - i - 1]/(n-1);
else {
double sum1 = tallyi.sum();
double sum2 = tallyj.sum();
double sum12 = sxy[i][j - i - 1];
return (sum12 - sum1*sum2/n)/(n-1);
}
}