pyrcca
pyrcca copied to clipboard
explained variance calculation is incorrect
Thanks for a great package. I did notice one error when I was using it.
Here is your code for calculating explained variance:
resids = [abs(d[0]-d[1]) for d in zip(vdata, preds)] for s in range(nD): ev = abs(vdata[s].var(0) - resids[s].var(0))/vdata[s].var(0)
Consider for simplicity vdata, and preds are just one dimensional vectors.
If preds = the mean of vdata, which for our case is 0, then we should expect that preds explains 0 of the variance, so ev =0.
However, with the current method, because you have resids =abs(vdata-pred), then in the case that preds is just constant and = mean(vdata) , the resids[0].var(0) will not be equal to the variance of the original data, rather the variance of the absolute value of the original data, which may not necessarily be equal to the variance of the original data. Hence ev will be greater than 0, even though it shouldn't be.