Geometric and weighted mean
12-22-2017, 10:13 PM (This post was last modified: 12-22-2017 10:16 PM by salvomic.)
Post: #1
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
Geometric and weighted mean
For example extracting data from Statistics: Statistics_1Var.D1 as a list and to calculate from that list.
Or is better to write a little program?
Sorry, but my memory fails (and I can't find those command in the Catalog)...

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-22-2017, 11:32 PM (This post was last modified: 12-23-2017 05:24 PM by Carlos295pz.)
Post: #2
 Carlos295pz Member Posts: 265 Joined: Sep 2015
RE: Geometric and weighted mean
I think there is no geometric mean.

Viga C | TD | FB
12-23-2017, 07:46 AM
Post: #3
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
(12-22-2017 11:32 PM)Carlos295pz Wrote:  I think there is no geometric mean.

thank you Carlos,

(size(D1)√(πList(D1)) is ok per geometric mean.
Wmean was in old HP calculators, like HP-42s and others.

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-23-2017, 08:05 AM
Post: #4
 AlexFekken Member Posts: 151 Joined: May 2016
RE: Geometric and weighted mean
You might also be able to abuse the regression functionality to get (some of) those values out.

The HP/Free/DM 42 is nice enough to calculate the required sums for both types of average/regression all the time; I don't think the Prime does that too.
12-23-2017, 08:57 AM
Post: #5
 Arno K Senior Member Posts: 430 Joined: Mar 2015
RE: Geometric and weighted mean
(12-23-2017 07:46 AM)salvomic Wrote:
(12-22-2017 11:32 PM)Carlos295pz Wrote:  I think there is no geometric mean.

thank you Carlos,

(size(D1)√(πList(D1)) is ok per geometric mean.
Wmean was in old HP calculators, like HP-42s and others.

Salvo

Your "arithmetic mean" is not correct, it is the median and should be 6.625. This is what mean() produces.
Arno
12-23-2017, 09:20 AM (This post was last modified: 12-23-2017 09:29 AM by salvomic.)
Post: #6
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
(12-23-2017 08:05 AM)AlexFekken Wrote:  You might also be able to abuse the regression functionality to get (some of) those values out.
ok
Quote:The HP/Free/DM 42 is nice enough to calculate the required sums for both types of average/regression all the time; I don't think the Prime does that too.
it should have those functions, as they are useful with simple statistics.

(12-23-2017 08:57 AM)Arno K Wrote:  Your "arithmetic mean" is not correct, it is the median and should be 6.625. This is what mean() produces.
Arno

Seeing in Wikipedia, we can add also the harmonic mean to the list...

For geometric mean better than use the product maybe it's better to consider the alternative definition with logarithms, to avoid the multiply by zero (defining what it should do ln(0)!):

I think to write a little program for my friend to offer geometric, weighted and harmonic means.

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-23-2017, 09:29 AM
Post: #7
 Arno K Senior Member Posts: 430 Joined: Mar 2015
RE: Geometric and weighted mean
(12-23-2017 09:20 AM)salvomic Wrote:  For geometric mean better than use the product maybe it's better to consider the alternative definition with logarithms, to avoid the multiply by zero:
[img]

Salvo

So you want to force an error if there is a 0 in the list?
Arno
12-23-2017, 09:31 AM (This post was last modified: 12-23-2017 09:53 AM by salvomic.)
Post: #8
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
(12-23-2017 09:29 AM)Arno K Wrote:
(12-23-2017 09:20 AM)salvomic Wrote:  For geometric mean better than use the product maybe it's better to consider the alternative definition with logarithms, to avoid the multiply by zero:
[img]

Salvo

So you want to force an error if there is a 0 in the list?
Arno

no... and I corrected my post (see now), as also ln(0) returns error, obviously...
Rigorously, geometric mean with zeros doesn't mean anything. And then the geometric mean is calculable only for positive numbers (for the root)...

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-23-2017, 10:33 AM (This post was last modified: 12-23-2017 07:35 PM by salvomic.)
Post: #9
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
Could this code be good?
No error correction (for 0, negative numbers) in it.

Code:
 // Geometric mean // list1 mustn't have 0 and must contain positive numbers EXPORT gmean(list1) BEGIN RETURN surd(ΠLIST(list1),SIZE(list1)); END; // Weighted mean // list1 items, wlist weights EXPORT wmean(list1, wlist) BEGIN RETURN ΣLIST(list1*wlist)/ΣLIST(wlist); END; // Harmonic mean // list1 mustn't contain 0 EXPORT hmean(list1) BEGIN RETURN (ΣLIST((list1)^(-1)))^(-1)*SIZE(list1); END;

With the Carlos' lists list1={5.2, 8.2,7.4,5.7}, wlist={3,1,2,4}:

mean(list1) = 6.625
median(list1) = 6.55

gmean(list1) = 6.51224817722
wmean(list1, wlist) = 6.14
hmean(list1) = 6.40171419012

Question for Bernard: are there those means in XCAS?

EDIT:: thanks to Carlos29pz for info: I didn't remember that we can use the already present command mean(list1, list2) to get weighted mean, so please, use my program only for geometric and harmonic means, since those command won't be built-in the Prime.

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-23-2017, 11:42 AM (This post was last modified: 12-23-2017 11:56 AM by DrD.)
Post: #10
 DrD Senior Member Posts: 1,029 Joined: Feb 2014
RE: Geometric and weighted mean
Salvo,

After reading your original post, I found a website that had some useful information. Did you happen to see this one, also?

http://buzzardsbay.org/special-topics/ca...tric-mean/

(Particularly, near the bottom where it has suggestions for handling negative values, or zero values).

-Dale-
12-23-2017, 11:51 AM
Post: #11
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
(12-23-2017 11:42 AM)DrD Wrote:  Salvo,

After reading your original post, I found a website that had some useful information. Did you happen to see this one, also?

http://buzzardsbay.org/special-topics/ca...tric-mean/

-Dale-

hi Dale,
I've not seen it first.
I'm bookmarking it to read in the local afternoon; there is also a discussion how to calculate geometric mean with 0 and negative values...

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-23-2017, 05:21 PM
Post: #12
 Carlos295pz Member Posts: 265 Joined: Sep 2015
RE: Geometric and weighted mean
Oh true, I chose wrong in the catalog, median instead of mean, they were very close xD
Corrected.

Viga C | TD | FB
12-23-2017, 05:25 PM
Post: #13
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
(12-23-2017 05:21 PM)Carlos295pz Wrote:  Oh true, I chose wrong in the catalog, median instead of mean, they were very close xD
Corrected.

Well! ;-)
in most cases mean and median are close, very close.
Geometric mean is lesser than arithmetic mean.

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
12-24-2017, 03:01 AM
Post: #14
 AlexFekken Member Posts: 151 Joined: May 2016
RE: Geometric and weighted mean
Perhaps it is worth pointing out that *an* average is a relatively arbitrary way of "summarising" a bunch of numbers into a single number. The abstract definition that I learnt at uni even covers the two extreme cases of min() and max().

It is very common not to justifiy a particular choice of average (e.g. the arithmetic mean), other than by its ubiqitous implementation. If you want to get really serious and properly justify why you "should" use a certain choice of average, you are typically lead to consider cost functions. For example: minimize sum of squares (arithmetic mean), miminize expected walking distance to the first lift that arrives in the office (median), ...

In terms of relative size, these hold in general:

min <= harmonic <= geometric <= arithmo-geometric <= arithmetic <= max

I think not much can be said about the relative sizes of other common types as it depends heavily on the (skewness of the) distribution of the numbers. In fact, their size relative to the arithmetic mean may be used as an indicator of skewness.
12-24-2017, 08:33 AM
Post: #15
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
(12-24-2017 03:01 AM)AlexFekken Wrote:  Perhaps it is worth pointing out that *an* average is a relatively arbitrary way of "summarising" a bunch of numbers into a single number. The abstract definition that I learnt at uni even covers the two extreme cases of min() and max().

It is very common not to justifiy a particular choice of average (e.g. the arithmetic mean), other than by its ubiqitous implementation. If you want to get really serious and properly justify why you "should" use a certain choice of average, you are typically lead to consider cost functions. For example: minimize sum of squares (arithmetic mean), miminize expected walking distance to the first lift that arrives in the office (median), ...

In terms of relative size, these hold in general:

min <= harmonic <= geometric <= arithmo-geometric <= arithmetic <= max

I think not much can be said about the relative sizes of other common types as it depends heavily on the (skewness of the) distribution of the numbers. In fact, their size relative to the arithmetic mean may be used as an indicator of skewness.

yes Alex, definitely all depends after the data we want treat and after the problem type.
That said, the Prime has already good instruments to handle Statistics. Perhaps it is missed only geometric mean, that in some cases is more adequate than other types or of the median. It is not a great problem as we can make it with a little program; my friend would like only to have it as a command; I tried to help him with a program that acts like a command, so he can experiment among the various types and I'll suggest him also your right considerations about the correct use of means.
Thank you,
Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
01-04-2018, 03:55 PM (This post was last modified: 01-04-2018 04:04 PM by StephenG1CMZ.)
Post: #16
 StephenG1CMZ Senior Member Posts: 690 Joined: May 2015
RE: Geometric and weighted mean
(12-24-2017 03:01 AM)AlexFekken Wrote:  Perhaps it is worth pointing out that *an* average is a relatively arbitrary way of "summarising" a bunch of numbers into a single number. The abstract definition that I learnt at uni even covers the two extreme cases of min() and max().

It is very common not to justifiy a particular choice of average (e.g. the arithmetic mean), other than by its ubiqitous implementation. If you want to get really serious and properly justify why you "should" use a certain choice of average, you are typically lead to consider cost functions. For example: minimize sum of squares (arithmetic mean), miminize expected walking distance to the first lift that arrives in the office (median), ...

In terms of relative size, these hold in general:

min <= harmonic <= geometric <= arithmo-geometric <= arithmetic <= max

I think not much can be said about the relative sizes of other common types as it depends heavily on the (skewness of the) distribution of the numbers. In fact, their size relative to the arithmetic mean may be used as an indicator of skewness.

I was intruiged by your mention of max and min as extreme examples of means. I realised that I really was not sure what "a mean" was. To try to understand the concept, I looked up several example means - and implemented many of them here.
I admit I still would not like to have to explain what "a mean" is.

As for justifying which mean to use for a given data set, I thought my IsMean procedure might be useful. Used properly, it can show which mean a tabloid newspaper has used in its headline. Used improperly, given the number you would like as your answer, it can identify which average you need to use (regardless of appropriateness).

By the way, if you have weighted data but your mean procedure does not implement weights, you can use my InvOCCUR procedure to turn Valuelist,Weightlist into Valuelist-with-repeated-values (I'm sure there must be a better name). Obviously, weights must be integer.

Stephen Lewkowicz (G1CMZ)
01-04-2018, 05:24 PM
Post: #17
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: Geometric and weighted mean
thank a lot, Stephen!

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
01-05-2018, 01:22 AM
Post: #18
 AlexFekken Member Posts: 151 Joined: May 2016
RE: Geometric and weighted mean
(01-04-2018 03:55 PM)StephenG1CMZ Wrote:  I admit I still would not like to have to explain what "a mean" is.

Nice to see someone taking my feedback seriously and expanding on it.

From memory, the abstract definition of a mean (that I learned in a "captia selecta" math lecture) is that of any function of a "finite sequence" (i.e. a list) of numbers satifying:

1 - the mean is not less than all of the numbers
2 - the mean is not more than all of the numbers
3 - the mean is scale-invariant

Presumably the numbers had to be real (or at least from a totally ordered set) for 1 and 2 to make sense. I am not sure if there were further domain restrictions, e.g. all numbers > 0, in this abstract context, but since we covered the arithmetico-geometric mean I suppose there must have been. And "weights" apparently weren't in scope at all :-)

The 3rd condition means that if you multiply all numbers in the seqence by a fixed constant then you can get the new mean by multiplying the original by the same constant. This ensures that if the number represent physical quantities on an absolute scale (e.g. NOT degrees Celsius, Fahrenheit), then you will get the same mean regardless of the units used. So other than "staying within range" that was the only functional restriction on the definition of a "mean".

But of course abstract definitions are not intended to explain but to distil the essence of a concept (my favourite being that of a "topology" to represent "closeness" without talking about distance). I would say using cost functions is probably the best way to justify/explain the different types of means (as "best estimates" that mimimize them). For example (and in addition to the ones I already mentioned), if the cost of underestimating is much very bigger than that of overestimating, then max would be your best "mean".
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)