Calculate weighted mean across individuals ---------------------------------------------------------------------------
| 206 | // Calculate weighted mean across individuals |
| 207 | // --------------------------------------------------------------------------- |
| 208 | float get_weighted_mean(const std::vector<float>& data, const std::vector<float>& weights) { |
| 209 | double sum = 0; |
| 210 | double totalWeights = 0; |
| 211 | int unsigned arrayLength = data.size(); |
| 212 | if (arrayLength != weights.size()) { |
| 213 | cerr << "Warning: arrays should have the same size in \"get_weighted_mean\"..\n"; |
| 214 | return NA; |
| 215 | } |
| 216 | for (int unsigned i=0; i< arrayLength; i++) { |
| 217 | sum+=data[i]*weights[i]; |
| 218 | totalWeights += weights[i]; |
| 219 | } |
| 220 | return (float)sum/totalWeights; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | // Calculate inter quartile range across individuals |
no outgoing calls
no test coverage detected