Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I have a class with a set of descriptive statistic functions (mean, median, kurtosis, etc...).

Now I need to include weight (array) into my equations. My first thought was to just create a weighted version of the functions where the additional weight array is passed.

However, I was wondering if there is a way to alter the data (array) so that the same functions can be used.

Note: This is my first Statistics project so I am learning as I go. Sorry if this is a stupid question.

Question:

Is there a way to weight the data before calculating the descriptive statistics - so that the existing functions can be used.

If this is possible then I could add an additional function to weight the data before it is passed into the descriptive functions.

share|improve this question

2 Answers

up vote 4 down vote accepted

It isn't entirely clear from your question what sort of 'weight' you are talking about. But I imagine it is a simple matter of wanting to count certain observations more than than others...

If you wanted to, and your weights were integer values (or you can find the lowest common denominator to multiply by that will give you integer values), you could simply expand your data out to match the weights. That is, a data point with a weight of 2 could be represented twice in your data array. This is fine for descriptives such as mean, median, kurtosis, and skew. However, it may be be problematic for calculations such as a sample estimate of the standard deviation where N matters and the difference between a raw N-1 and a N-1 where N is representative of the restructured array might be meaningful.

The only shortcut I can think of that might apply is to multiply your array by the weights and then analyze those results. For the mean, to renormalize the value, you will need to divide the result by (sum)Weights/N_original.

However, for the median, kurtosis, and skew you won't be able to (readily) use this technique and I think you will have to revert to altering your function to produce new data arrays.

Good luck.

share|improve this answer
1  
+1. Actually, kurtosis and skewness aren't any more of a problem to compute this way: typically, wherever division by N is called for, one divides by the sum of weights. The median can be obtained by sorting the data, computing the cumulative sum of weights, and picking the value where half the total sum is crossed. Weighted percentiles are obtained similarly. – whuber Nov 19 '10 at 21:52
2  
I agree that it depends entirely on what sort of weights you have. Decent statistical packages distinguish between several (sampling weights, frequency weights, inverse-variance weights...) and treat them differently. – onestop Nov 19 '10 at 22:04

Weights can arise in data analysis through various mechanisms, each of which requires its own formulas:

  1. A dataset with many duplicate results can be summarized by listing each unique result together with its frequency of occurrence. This is the definition @drknexus assumes in order to provide a definite answer (after recognizing that other definitions are possible).

  2. When datasets represent averages or other statistics, their values have known (or at least pre-estimated) levels of uncertainty. The weights can represent those levels. (Typically the appropriate weight to use is the inverse of the variance.) These are incorporated in methods like weighted least squares regression.

  3. Many datasets obtained through observational studies in the social and biological sciences arise from complex sampling schemes in which units/subjects have differing chances of being selected. The appropriate weights to use in estimates are usually the inverses of the selection probabilities, as in the Hansen-Hurwitz Estimator and the Horvitz-Thompson Estimator.

  4. Various robust methods, such as IRLS regression, iteratively reweight data in order to de-emphasize atypical values. These weights can enter into formulas in ways that differ from (1) - (3) above.

Thus, you need first to decide what your weights mean and what the purpose of computing the weighted statistics might be.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.