Weighted Average and its Uncertainty

Average rating
(0 votes)

// after e.g. J.R. Taylor 1997, Introduction to error analysis, 2nd Ed., University Science Books, p175
// input waves MUST NOT contain NaNs or INFs
function/WAVE WeightedAvg(data, error)
	wave data, error	
 
	// define weight
	MatrixOP/O/FREE w = rec(magSqr(error))
 
	// weighted average
	MatrixOP/O/FREE avg = sum(w * data) * rec(sum(w))
 
	// uncertainty
	MatrixOP/O/FREE sigma = rec(sqrt(sum(w)))
 
	// Combine results into 2D wave, 1st col = wAvg, 2nd col = error
	Concatenate/O {avg,sigma}, W_wAvg
 
	return W_wAvg
end

Back to top