I wrote simple code, but it looks messy because I am removing NaN and I usually want to apply element-by-element. To illustrate, I show my calculation of the Pearson correlation coefficient:
function r(obs, mod) om = (obs - mean(obs[!isnan.(obs)])) .* (mod - mean(mod[!isnan.(mod)])) oo = (obs - mean(obs[!isnan.(obs)])).^2 mm = (mod - mean(mod[!isnan.(mod)])).^2 sum(om[!isnan.(om)]) ./ sqrt.(sum(oo[!isnan.(oo)]) .* sum(mm[!isnan.(mm)])) end
mod are arrays of floats of arbitrary dimension. It looks messy because of the additions of:
[!isnan.()]to the argument of every use of
.for the functions
sqrt(), but of course not for
There must be a less verbose, or more elegant, way to write this?