Hi All -

I recently wrote a few basic stat verbs for doing weighted versions of some
of the common descriptive statistics.  They lack the cohesive elegance of
the standard versions from the "univariate.ijs" script but I couldn't
figure out how to replicate it with the weighted versions as I've made them
dyadic.

NB.* wtdMean: weighted-mean: x is weights, y is values
wtdMean=: ([: +/ *) % [: +/ [
NB.EG 7r3 = 1 2 3 wtdMean 1 2 3

NB. wtdSumDev: weighted sum of deviations
wtdSumDev=: [: +/ [ * ] - [: (+/ % #) ]
NB.* wtdVar: weighted variance
wtdVar=: ([: +/ [ * [: *: ] - wtdMean) % ([: ([: (<: % ]) [: # 0 -.~ ]) [)
* [: +/ [
NB.* wtdSD: weighted standard deviation (biased)
wtdSD=: [: %: ([: +/ [ * [: *: ] - wtdMean) % [: +/ [
NB.* wtdSDunbias: weighted standard deviation (unbiased)
wtdSDunbias=: [: %: ([: +/ [ * [: *: ] - wtdMean) % ([: ([: (<: % ]) [: # 0
-.~ ]) [) * [: +/ [

These seem to work OK - see
http://www.itl.nist.gov/div898/software/dataplot/refman2/ch2/weightsd.pdf -
but are not as elegantly-interconnected as these:

   whereDefined 'stddev'
c:\...\j64-804\addons\stats\base\univariate.ijs
   stddev
%:@var
   var
ssdev % <:@#
   ssdev
+/@:*:@dev
   dev
-"_1 _ mean
   mean
+/ % #

Comments on these are welcome.

-- 

Devon McCormick, CFA

Quantitative Consultant
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to