MCPcopy Create free account
hub / github.com/BoevaLab/FREEC / get_weighted_mean

Function get_weighted_mean

src/myFunc.cpp:208–221  ·  view source on GitHub ↗

Calculate weighted mean across individuals ---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

206// Calculate weighted mean across individuals
207// ---------------------------------------------------------------------------
208float 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

Callers 1

evaluateContaminationMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected