Introduction to  probability & Bayes’ rule

ECE generic - segment 2

4. Joint probability: a primer

4.1 Examples for concept introduction

4.1.1 Example of finite outcome Ω

Draw a card, suppose we want a black card, the probability is denoted as p[black], the yellow-hi-lited cards below meet the requirement.

Suppose we want a number card that is divisible by 3, we denote the probability as p[div3]. The blue-hi-lited cards below meet the requirement.

Joint probability occurs when we want the probability of not just one feature but multiple features. Thus, if we want a black number card divisible by 3, we call that probability as p[black, div3]: it is the probability to have BOTH requirements, as shown below. They are black cards of 3, 6, 9.

Thus, formally, we can say that the first feature (black card in this example) is subset A in σ-field, and second feature, divisible by 3 is subset B in σ-field, then, the joint probability for both feature is:
                                           p[black, div3]≡p[A,B]=p[A⋂B]

Of course we can have more than 2 features. Let’s add a third feature, the number card must be even, then, this is what we have for P[black, div3, even]:  p[black, div3, even]≡p[A,B,C]=P[A⋂B⋂C], which are just the two black 6 cards as shown below.

4.1.2 Example of continuous variables

We encounter joint probability far more often when dealing with data of real variables. Consider a person’s height, weight, shoulder width, waist size, ... If we have a large group of people, we have a multivariate distribution:
                               p[height, weight, shoulder, waistline,...]
which is a joint-PDF of these variables.

Let’s take a look at a more specific example. Below shows the actual data of a group of people. Each dot is an individual.

Suppose we want the joint-probability of people with height between 182-186 cm and shoulder width between 40-43 cm. Then, it will be the fraction of people in the rectangle intersection of the two bands as shown.

If we have the PDF: p[h,s], the formal expression is:
                (Subscript[P, height,shoulder])[h∈[(Subscript[h, 0]) ,(Subscript[h, 0]) +Δh];s∈[(Subscript[s, 0]) ,(Subscript[s, 0])+Δh]]= (∫_(Subscript[s, 0])^((Subscript[s, 0])+Δh))(∫_(Subscript[h, 0])^((Subscript[h, 0]) +Δh))p[h,s]dhds

Of course, the probability integration doesn’t have to be over a rectangle as shown but any domain in the (h,s) space that p[h,s] is integrable.

4.2 Statistical dependence/independence

The most important concepts when having two or more variables or two or more features of interest are “statistical dependence/independence” and “statistically correlation”. These concepts are not relevant if we have only one variable.

Draw a card, we want an ace. That probability is p[ace]. If we want a ♢, that probability is p[♢]. Can we have both? of course, and the probability is p[ace,♢].

But what if I want p[ace, red, ♢]? do we need all three features? no, because ♢ is automatically a part of red. We will say that red is NOT statistically independent of ♢, because if it is a ♢, it MUST be red.

Now, suppose we have continuous variables, such as Form1040 adjusted gross income (AGI) (rounded of to $50 step) and tax. Are they statistically independent? Anyone who pays tax knows the answer: no, death and tax are certainty of life, and the etched-in-stone tax table will say exactly what the tax is for a given AGI. Given a tax, we can inverse lookup what the AGI is. They are statistically dependent on each other.

Let’s measure a car speed with known mass and its kinetic energy. Are speed and KE independent? no, because we know that:    KE=(1/2)m (v^2)

But far more often, we don’t encounter such clearcut cases of statistical dependence or independence in real life applications. Let’s take a look at the example of human height and shoulder width:

({{           , }, {, }})

If a person is tall, is it more likely he (the above population is male) has broader shoulder? The data says what common knowledge does: the taller a man is, the more likely will he have a broader shoulder. But given a person’s shoulder width, can we predict exactly what his height is? No, because it has statistical fluctuation. This is a case of statistical correlation, not cut-and-dry dependence/independence discussed above, and it is actually far more common and important in real life applications.

4.3 Statistical correlation or association

Let’s take a look at the figure below for the same example in 4.2:

We see that height and shoulder width are NOT completely (or absolutely) independent. Given a height, we can make a guess (inference) what the range of shoulder should be. This is the key concept here: variables that are or are not 100% independent of each other.

In this particular case, we can make a simple linear model: (regression for those who have learned it)
                          (Subscript[μ, Sh]) = α (x -(Subscript[μ, H])) + (Subscript[μ, Sh0])             x is the height.

where (Subscript[μ, H]) is height mean, and (Subscript[μ, Sh0]) is the shoulder mean. We don’t know what slope α is but can try to fit visually:

code

αinit=((43.5-38.5)/(195.-160.));  (* this is what we make an initial estimate of slope α  *)
Manipulate[
Column[{TextCell["vary α to get a good visual fit",18,Italic,FontFamily->"Calibri"
,Background->LightBlue]

,Show[menHSscatterplot
,Plot[α (x-menheightμ)+menshoulμ,{x,155.,200}
,PlotStyle-> {Thickness[0.02],Hue[0.35,1,1,0.8]}], ImageSize-> 400]
}]

,{{α,αinit},0.,2.*αinit}
,Initialization:>{
αinit=((43.5-38.5)/(195.-160.));
menheightμ= 177.75; menheightσ=7.2;
menshoulμ=41.24; menshoulσ=2.09;
menHSscatterplot= ;

}]

There are many similar cases in social science. What is the distribution of income? What is the distribution of height? Is there a corr between income and height? (these are interesting stuffs you can read from time to time in newspapers).

Another example: suppose we collect the following data: 
                      p[age, obesity, cholesterol level,frequency of strokes]
Statisticians and epidemiologists love to crank through statistics on the correlation of these things. These research lead to things like:

Other things of popular interest:

There is a whole class of research known as GWAS (Genome Wide Association Studies) if you are curious. Notice that the term “association” is used instead of correlation. The latter is usually used if the relationship is quantitative such as y=a x +b. The former is used for more general relationship that can be either functional or discrete or Boolean (categories).

Example: What genomic features are correlated with income?

The above is just one in the trend of GWAS that includes research such as the below:

Something more amusing:

4.4 Joint-probability axiom and marginal distribution

4.4.1 Joint-probability axiom

In the last example of the above section, we can understand that there is a genetic link to ice cream flavor preference. But let’s consider a study that includes a person’s zip code vs. ice cream flavor, e. g. chocolate or vanilla. Is there any correlation? If we move from one zipcode to another, will we change our ice cream preference? Unlikely!. If so, is there any thing interesting about joint probability p[zipcode, choc/vanil]? Most likely, no. In other words, for any zip code, 
                   p[zipcode, choc]=(Subscript[p, 0]) ;   p[zipcode, vanil]=1-(Subscript[p, 0])   where (Subscript[p, 0]) is constant  vs. zip code.

If so, should we bother to include zipcode in p[zipcode, choc/vanil]? Obviously, we should not because it is irrelevant. This is why the joint probability distribution of statistically correlated variables is more interesting than either statistical dependence or independence.

The formal axiom on joint probability is that two events will be called statistically independent if and only if
                                                          p[A,B]=p[A].p[B]

Another way to express the concept is that two events are independent when the probablity of occurence of each is the same regardless whether the other occur or not. If A and B are independent, then:
                                                        p[A⋂B]=p[A].p[B]

Exercise

1. What is the probability for a card to be red and = 5?  
2. What is the probability of a card to be red and heart?
3. Let’s take 2 cards from a deck of 52; let A= a set of 2 cards that is one red and one black; What is the probability of A?
4. If we take two cards in two different times, each time with a full 52 card deck, what is p[A].
5. Let B be blackjack, excluding double aces. What is p[B]?

Answer

1. What is the probability for a card to be red and = 5?  Probability to be red is 1/2; probability to be 5 is 1/13. So the prob of a card that is red and 5 is:
(1/2) (4/52)=(1/(26 ))

2. What is the probability of a card to be red and heart? If we use the above principle, 
(1/2) (1/4)=(1/(8 )): this is wrong. The reason is that red and heart are NOT independent. Heart is a subset of red. If know a card is a heart, then it must be red. There is no uncertainty. Here we can say that the probability for a card to red if it is known to be a heart is 100%. This is the concept of conditional probability (discussed laler).

3. Let’s take 2 cards from a deck of 52; let A= a set of 2 cards that is one red and one black; What is the probability of A?
                    p[A]= ((26×26)/((({{52}, {2}}))))=((26×26)/((52×51)/2))=(26/51).

4. But now, if we take two cards in two different times, each time with a full 52-card deck, then p[A]=(1/2)(1/2)+(1/2)(1/2)=(1/2). We notice that the difference between 1/2 and 26/51 is the fact that in one case, the deck becomes 51 after the first card is drawn. 

5. Let B be blackjack, excluding double aces. p[B]=((4 aces ×16 tens)/((52×51)/2))=((4×16)/(26×51))

Further discussion:

What is the probability for both A and B? (Black jack with one red card and one black card). If A and B were independent: 
                             p[A] . p[B]=(26/51)4×(16/(26×51))=(64/2601)

(26/51)((4×16)/(26×51))

Is it correct? the probability for a black jack with a red and a black card is:
red aces & black tens + black aces & red tens= 2×2×8
Thus p[A⋂B]=((2×2×8)/(26×51))

((2×2×8)/(26×51))

This is NOT the same as p[A] . p[B]

N[(64/2601)] 
N[(16/663)]

4.4.2 Marginal probability

Consider this example again, If we neglect either one of the two variables, we obtain the PDF of the other variable: this is called marginal PDF.

({{           , }, {, }})

Each slice of PDF below is also marginal, if we select the height data to be within the indicated range and discard the rest. However, why should we discard the data? A better way to express this is the concept of “conditional probability,” because each slice is conditional that the height be in the domain as indicated.

Now, we can discuss marginal propability with formal definition. Let p[A,B] be a joint-distribution, we define the marginal probability as:
                                                 p[A]=(∑_(i=1)^M)P[A,(Subscript[B, i])]
where (Subscript[{(Subscript[B, i])}, i=1]^M) is the complete set of mutually exclusive events that describe all events of set (Subscript[Ω, B]). Likewise:
                                                 p[B]=(∑_(i=1)^N)P[(Subscript[A, i]),B]

For continuous real variable, the definition is:
                                      (Subscript[p, X])[x]=(∫_□^□)p[x,y]dy   and     (Subscript[p, Y])[y]=(∫_□^□)p[x,y]dx   
More generally:  (Subscript[p, (Subscript[X, 1]),...(Subscript[X, m])])[(Subscript[x, 1]), ...,(Subscript[x, m])]=(∫_□^□)p[(Subscript[x, 1]), ...,(Subscript[x, m]), (Subscript[x, m+1]), ...,(Subscript[x, N])]d(Subscript[x, m+1])...d(Subscript[x, N])

E.2 Exercise/lecture - multi-variate normal distribution

E.2.1 The importance of multi-variate distribution: an example

Let’s say a clothing manufacturer has big contracts to make school uniforms for two large school systems, say A and B. But it had a terrible manufacturing foul-up: it mixed up two large batches of school uniforms before any decals were sewn-on for identification.

The uniforms are all of different sizes for kids of different ages. And although they may appear similar, the fashion designs are different. School system A uniform has a slightly larger hat, but shorter jacket while school system B has a smaller hat but longer jacket. A casual observer might not know. But not to the fastidious sharp-eye school uniform police who can tell the most minutia fashion details. They would be very upset if the uniforms are wrong.

According to the online-order record and the computerized production system statistics, this is the distribution of hat size and jacket length (relative to the means).

Is it hopeless for the company to salvage the batches by finding a way to discriminate and separate A and B uniforms? They couldn’t afford to randomly send these to the school systems and know they would upset the schools, the parents, and lose their customers once they find out.

It turns out the situation might not be that hopeless.  The good news is, the hat and jacket were packaged together. The mix-up happened after the packaging.  As the company checked the production run, they obtain the joint distribution statistics of hat-and-jacket as shown below:

As one can see, we can draw a line - a discriminant boundary to separate (classify) the two clusters and not a single mix-up if both variables are taken together. What we see here is the effect of “multi-dimensionality” space scaling. The space volumn of a cube of side d grows geometrically ((d^n)) as a function of number of variables n. If everyone moves on one line, collision will happen. But if we move x and y, we can avoid each other. If we can move x, y, z we can avoid collision even more which is why airplanes don’t collide mid-air as easily as cars. And cars at an intersection with overpasses don’t have accidents as easily as at a path-crossing intersection. (In the above, there is one dimension that is implicit: time - which is why time-multiplexing red/green traffic lights can help avoid data collision).

Airplanes may look dense on 2D, but in reality, they are very very far apart in {x, y, z, t}.

Data in high-dimensional space tend to be rarified and that is the reason why we can classify them into distinct clusters. Clearly, how well we can classify and separate them depends on the distribution.

A very common and straight-forward type of distribution to classify is normal distribution. The game we play in Section 3 in Segment 1 is 1D classification, which requires just one point (although we draw a vertical line, the vertical axis doesn’t mean anything). Here, we will see examples of 2D where the discriminant boundary is truly a 2D line, and 3D with a 3D surface. With generalization to any dimension, the discrimant is an (n^th)-dimension surface.

E.x  Side note: data input and handling review

While doing exercise 5.2 you may wonder, “is there a quicker and easier way to get parameters and fit a distribution in 5.2”? The answer is yes. If we know the type of distribution, we can use formulas to obtain estimates of parameters which can be used to describe the distribution.

How complex this calculation is depends on the type of distribution. As you might guess, a common type of distribution - and also an easy one to handle - is multivariate normal distribution: it is an extension of the one-D version into higher dimension. You have seen one in 5.3. Since it is a useful distribution, we have this section just for it.

We will use the example of height and shoulder width again. You may wonder why we don’t use an obvious thing like height and weight? The reason is that the distribution of human weight is not Gaussian but lognormal. It is messier mathematically to convolute a Gaussian with lognormal. It is generally true that convolution between any two different distributions is a mess. Of course, numerically, we can program the computer to do anything, but for the learning purpose, the math of Gaussian distribution is the easiest to handle. Both height and should width are length and length of human body tends to have Gaussian distribution.

Here is the data that you should execute to do calculation in subsequent sections.

Data on human body measurements (open up to see details if needed)

menbodstat={{21.`,1,174.`,65.6`,42.9`,26.`,106.2`,89.5`,71.5`},{23.`,1,175.3`,71.8`,43.7`,28.5`,110.5`,97.`,79.`},{28.`,1,193.5`,80.7`,40.1`,28.2`,115.1`,97.5`,83.2`},{23.`,1,186.5`,72.6`,44.3`,29.9`,104.5`,97.`,77.8`},{22.`,1,187.2`,78.8`,42.5`,29.9`,107.5`,97.5`,80.`},{21.`,1,181.5`,74.8`,43.3`,27.`,119.8`,99.9`,82.5`},{26.`,1,184.`,86.4`,43.5`,30.`,123.5`,106.9`,82.`},{27.`,1,184.5`,78.4`,44.4`,29.8`,120.4`,102.5`,76.8`},{23.`,1,175.`,62.`,43.5`,26.5`,111.`,91.`,68.5`},{21.`,1,184.`,81.6`,42.`,28.`,119.5`,93.5`,77.5`},{23.`,1,180.`,76.6`,40.3`,29.`,117.1`,97.7`,81.9`},{22.`,1,177.8`,83.6`,43.7`,29.`,123.5`,99.5`,82.6`},{20.`,1,192.`,90.`,47.4`,29.6`,116.5`,103.`,85.`},{26.`,1,176.`,74.6`,40.3`,27.5`,113.`,99.6`,85.6`},{23.`,1,174.`,71.`,41.`,26.8`,107.5`,101.5`,78.`},{22.`,1,184.`,79.6`,45.`,27.`,112.`,104.1`,82.`},{30.`,1,192.7`,93.8`,39.9`,30.`,112.2`,100.`,88.3`},{22.`,1,171.5`,70.`,43.`,26.5`,120.`,93.8`,73.6`},{29.`,1,173.`,72.4`,43.1`,28.6`,109.`,98.5`,78.5`},{22.`,1,176.`,85.9`,43.6`,29.3`,118.5`,104.`,87.3`},{22.`,1,176.`,78.8`,42.`,27.5`,116.`,100.`,92.`},{20.`,1,180.5`,77.8`,43.8`,28.`,111.`,100.`,80.`},{22.`,1,172.7`,66.2`,42.3`,26.4`,117.7`,99.`,74.5`},{24.`,1,176.`,86.4`,42.7`,29.9`,123.9`,101.`,90.6`},{26.`,1,173.5`,81.8`,44.8`,27.8`,120.6`,101.6`,81.4`},{24.`,1,178.`,89.6`,46.`,30.1`,129.5`,108.8`,89.5`},{21.`,1,180.3`,82.8`,45.4`,31.8`,115.`,100.`,85.`},{24.`,1,180.3`,76.4`,40.5`,28.3`,116.`,88.`,73.5`},{23.`,1,164.5`,63.2`,39.4`,25.5`,107.8`,88.7`,75.8`},{19.`,1,173.`,60.9`,40.2`,27.2`,100.2`,84.5`,74.`},{23.`,1,183.5`,74.8`,44.2`,30.3`,113.`,93.6`,77.5`},{25.`,1,175.5`,70.`,41.`,23.6`,117.9`,105.`,74.`},{23.`,1,188.`,72.4`,44.`,31.`,112.5`,90.9`,74.`},{23.`,1,189.2`,84.1`,41.6`,32.`,110.5`,91.2`,82.`},{23.`,1,172.8`,69.1`,41.`,25.1`,112.`,98.4`,73.`},{20.`,1,170.`,59.5`,41.5`,24.5`,104.`,85.`,70.5`},{22.`,1,182.`,67.2`,41.1`,27.8`,114.8`,97.2`,75.`},{24.`,1,170.`,61.3`,38.8`,27.2`,108.`,91.5`,72.1`},{22.`,1,177.8`,68.6`,36.2`,27.5`,111.2`,91.2`,78.8`},{24.`,1,184.2`,80.1`,42.1`,27.5`,118.3`,101.1`,77.5`},{21.`,1,186.7`,87.8`,40.3`,29.4`,115.2`,104.3`,91.5`},{23.`,1,171.4`,84.7`,41.7`,27.1`,129.9`,110.8`,84.9`},{24.`,1,172.7`,73.4`,37.8`,27.1`,112.9`,96.3`,79.1`},{35.`,1,175.3`,72.1`,39.2`,26.1`,112.2`,102.7`,77.9`},{29.`,1,180.3`,82.6`,41.5`,30.8`,117.1`,103.9`,91.7`},{25.`,1,182.9`,88.7`,42.5`,27.8`,118.7`,105.6`,86.6`},{23.`,1,188.`,84.1`,39.4`,26.1`,109.2`,95.8`,84.7`},{20.`,1,177.2`,94.1`,43.6`,33.1`,128.1`,111.2`,90.3`},{25.`,1,172.1`,74.9`,38.9`,24.9`,113.3`,100.`,79.7`},{29.`,1,167.`,59.1`,37.6`,24.4`,108.4`,91.6`,73.1`},{23.`,1,169.5`,75.6`,39.4`,28.3`,118.7`,108.`,79.8`},{23.`,1,174.`,86.2`,38.5`,26.1`,126.3`,109.6`,81.6`},{36.`,1,172.7`,75.3`,40.1`,27.8`,124.2`,105.7`,76.8`},{25.`,1,182.2`,87.1`,40.3`,28.`,126.7`,109.1`,85.9`},{24.`,1,164.1`,55.2`,37.6`,26.6`,103.3`,88.8`,73.3`},{20.`,1,163.`,57.`,38.3`,25.2`,101.2`,86.1`,69.9`},{52.`,1,171.5`,61.4`,39.7`,28.6`,104.3`,91.3`,72.7`},{50.`,1,184.2`,76.8`,42.2`,29.`,113.2`,100.6`,82.7`},{46.`,1,174.`,86.8`,41.1`,30.4`,121.9`,105.5`,90.1`},{51.`,1,174.`,72.2`,40.5`,29.3`,113.1`,97.5`,82.9`},{28.`,1,177.`,71.6`,41.5`,28.6`,108.5`,94.4`,77.9`},{48.`,1,186.`,84.8`,43.4`,32.4`,113.9`,99.6`,92.5`},{35.`,1,167.`,68.2`,43.5`,26.`,112.6`,98.1`,77.8`},{23.`,1,171.8`,66.1`,41.3`,27.1`,110.2`,93.6`,72.7`},{23.`,1,182.`,72.`,40.3`,29.5`,108.7`,93.4`,75.`},{62.`,1,167.`,64.6`,36.3`,29.2`,104.`,92.`,76.`},{21.`,1,177.8`,74.8`,39.9`,28.3`,115.2`,99.2`,82.7`},{26.`,1,164.5`,70.`,39.8`,28.8`,111.9`,97.6`,80.`},{33.`,1,192.`,101.6`,43.5`,33.2`,127.`,108.8`,107.1`},{36.`,1,175.5`,63.2`,41.2`,26.6`,111.2`,91.9`,76.2`},{41.`,1,171.2`,79.1`,44.`,28.4`,122.`,105.2`,90.2`},{40.`,1,181.6`,78.9`,41.8`,28.5`,114.5`,98.3`,89.4`},{27.`,1,167.4`,67.7`,42.9`,27.5`,109.5`,92.5`,80.9`},{27.`,1,181.1`,66.`,38.7`,24.6`,110.8`,92.5`,73.5`},{23.`,1,177.`,68.2`,41.4`,26.4`,118.8`,101.6`,70.9`},{31.`,1,174.5`,63.9`,39.6`,27.5`,108.`,94.6`,76.1`},{26.`,1,177.5`,72.`,40.5`,27.5`,114.3`,92.5`,81.`},{23.`,1,170.5`,56.8`,34.1`,28.1`,105.4`,88.2`,72.`},{24.`,1,182.4`,74.5`,43.5`,28.8`,115.`,91.`,76.8`},{24.`,1,197.1`,90.9`,44.1`,29.2`,119.5`,106.`,86.`},{34.`,1,180.1`,93.`,42.2`,32.6`,130.`,115.`,98.5`},{21.`,1,175.5`,80.9`,42.2`,30.1`,113.3`,100.`,79.`},{25.`,1,180.6`,72.7`,43.`,26.5`,113.2`,94.7`,77.5`},{34.`,1,184.4`,68.`,39.8`,28.7`,106.9`,92.5`,75.2`},{31.`,1,175.5`,70.9`,37.7`,29.7`,113.8`,96.7`,82.`},{40.`,1,180.6`,72.5`,39.6`,27.9`,117.3`,97.4`,79.6`},{21.`,1,177.`,72.5`,43.2`,26.3`,124.2`,106.7`,75.2`},{33.`,1,177.1`,83.4`,44.3`,28.2`,123.`,106.2`,88.6`},{25.`,1,181.6`,75.5`,43.3`,28.2`,117.8`,103.6`,81.5`},{29.`,1,176.5`,73.`,42.8`,27.5`,118.8`,98.3`,79.9`},{27.`,1,175.`,70.2`,41.5`,30.`,112.`,87.8`,73.5`},{44.`,1,174.`,73.4`,42.`,27.6`,113.`,99.8`,80.3`},{26.`,1,165.1`,70.5`,41.2`,27.1`,116.`,104.6`,81.5`},{22.`,1,177.`,68.9`,43.8`,29.5`,112.8`,86.5`,74.`},{37.`,1,192.`,102.3`,46.2`,31.`,125.`,110.`,104.`},{38.`,1,176.5`,68.4`,40.4`,28.6`,108.3`,93.2`,76.2`},{20.`,1,169.4`,65.9`,40.8`,27.1`,108.2`,90.`,76.5`},{21.`,1,182.1`,75.7`,43.9`,27.`,113.`,98.4`,81.`},{24.`,1,179.8`,84.5`,44.2`,27.9`,115.`,107.2`,88.8`},{45.`,1,175.3`,87.7`,41.6`,28.`,123.`,108.3`,94.`},{25.`,1,184.9`,86.4`,38.1`,30.1`,120.2`,105.7`,83.4`},{22.`,1,177.3`,73.2`,42.`,28.`,114.`,88.5`,77.`},{29.`,1,167.4`,53.9`,37.`,27.3`,102.9`,79.3`,75.4`},{37.`,1,178.1`,72.`,41.6`,27.5`,112.5`,90.9`,80.3`},{20.`,1,168.9`,55.5`,40.1`,19.4`,104.5`,90.2`,68.`},{20.`,1,157.2`,58.4`,38.7`,25.2`,111.3`,91.6`,80.6`},{32.`,1,180.3`,83.2`,37.4`,29.9`,117.2`,105.2`,88.6`},{23.`,1,170.2`,72.7`,41.7`,28.`,112.8`,97.`,81.1`},{25.`,1,177.8`,64.1`,38.`,27.1`,104.8`,85.3`,70.8`},{27.`,1,172.7`,72.3`,40.5`,24.9`,117.7`,99.6`,73.3`},{21.`,1,165.1`,65.`,35.6`,28.5`,107.7`,94.3`,75.9`},{27.`,1,186.7`,86.4`,43.6`,30.2`,125.2`,111.8`,86.2`},{25.`,1,165.1`,65.`,37.6`,24.4`,109.1`,94.3`,75.`},{38.`,1,174.`,88.6`,41.1`,31.7`,122.6`,106.1`,101.`},{44.`,1,175.3`,84.1`,42.1`,30.6`,117.3`,102.`,90.`},{27.`,1,185.4`,66.8`,40.5`,28.3`,109.1`,94.8`,75.`},{37.`,1,177.8`,75.5`,40.9`,28.5`,116.7`,102.9`,75.9`},{28.`,1,180.3`,93.2`,43.`,30.6`,124.9`,115.8`,96.`},{33.`,1,180.3`,82.7`,40.5`,27.8`,118.6`,105.4`,84.`},{25.`,1,177.8`,58.`,41.9`,25.4`,108.8`,87.1`,67.1`},{21.`,1,177.8`,79.5`,42.1`,28.5`,121.9`,104.1`,82.5`},{30.`,1,177.8`,78.6`,43.8`,29.2`,117.3`,95.8`,83.7`},{26.`,1,177.8`,71.8`,42.1`,28.5`,115.`,98.6`,76.7`},{27.`,1,177.8`,116.4`,43.4`,32.`,134.8`,118.7`,105.2`},{33.`,1,163.8`,72.2`,38.7`,26.8`,113.8`,100.9`,90.6`},{29.`,1,188.`,83.6`,39.6`,28.7`,119.4`,98.5`,85.7`},{27.`,1,198.1`,85.5`,43.4`,30.6`,117.9`,96.9`,82.5`},{34.`,1,175.3`,90.9`,40.5`,29.7`,127.3`,110.7`,94.7`},{42.`,1,166.4`,85.9`,40.3`,30.4`,118.8`,108.`,105.2`},{29.`,1,190.5`,89.1`,44.2`,30.6`,122.4`,109.`,86.`},{41.`,1,166.4`,75.`,41.3`,26.8`,111.5`,104.2`,90.9`},{43.`,1,177.8`,77.7`,39.8`,25.6`,113.2`,100.5`,92.4`},{43.`,1,179.7`,86.4`,41.3`,29.`,115.3`,105.7`,96.5`},{29.`,1,172.7`,90.9`,38.9`,27.5`,122.5`,112.4`,98.4`},{27.`,1,190.5`,73.6`,41.1`,25.6`,114.4`,96.2`,76.7`},{62.`,1,185.4`,76.4`,41.5`,30.6`,112.8`,97.5`,94.8`},{33.`,1,168.9`,69.1`,38.5`,27.8`,112.2`,90.9`,80.1`},{45.`,1,167.6`,84.5`,39.4`,29.7`,119.4`,108.4`,97.4`},{30.`,1,175.3`,64.5`,40.9`,26.1`,108.4`,94.3`,73.7`},{20.`,1,170.2`,69.1`,41.1`,23.`,122.4`,109.1`,76.1`},{22.`,1,190.5`,108.6`,43.6`,28.`,128.8`,115.`,95.6`},{51.`,1,177.8`,86.4`,39.8`,29.`,118.`,104.4`,101.`},{34.`,1,190.5`,80.9`,42.1`,27.8`,116.5`,100.1`,84.5`},{44.`,1,177.8`,87.7`,41.1`,27.1`,120.4`,108.4`,98.`},{46.`,1,184.2`,94.5`,44.2`,30.4`,123.1`,107.3`,101.6`},{34.`,1,176.5`,80.2`,38.9`,26.8`,117.2`,101.8`,87.8`},{32.`,1,177.8`,72.`,40.1`,28.7`,113.`,94.5`,80.`},{28.`,1,180.3`,71.4`,38.7`,26.8`,109.4`,91.7`,81.8`},{31.`,1,171.4`,72.7`,35.6`,26.4`,105.7`,95.9`,84.4`},{29.`,1,172.7`,84.1`,40.5`,26.8`,119.7`,110.5`,85.`},{42.`,1,172.7`,76.8`,41.1`,25.4`,118.`,104.`,90.`},{29.`,1,177.8`,63.6`,38.7`,26.1`,104.3`,86.8`,72.9`},{31.`,1,177.8`,80.9`,38.9`,27.1`,114.1`,106.7`,81.`},{30.`,1,182.9`,80.9`,39.4`,29.7`,119.`,102.5`,86.5`},{27.`,1,170.2`,85.5`,37.6`,27.8`,113.8`,103.`,93.9`},{25.`,1,167.6`,68.6`,39.8`,25.9`,118.`,95.`,77.`},{24.`,1,175.3`,67.7`,40.3`,27.3`,116.`,99.`,75.`},{33.`,1,165.1`,66.4`,40.3`,25.2`,108.3`,89.7`,80.6`},{45.`,1,185.4`,102.3`,43.8`,30.4`,129.2`,111.5`,100.5`},{37.`,1,181.6`,70.5`,41.1`,27.8`,109.2`,94.1`,81.2`},{44.`,1,172.7`,95.9`,41.7`,30.6`,124.3`,118.3`,103.4`},{34.`,1,190.5`,84.1`,45.4`,30.8`,122.6`,106.5`,90.3`},{55.`,1,179.1`,87.3`,43.`,30.8`,122.4`,110.4`,98.`},{43.`,1,175.3`,71.8`,41.1`,25.4`,114.9`,102.3`,86.5`},{24.`,1,170.2`,65.9`,41.1`,29.2`,111.1`,98.5`,77.9`},{22.`,1,193.`,95.9`,45.2`,32.2`,126.`,111.6`,89.1`},{38.`,1,171.4`,91.4`,39.8`,34.7`,115.5`,106.7`,93.9`},{24.`,1,177.8`,81.8`,39.6`,28.7`,124.7`,110.4`,85.3`},{29.`,1,177.8`,96.8`,42.3`,30.2`,125.3`,114.`,98.5`},{25.`,1,167.6`,69.1`,40.9`,29.`,118.2`,101.8`,79.5`},{37.`,1,167.6`,82.7`,39.8`,28.`,124.3`,109.6`,94.9`},{30.`,1,180.3`,75.5`,42.3`,27.1`,118.3`,100.7`,76.5`},{26.`,1,182.9`,79.5`,42.3`,26.8`,122.3`,104.3`,88.4`},{35.`,1,176.5`,73.6`,40.5`,28.7`,116.5`,104.2`,84.2`},{29.`,1,186.7`,91.8`,42.7`,28.5`,123.`,107.4`,87.6`},{30.`,1,188.`,84.1`,43.6`,30.8`,117.6`,101.`,83.7`},{37.`,1,188.`,85.9`,42.5`,31.3`,117.5`,103.`,92.1`},{34.`,1,177.8`,81.8`,41.3`,30.8`,117.3`,107.2`,89.9`},{28.`,1,174.`,82.5`,41.3`,24.7`,114.5`,99.`,88.7`},{27.`,1,177.8`,80.5`,42.3`,26.6`,122.9`,100.3`,83.9`},{32.`,1,171.4`,70.`,36.9`,25.9`,115.5`,100.2`,79.5`},{28.`,1,185.4`,81.8`,40.3`,28.5`,116.1`,99.8`,84.5`},{22.`,1,185.4`,84.1`,40.1`,26.4`,121.6`,107.5`,89.2`},{44.`,1,188.`,90.5`,43.2`,31.3`,131.6`,110.1`,90.7`},{25.`,1,188.`,91.4`,45.`,29.`,124.5`,107.`,88.8`},{49.`,1,182.9`,89.1`,42.1`,29.7`,115.6`,105.6`,103.6`},{54.`,1,176.5`,85.`,40.9`,28.7`,117.`,103.6`,98.5`},{49.`,1,175.3`,69.1`,41.3`,27.3`,108.6`,97.1`,82.9`},{60.`,1,175.3`,73.6`,42.1`,29.7`,120.2`,109.8`,90.5`},{42.`,1,188.`,80.5`,45.2`,29.7`,116.2`,103.3`,84.5`},{52.`,1,188.`,82.7`,42.1`,31.1`,115.4`,103.7`,86.`},{23.`,1,175.3`,86.4`,41.2`,29.8`,120.`,108.5`,84.2`},{33.`,1,170.5`,67.7`,41.7`,29.2`,110.3`,97.8`,85.7`},{46.`,1,179.1`,92.7`,43.`,29.4`,119.7`,112.7`,112.1`},{43.`,1,177.8`,93.6`,41.7`,28.5`,123.5`,111.4`,99.7`},{56.`,1,175.3`,70.9`,38.`,29.7`,107.8`,95.1`,84.7`},{21.`,1,182.9`,75.`,41.9`,27.8`,118.7`,100.2`,80.3`},{18.`,1,170.8`,93.2`,40.7`,28.`,120.7`,106.3`,98.6`},{21.`,1,188.`,93.2`,41.3`,29.7`,118.7`,109.5`,90.`},{45.`,1,180.3`,77.7`,40.9`,28.7`,118.`,106.3`,86.6`},{22.`,1,177.8`,61.4`,41.7`,26.8`,105.`,91.5`,80.2`},{55.`,1,185.4`,94.1`,41.3`,31.1`,110.6`,104.9`,109.2`},{42.`,1,168.9`,75.`,41.1`,27.8`,123.1`,109.6`,88.4`},{29.`,1,185.4`,83.6`,43.4`,27.3`,121.`,102.5`,81.`},{40.`,1,180.3`,85.5`,40.7`,27.8`,111.7`,101.2`,88.8`},{24.`,1,174.`,73.9`,42.5`,25.2`,111.`,98.7`,78.1`},{62.`,1,167.6`,66.8`,40.3`,28.3`,112.`,96.`,81.5`},{26.`,1,182.9`,87.3`,39.8`,27.8`,115.9`,104.2`,87.6`},{35.`,1,160.`,72.3`,39.8`,28.3`,121.`,103.`,92.5`},{37.`,1,180.3`,88.6`,40.5`,29.9`,123.6`,107.`,97.`},{34.`,1,167.6`,75.5`,41.1`,26.8`,120.`,101.`,82.`},{25.`,1,186.7`,101.4`,42.5`,29.4`,128.7`,112.1`,99.5`},{30.`,1,175.3`,91.1`,42.5`,29.4`,124.5`,103.4`,93.8`},{32.`,1,175.3`,67.3`,38.5`,24.4`,112.4`,100.3`,79.1`},{27.`,1,175.9`,77.7`,43.8`,29.2`,112.2`,95.7`,85.8`},{42.`,1,175.3`,81.8`,41.5`,29.`,127.`,108.`,90.8`},{44.`,1,179.1`,75.5`,40.3`,27.8`,115.3`,101.`,85.4`},{46.`,1,181.6`,84.5`,40.3`,30.2`,111.5`,98.6`,91.6`},{19.`,1,177.8`,76.6`,42.1`,27.1`,118.3`,101.6`,79.7`},{43.`,1,182.9`,85.`,42.1`,31.3`,118.`,99.`,86.1`},{28.`,1,177.8`,102.5`,38.9`,29.4`,127.`,116.7`,113.2`},{39.`,1,184.2`,77.3`,44.4`,24.`,124.4`,105.`,79.5`},{30.`,1,179.1`,71.8`,40.9`,24.4`,112.4`,95.1`,85.4`},{36.`,1,176.5`,87.9`,42.1`,28.7`,125.8`,106.7`,97.9`},{48.`,1,188.`,94.3`,43.`,27.1`,131.7`,116.6`,94.7`},{48.`,1,174.`,70.9`,38.`,27.1`,117.3`,103.5`,86.1`},{53.`,1,167.6`,64.5`,37.1`,24.2`,107.6`,90.4`,84.9`},{45.`,1,170.2`,77.3`,41.1`,24.`,122.4`,107.5`,92.2`},{39.`,1,167.6`,72.3`,40.9`,24.4`,117.`,100.8`,83.7`},{43.`,1,188.`,87.3`,38.9`,27.1`,119.`,104.2`,97.8`},{65.`,1,174.`,80.`,40.9`,28.3`,123.5`,104.9`,98.6`},{45.`,1,176.5`,82.3`,39.2`,26.8`,121.4`,112.8`,89.5`},{37.`,1,180.3`,73.6`,41.7`,26.6`,112.3`,95.7`,82.9`},{55.`,1,167.6`,74.1`,39.4`,26.6`,113.2`,104.9`,90.1`},{33.`,1,188.`,85.9`,40.1`,26.4`,121.7`,109.1`,78.9`},{25.`,1,180.3`,73.2`,38.9`,25.6`,116.6`,105.4`,80.7`},{35.`,1,167.6`,76.3`,38.9`,26.4`,117.8`,104.3`,94.3`},{28.`,1,183.`,65.9`,41.7`,26.4`,118.`,100.5`,70.2`},{26.`,1,183.`,90.9`,43.2`,26.8`,131.1`,111.8`,83.6`},{43.`,1,179.1`,89.1`,40.5`,29.2`,121.4`,109.5`,91.9`},{30.`,1,170.2`,62.3`,39.2`,23.5`,116.3`,101.2`,71.8`},{26.`,1,177.8`,82.7`,40.9`,25.4`,121.8`,103.3`,85.`},{51.`,1,179.1`,79.1`,41.7`,27.3`,118.2`,101.6`,85.7`},{30.`,1,190.5`,98.2`,43.8`,32.2`,126.3`,103.1`,96.5`},{24.`,1,177.8`,84.1`,41.9`,28.`,121.`,104.6`,82.4`},{35.`,1,180.3`,83.2`,43.`,27.8`,123.1`,104.3`,86.3`},{37.`,1,180.3`,83.2`,41.5`,28.5`,114.9`,95.9`,83.2`}};

womenbodstat={{22.`,0,161.2`,51.6`,37.6`,25.`,95.`,83.`,66.5`},{20.`,0,167.5`,59.`,36.7`,26.4`,99.5`,78.5`,61.5`},{19.`,0,159.5`,49.2`,34.8`,25.9`,88.`,75.`,61.2`},{25.`,0,157.`,63.`,36.6`,27.9`,97.`,86.5`,78.`},{21.`,0,155.8`,53.6`,35.5`,28.2`,103.3`,91.`,70.5`},{23.`,0,170.`,59.`,37.`,28.`,93.5`,79.5`,66.5`},{26.`,0,159.1`,47.6`,35.5`,26.5`,93.3`,77.`,58.`},{22.`,0,166.`,69.8`,37.4`,30.2`,94.5`,88.`,74.5`},{28.`,0,176.2`,66.8`,37.8`,29.`,98.6`,85.`,73.5`},{40.`,0,160.2`,75.2`,38.6`,28.8`,115.5`,98.8`,90.5`},{32.`,0,172.5`,55.2`,37.6`,28.5`,97.9`,79.`,66.5`},{25.`,0,170.9`,54.2`,36.`,25.6`,97.7`,77.6`,61.`},{25.`,0,172.9`,62.5`,39.5`,30.`,100.5`,85.`,69.5`},{29.`,0,153.4`,42.`,34.`,25.`,88.7`,76.7`,62.`},{22.`,0,160.`,50.`,35.`,26.5`,96.6`,76.7`,63.4`},{25.`,0,147.2`,49.8`,35.6`,25.8`,92.`,82.`,71.`},{23.`,0,168.2`,49.2`,36.2`,27.4`,90.`,79.`,59.`},{37.`,0,175.`,73.2`,39.`,28.4`,104.`,89.5`,74.`},{19.`,0,157.`,47.8`,32.6`,25.6`,90.1`,73.5`,60.5`},{23.`,0,167.6`,68.8`,37.6`,30.`,104.`,90.`,75.`},{25.`,0,159.5`,50.6`,36.3`,27.5`,91.`,80.`,65.`},{26.`,0,175.`,82.5`,38.`,29.6`,111.4`,94.5`,82.2`},{24.`,0,166.8`,57.2`,37.`,27.9`,96.2`,83.8`,70.2`},{29.`,0,176.5`,87.8`,42.6`,31.8`,117.1`,95.2`,85.`},{22.`,0,170.2`,72.8`,37.5`,29.2`,101.5`,91.`,75.`},{30.`,0,174.`,54.5`,36.1`,28.2`,95.1`,80.`,63.`},{23.`,0,173.`,59.8`,39.1`,27.5`,97.1`,81.7`,70.`},{38.`,0,179.9`,67.3`,39.6`,28.6`,101.4`,89.6`,72.6`},{23.`,0,170.5`,67.8`,40.5`,29.6`,103.7`,90.9`,78.7`},{19.`,0,160.`,47.`,35.`,26.`,89.2`,78.5`,61.`},{46.`,0,154.4`,46.2`,34.5`,26.4`,86.`,78.`,64.2`},{20.`,0,162.`,55.`,35.6`,27.9`,98.1`,80.2`,63.1`},{22.`,0,176.5`,83.`,39.1`,29.7`,114.`,99.`,85.`},{25.`,0,160.`,54.4`,36.6`,28.2`,95.`,80.`,66.`},{21.`,0,152.`,45.8`,34.8`,26.3`,87.`,75.5`,65.`},{23.`,0,162.1`,53.6`,36.7`,22.1`,100.8`,82.6`,63.2`},{31.`,0,170.`,73.2`,39.7`,31.6`,112.2`,94.5`,83.6`},{29.`,0,160.2`,52.1`,35.5`,24.3`,98.7`,83.9`,68.`},{19.`,0,161.3`,67.9`,36.`,28.`,100.1`,92.8`,75.7`},{21.`,0,166.4`,56.6`,35.8`,26.4`,100.3`,85.3`,65.5`},{23.`,0,168.9`,62.3`,37.6`,27.3`,100.5`,84.4`,66.9`},{24.`,0,163.8`,58.5`,37.6`,28.7`,101.2`,87.6`,67.9`},{20.`,0,167.6`,54.5`,34.9`,28.`,96.`,81.`,67.8`},{19.`,0,160.`,50.2`,33.3`,24.9`,92.8`,84.1`,63.2`},{20.`,0,161.3`,60.3`,36.2`,27.1`,95.5`,88.2`,73.1`},{19.`,0,167.6`,58.3`,33.3`,29.2`,98.7`,88.1`,65.3`},{20.`,0,165.1`,56.2`,36.`,25.2`,96.9`,84.9`,65.6`},{19.`,0,160.`,50.2`,34.`,27.3`,91.`,81.2`,62.7`},{22.`,0,170.`,72.9`,36.2`,28.7`,106.3`,91.6`,81.8`},{39.`,0,157.5`,59.8`,34.9`,27.1`,99.8`,88.4`,72.1`},{18.`,0,167.6`,61.`,37.4`,28.3`,105.`,87.6`,68.6`},{19.`,0,160.7`,69.1`,33.8`,28.7`,106.2`,91.3`,80.`},{26.`,0,163.2`,55.9`,34.`,27.3`,97.7`,87.2`,64.9`},{20.`,0,152.4`,46.5`,34.4`,23.5`,97.4`,82.2`,61.7`},{20.`,0,157.5`,54.3`,34.7`,27.8`,96.3`,82.1`,64.`},{26.`,0,168.3`,54.8`,35.6`,26.4`,98.`,82.6`,58.6`},{21.`,0,180.3`,60.7`,33.8`,29.7`,94.5`,86.5`,68.3`},{21.`,0,165.5`,60.`,37.8`,26.6`,101.4`,85.3`,69.5`},{38.`,0,165.`,62.`,38.3`,30.4`,95.1`,84.7`,70.5`},{23.`,0,164.5`,60.3`,40.3`,29.2`,101.1`,86.8`,69.8`},{37.`,0,156.`,52.7`,38.9`,27.5`,97.4`,85.2`,69.`},{19.`,0,160.`,74.3`,39.4`,29.2`,104.8`,93.9`,81.`},{25.`,0,163.`,62.`,35.`,27.`,94.5`,84.5`,71.`},{20.`,0,165.7`,73.1`,40.7`,29.`,103.2`,90.7`,73.6`},{41.`,0,161.`,80.`,39.6`,30.4`,110.8`,97.4`,96.3`},{26.`,0,162.`,54.7`,36.9`,28.3`,94.6`,83.3`,65.`},{21.`,0,166.`,53.2`,35.6`,25.7`,96.6`,82.1`,62.8`},{47.`,0,174.`,75.7`,38.2`,30.`,102.8`,92.2`,83.`},{19.`,0,172.7`,61.1`,36.9`,29.`,96.9`,83.6`,67.6`},{44.`,0,167.6`,55.7`,36.9`,26.9`,95.6`,82.6`,65.4`},{35.`,0,151.1`,48.7`,34.8`,26.4`,92.4`,77.`,61.6`},{32.`,0,164.5`,52.3`,36.6`,27.5`,93.7`,79.3`,63.2`},{46.`,0,163.5`,50.`,36.9`,27.4`,96.1`,84.3`,59.4`},{22.`,0,152.`,59.3`,36.9`,26.4`,100.1`,85.6`,62.7`},{49.`,0,169.`,62.5`,36.9`,30.2`,98.8`,85.`,66.6`},{52.`,0,164.`,55.7`,36.`,28.6`,92.2`,79.1`,64.6`},{25.`,0,161.2`,54.8`,36.2`,30.2`,97.3`,85.`,65.7`},{48.`,0,155.`,45.9`,35.1`,28.1`,90.5`,79.`,63.`},{41.`,0,170.`,70.6`,38.8`,27.2`,110.5`,96.2`,78.5`},{18.`,0,176.2`,67.2`,36.4`,26.2`,103.`,86.`,68.2`},{30.`,0,170.`,69.4`,38.6`,24.2`,109.`,89.8`,68.5`},{20.`,0,162.5`,58.2`,36.5`,26.`,104.8`,84.5`,68.8`},{24.`,0,170.3`,64.8`,37.5`,27.4`,109.2`,88.2`,69.`},{23.`,0,164.1`,71.6`,39.9`,20.`,117.`,99.5`,78.`},{30.`,0,169.5`,52.8`,34.4`,26.1`,93.9`,76.1`,62.`},{23.`,0,163.2`,59.8`,38.7`,23.5`,105.5`,85.8`,65.8`},{45.`,0,154.5`,49.`,32.6`,24.6`,99.4`,82.`,65.`},{20.`,0,159.8`,50.`,34.5`,25.6`,89.5`,77.5`,64.9`},{20.`,0,173.2`,69.2`,36.7`,28.2`,98.5`,85.7`,71.5`},{23.`,0,170.`,55.9`,36.5`,27.`,94.9`,78.8`,61.4`},{21.`,0,161.4`,63.4`,34.2`,28.`,96.3`,88.`,75.4`},{28.`,0,169.`,58.2`,37.8`,28.6`,96.8`,80.2`,67.2`},{45.`,0,166.2`,58.6`,35.7`,25.5`,102.5`,85.6`,69.5`},{24.`,0,159.4`,45.7`,33.9`,24.3`,95.2`,81.3`,57.9`},{25.`,0,162.5`,52.2`,35.2`,24.1`,103.`,84.6`,64.4`},{19.`,0,159.`,48.6`,37.1`,24.3`,99.1`,82.2`,62.3`},{20.`,0,162.8`,57.8`,37.7`,26.2`,104.1`,84.9`,68.7`},{29.`,0,159.`,55.6`,37.8`,28.1`,99.5`,81.5`,68.`},{24.`,0,179.8`,66.8`,39.3`,24.5`,110.2`,89.9`,66.`},{24.`,0,162.9`,59.4`,37.2`,24.4`,107.1`,89.8`,71.2`},{25.`,0,161.`,53.6`,36.1`,26.8`,95.7`,80.8`,64.8`},{31.`,0,151.1`,73.2`,35.2`,25.1`,103.4`,88.4`,78.`},{22.`,0,168.2`,53.4`,35.8`,27.7`,94.6`,80.2`,60.7`},{20.`,0,168.9`,69.`,35.`,25.6`,104.5`,89.5`,75.`},{32.`,0,173.2`,58.4`,37.8`,29.9`,97.7`,83.7`,68.6`},{25.`,0,171.8`,56.2`,35.7`,27.`,96.4`,82.5`,67.1`},{19.`,0,178.`,70.6`,39.5`,29.8`,103.`,85.5`,68.`},{23.`,0,164.3`,59.8`,38.8`,26.3`,103.4`,88.3`,71.`},{22.`,0,163.`,72.`,37.9`,29.`,109.5`,91.5`,76.`},{20.`,0,168.5`,65.2`,37.7`,25.`,110.7`,92.2`,70.3`},{27.`,0,166.8`,56.6`,38.2`,25.9`,102.2`,80.5`,69.5`},{34.`,0,172.7`,105.2`,40.`,31.`,129.5`,108.`,101.5`},{25.`,0,163.5`,51.8`,35.7`,28.3`,99.2`,80.`,67.2`},{26.`,0,169.4`,63.4`,35.7`,25.9`,104.7`,89.5`,68.7`},{19.`,0,167.8`,59.`,36.`,27.6`,98.9`,84.9`,66.`},{26.`,0,159.5`,47.6`,35.`,25.`,98.5`,80.8`,67.5`},{25.`,0,167.6`,63.`,37.`,26.9`,102.2`,81.`,65.2`},{20.`,0,161.2`,55.2`,36.7`,23.5`,100.2`,88.7`,64.2`},{21.`,0,160.`,45.`,32.8`,26.2`,85.9`,74.5`,61.`},{18.`,0,163.2`,54.`,34.8`,20.3`,99.8`,81.9`,60.2`},{19.`,0,162.2`,50.2`,35.`,23.7`,93.3`,75.8`,62.6`},{27.`,0,161.3`,60.2`,38.7`,27.1`,107.3`,88.`,72.7`},{26.`,0,149.5`,44.8`,32.8`,20.9`,90.`,72.6`,58.5`},{36.`,0,157.5`,58.8`,36.7`,23.`,101.5`,88.`,67.5`},{20.`,0,163.2`,56.4`,38.8`,26.5`,105.1`,86.`,66.1`},{28.`,0,172.7`,62.`,36.4`,24.9`,101.`,85.5`,68.`},{32.`,0,155.`,49.2`,34.`,27.8`,91.9`,80.4`,64.`},{32.`,0,156.5`,67.2`,38.2`,27.5`,112.1`,98.1`,90.1`},{23.`,0,164.`,53.8`,35.1`,23.4`,98.2`,82.`,64.1`},{20.`,0,160.9`,54.4`,36.`,25.2`,102.5`,89.`,72.4`},{20.`,0,162.8`,58.`,35.9`,25.1`,98.4`,85.8`,71.`},{20.`,0,167.`,59.8`,35.`,27.1`,96.8`,85.9`,69.1`},{23.`,0,160.`,54.8`,35.2`,24.4`,103.9`,82.5`,66.1`},{20.`,0,160.`,43.2`,34.9`,26.2`,92.7`,74.5`,59.5`},{28.`,0,168.9`,60.5`,36.`,28.1`,105.`,89.4`,71.5`},{23.`,0,158.2`,46.4`,36.4`,27.7`,94.`,80.3`,65.`},{19.`,0,156.`,64.4`,35.5`,27.7`,101.5`,85.6`,71.5`},{28.`,0,160.`,48.8`,34.1`,18.7`,92.`,83.`,63.`},{19.`,0,167.1`,62.2`,37.1`,25.`,108.5`,88.2`,70.`},{29.`,0,158.`,55.5`,35.2`,26.`,93.8`,85.5`,70.4`},{32.`,0,167.6`,57.8`,37.5`,26.`,99.8`,80.6`,64.3`},{20.`,0,156.`,54.6`,36.3`,24.9`,100.3`,81.`,66.`},{28.`,0,162.1`,59.2`,37.2`,26.`,101.5`,83.6`,70.5`},{36.`,0,173.4`,52.7`,37.6`,27.7`,94.7`,79.4`,62.`},{22.`,0,159.8`,53.2`,33.6`,24.3`,103.1`,82.9`,67.6`},{20.`,0,170.5`,64.5`,34.5`,29.2`,94.5`,83.2`,65.`},{22.`,0,159.2`,51.8`,36.`,27.1`,97.1`,78.1`,64.`},{32.`,0,157.5`,56.`,35.4`,27.`,98.`,82.4`,70.5`},{40.`,0,161.3`,63.6`,35.8`,28.3`,102.4`,90.`,79.2`},{40.`,0,162.6`,63.2`,38.3`,28.3`,109.1`,92.4`,71.1`},{42.`,0,160.`,59.5`,33.8`,28.7`,94.7`,86.7`,74.7`},{40.`,0,168.9`,56.8`,36.9`,31.1`,98.2`,84.`,62.9`},{44.`,0,165.1`,64.1`,34.9`,28.`,101.5`,86.`,70.6`},{30.`,0,162.6`,50.`,35.1`,28.3`,96.6`,84.5`,61.6`},{28.`,0,165.1`,72.3`,37.4`,30.2`,106.1`,91.2`,74.2`},{37.`,0,166.4`,55.`,36.9`,27.5`,100.1`,81.1`,65.5`},{40.`,0,160.`,55.9`,36.`,28.`,105.3`,87.6`,67.7`},{45.`,0,152.4`,60.4`,32.9`,26.6`,99.8`,88.2`,72.9`},{35.`,0,170.2`,69.1`,38.3`,31.7`,103.9`,88.2`,72.1`},{41.`,0,162.6`,84.5`,37.6`,30.7`,111.`,104.2`,93.4`},{27.`,0,170.2`,55.9`,36.7`,28.`,99.`,84.8`,60.7`},{20.`,0,158.8`,55.5`,38.9`,25.2`,102.5`,84.3`,69.2`},{24.`,0,172.7`,69.5`,37.8`,28.`,105.6`,91.`,75.5`},{36.`,0,167.6`,76.4`,38.`,31.7`,99.5`,90.5`,85.6`},{27.`,0,162.6`,61.4`,38.7`,30.4`,106.5`,89.6`,71.6`},{32.`,0,167.6`,65.9`,37.1`,27.1`,104.1`,89.3`,75.5`},{64.`,0,156.2`,58.6`,35.8`,30.2`,99.7`,90.`,73.7`},{21.`,0,175.2`,66.8`,38.5`,30.4`,106.6`,88.2`,67.9`},{32.`,0,172.1`,56.6`,38.5`,30.8`,97.2`,83.5`,71.2`},{35.`,0,162.6`,58.6`,36.`,30.2`,100.8`,91.`,69.3`},{41.`,0,160.`,55.9`,34.`,26.4`,100.7`,88.2`,75.6`},{40.`,0,165.1`,59.1`,38.3`,26.6`,99.1`,82.2`,63.8`},{29.`,0,182.9`,81.8`,38.7`,33.3`,108.9`,98.9`,83.6`},{40.`,0,166.4`,70.7`,36.9`,29.`,109.8`,97.9`,84.9`},{24.`,0,165.1`,56.8`,35.8`,26.6`,99.5`,81.7`,66.`},{23.`,0,177.8`,60.`,36.7`,29.`,100.5`,86.1`,68.3`},{41.`,0,165.1`,58.2`,36.7`,28.`,97.4`,87.1`,63.8`},{44.`,0,175.3`,72.7`,37.6`,31.3`,105.`,76.8`,73.6`},{53.`,0,154.9`,54.1`,35.1`,23.7`,102.9`,87.9`,76.3`},{19.`,0,158.8`,49.1`,35.3`,23.3`,93.9`,81.6`,58.8`},{24.`,0,172.7`,75.9`,38.5`,26.6`,114.2`,92.3`,78.`},{25.`,0,168.9`,55.`,37.8`,29.4`,95.9`,81.3`,64.5`},{20.`,0,161.3`,57.3`,35.1`,25.6`,98.7`,82.2`,65.8`},{34.`,0,167.6`,55.`,32.4`,30.2`,91.2`,78.6`,62.5`},{32.`,0,165.1`,65.5`,39.2`,31.3`,105.1`,94.3`,77.5`},{24.`,0,175.3`,65.5`,38.3`,30.8`,102.3`,89.5`,70.`},{29.`,0,157.5`,48.6`,32.9`,20.9`,93.1`,81.`,59.4`},{31.`,0,163.8`,58.6`,38.`,28.3`,101.7`,85.4`,68.3`},{34.`,0,167.6`,63.6`,37.8`,32.`,105.`,86.2`,77.9`},{36.`,0,165.1`,55.2`,34.2`,29.2`,96.4`,85.3`,68.3`},{32.`,0,165.1`,62.7`,37.6`,31.3`,103.5`,86.1`,72.`},{39.`,0,168.9`,56.6`,35.3`,25.4`,99.8`,84.5`,62.7`},{37.`,0,162.6`,53.9`,34.9`,27.3`,87.`,72.6`,58.`},{52.`,0,164.5`,63.2`,37.4`,32.`,105.2`,90.`,72.7`},{24.`,0,176.5`,73.6`,36.2`,31.1`,102.1`,95.8`,85.4`},{33.`,0,168.9`,62.`,38.9`,29.`,101.3`,85.5`,67.3`},{42.`,0,175.3`,63.6`,36.`,30.4`,99.6`,85.7`,70.8`},{34.`,0,159.4`,53.2`,33.3`,25.9`,99.4`,85.4`,67.4`},{37.`,0,160.`,53.4`,37.4`,29.4`,99.4`,79.1`,66.`},{39.`,0,170.2`,55.`,34.7`,29.4`,99.`,84.4`,63.6`},{41.`,0,162.6`,70.5`,38.7`,28.`,108.2`,90.`,71.7`},{36.`,0,167.6`,54.5`,36.2`,28.3`,96.4`,82.9`,73.6`},{19.`,0,162.6`,54.5`,37.6`,27.8`,101.4`,87.3`,66.9`},{22.`,0,160.7`,55.9`,34.9`,26.1`,98.2`,85.3`,65.5`},{23.`,0,160.`,59.`,34.7`,24.7`,100.6`,87.3`,70.4`},{36.`,0,157.5`,63.6`,34.`,26.8`,108.4`,93.2`,80.3`},{45.`,0,162.6`,54.5`,37.8`,28.5`,100.8`,84.7`,65.`},{25.`,0,152.4`,47.3`,35.1`,27.8`,94.8`,78.`,60.4`},{67.`,0,170.2`,67.7`,39.2`,29.9`,108.2`,90.7`,75.3`},{26.`,0,165.1`,80.9`,35.1`,29.9`,110.7`,95.`,83.4`},{21.`,0,172.7`,70.5`,37.1`,29.2`,102.6`,88.7`,72.2`},{33.`,0,165.1`,60.9`,35.8`,29.4`,98.1`,86.6`,70.1`},{25.`,0,170.2`,63.6`,35.3`,26.8`,92.`,82.5`,69.8`},{24.`,0,170.2`,54.5`,37.6`,26.8`,98.6`,81.4`,66.4`},{21.`,0,170.2`,59.1`,35.8`,29.`,96.1`,79.9`,61.7`},{35.`,0,161.3`,70.5`,36.`,29.2`,107.7`,91.1`,76.4`},{27.`,0,167.6`,52.7`,35.6`,28.3`,95.4`,80.1`,63.8`},{27.`,0,167.6`,62.7`,37.1`,27.8`,99.3`,86.4`,70.2`},{26.`,0,165.1`,86.3`,35.6`,30.2`,115.2`,105.2`,88.2`},{25.`,0,162.6`,66.4`,35.1`,29.4`,96.7`,91.1`,75.8`},{44.`,0,152.4`,67.3`,35.8`,26.8`,109.`,96.7`,81.5`},{29.`,0,168.9`,63.`,37.4`,29.4`,95.1`,80.5`,67.4`},{26.`,0,170.2`,73.6`,38.9`,28.5`,108.4`,90.4`,78.3`},{23.`,0,175.2`,62.3`,37.4`,29.`,98.2`,84.1`,65.9`},{32.`,0,175.2`,57.7`,37.6`,28.3`,99.7`,84.2`,62.4`},{32.`,0,160.`,55.4`,35.1`,26.6`,94.4`,82.5`,65.6`},{43.`,0,165.1`,104.1`,38.`,33.3`,127.1`,106.9`,96.2`},{32.`,0,174.`,55.5`,36.7`,25.2`,94.9`,79.9`,62.5`},{41.`,0,170.2`,77.3`,35.6`,29.9`,98.9`,93.`,80.5`},{33.`,0,160.`,80.5`,35.6`,30.8`,106.4`,96.3`,86.1`},{28.`,0,167.6`,64.5`,35.6`,27.3`,102.2`,86.8`,71.3`},{28.`,0,167.6`,72.3`,37.8`,29.`,110.3`,95.3`,79.4`},{25.`,0,167.6`,61.4`,40.9`,28.7`,107.3`,93.`,72.3`},{38.`,0,154.9`,58.2`,34.`,25.9`,95.`,86.4`,67.4`},{37.`,0,162.6`,81.8`,34.9`,31.3`,115.6`,109.`,94.2`},{25.`,0,175.3`,63.6`,35.8`,31.5`,99.3`,86.2`,67.`},{37.`,0,171.4`,53.4`,36.5`,27.5`,93.1`,85.3`,69.5`},{27.`,0,157.5`,54.5`,32.9`,26.8`,94.9`,84.2`,66.4`},{27.`,0,165.1`,53.6`,36.9`,28.5`,100.`,83.7`,67.6`},{20.`,0,160.`,60.`,35.8`,29.4`,98.6`,86.5`,66.6`},{19.`,0,174.`,73.6`,39.4`,28.3`,107.2`,98.2`,69.7`},{32.`,0,162.6`,61.4`,36.5`,28.3`,98.3`,88.`,72.`},{26.`,0,174.`,55.5`,35.8`,27.3`,92.4`,80.4`,64.5`},{56.`,0,162.6`,63.6`,34.4`,29.7`,93.`,86.`,72.3`},{23.`,0,161.3`,60.9`,36.5`,26.6`,99.5`,86.4`,69.1`},{19.`,0,156.2`,60.`,38.5`,25.6`,92.8`,87.6`,74.7`},{31.`,0,149.9`,46.8`,35.3`,25.4`,95.9`,80.9`,60.8`},{34.`,0,169.5`,57.3`,36.2`,28.7`,96.1`,82.1`,66.9`},{34.`,0,160.`,64.1`,34.9`,28.7`,98.5`,89.3`,68.8`},{24.`,0,175.3`,63.6`,38.7`,29.7`,103.8`,85.3`,63.7`},{22.`,0,169.5`,67.3`,37.6`,25.2`,105.`,89.`,71.2`},{34.`,0,160.`,75.5`,34.7`,29.4`,100.2`,94.1`,79.6`},{30.`,0,172.7`,68.2`,37.8`,29.7`,99.1`,90.8`,77.9`},{32.`,0,162.6`,61.4`,39.8`,27.5`,107.6`,97.`,69.6`},{40.`,0,157.5`,76.8`,36.5`,29.7`,104.`,95.4`,86.`},{29.`,0,176.5`,71.8`,38.`,30.4`,108.4`,91.8`,69.9`},{21.`,0,164.4`,55.5`,35.3`,28.7`,99.3`,87.3`,63.5`},{33.`,0,160.7`,48.6`,34.7`,24.9`,91.9`,78.1`,57.9`},{33.`,0,174.`,66.4`,38.5`,29.`,107.1`,90.9`,72.2`},{38.`,0,163.8`,67.3`,35.6`,29.`,100.5`,97.1`,80.4`}};

In the data cell above, there are two arrays: menbodstat and womenbodstat. Their lengths and dimensions are:

Length /@ {menbodstat,womenbodstat}
Dimensions /@ {menbodstat,womenbodstat}

which means there are 247 observations for men, 260 observations for women, each observation has 9 variables. They are:
{age, gender (1=men, 0-woman), height, weight, shouderwidth, pelvic, shouldergirth, chestgirth, waistgirth}

Grid[{Range[9],ToString /@ {age,gender,height,weight,shouderwidth,pelvic,shouldergirth,chestgirth,waistgirth}}]

Quiet @ Dynamic[If[TrueQ[Length[menbodstat]>1], Quiet @ 
   
,"run to read in data in the data block above"]];

After you read in the data, we are ready to move onto the next.

E .2.1  Covariance matrix and normal distribution fit - Exercise

Exercise - set up data pair height and shoulder width

1- Select height and shoulder width data for men and women (separately) and combine the two variables into a pair. You can name the new data menHS and womenHS. You can do this with Table or Transpose. The first is a bit more intuitive for beginning programmers.

menHS=Table[{m[[3]],m[[5]]},{m,menbodstat}] ;
womenHS=Table[{w[[3]],w[[5]]},{w,womenbodstat}] ;

The Transpose method: (you have to use only one, but try to gain an understanding how it works).

mData=Transpose[menbodstat];
menHS=Transpose[{mData[[3]],mData[[5]]}] ;
wData=Transpose[womenbodstat];
womenHS=Transpose[{wData[[3]],wData[[5]]}] ;

Once the data is read-in once,  Transpose method is faster.

2- Make a 3D histogram for each gender, name the histograms menhist3D and womenhist3D, use option “PDF”

menhist3D=Histogram3D[menHS,Automatic,"PDF",ChartStyle->Hue[0.5,1,1,0.75], ChartElementFunction->"FadingCube"
,AxesStyle-> White, BoxStyle->GrayLevel[0.6]
,BoxRatios-> {1,1,1},Background-> Black, ImageSize->400]
womenhist3D=Histogram3D[womenHS,Automatic,"PDF",ChartStyle->Hue[0.15,1,1,0.75], ChartElementFunction-> "FadingCube"
,AxesStyle-> White, BoxStyle->GrayLevel[0.6]
,BoxRatios-> {1,1,1},Background-> Black, ImageSize->400]

your answer

Exercise - obtain the mean and covariance (don’t worry) and plot the fit distribution

If you feel “omg, I forgot what covariance is,” don’t worry, just do it now to get familiar with it and you will learn its details later.

1- Obtain the mean of each gender distribution

μM=Mean @ menHS  (* DO NOT do Mean /@ - no slash, which is totally different operation *)
μW=Mean @ womenHS

2- Instead of variance ( standard of (deviation^2) ) for one-dim variable, we obtain the covariance matrix for any data with 2-and-higher D.

ΣM=Covariance @ menHS ;
ΣW=Covariance @ womenHS ;
Grid[{{"men covariance","women covariance" }
,{ΣM  //MatrixForm,ΣW //MatrixForm}} ]

What is the covariance matrix? don’t worry about it for now, just think of it as a complicated form of variance, which is the square of the standard of deviation.

your answer

Exercise - Plot bivariate normal distribution with mean and covariance estimates obtained

Use this formula and use Plot3D to plot them. μ is the mean and Σ is the covariance matrix you obtain above. Plot 3D distribution for men, for women, and show or plot both together, name the plot: menNDfit, womenNDfit, and menwoND. Plot all on the same range:
{x,145,200},{y,32,50.} so that we can compare. You can choose your own styling.

pdfGauss3D[{x_,y_},μ_,Σ_]:= (1./(2 π (Sqrt[Det[Σ]])))(E^(-0.5* (({x,y}-μ) . Inverse[Σ] . ({x,y}-μ))))

{menNDfit=Plot3D[pdfGauss3D[{x,y},μM,ΣM],{x,145,200},{y,32,50.}
, PlotPoints->40 ,MeshFunctions->{#3&},Mesh->5, MeshStyle->{Thickness[0.005],Hue[0.75,0.7,1]}
,PlotStyle-> Hue[0.35,0.65,1,0.85]
,PlotRange-> All,BoxRatios->{1,1,0.66}
,ImageSize->350]
,womenNDfit=Plot3D[pdfGauss3D[{x,y},μW,ΣW],{x,145,200},{y,32,50.}
, PlotPoints->40,MeshFunctions->{#3&},Mesh->5, MeshStyle->{Thickness[0.005],Hue[0.05,1,1]}
,PlotStyle->Hue[0.87,0.6,1,0.85]
,PlotRange-> All,BoxRatios->{1,1,0.66}
,ImageSize->350]
,Show[menNDfit,womenNDfit,ImageSize->350]}

your answer

Exercise - show the histogram3D you obtain with its Gaussian fit. One for each gender

Observe how the normal distrinbution fit is oriented in a way to cover the histogram as expected with correct aspect of the ellipse and the tilt.

{Show[menhist3D,menNDfit,ImageSize-> 400],Show[womenhist3D,womenNDfit,ImageSize-> 400]}

your answer

Exercise - generate simulation with more data points, e. g. 10000

The data above may appear rough fit with its normal distribution. The reason is data insufficiency. If we need 1000 data points to have a smooth fit in 1 D, we would need 1,000,000 data points in 2D. That will take a lot of CPU time. We can do with 10000 points. Use the code developed in 5.2 above, generate 10,000 data points or more and show its histogram with its normal distribution estimate.

menheightμ= 177.75; menheightσ=7.2; nsample=10000; 
menshoulμ=41.24;
αinit=((43.5-38.5)/(195.-160.));  sd0=1.5;

(* we generate a new random data set for height below - one can use the old one
but we generate here so that this cell is self-sufficient to be executed  *)

h1=RandomVariate[NormalDistribution[menheightμ,menheightσ],nsample];

(* here is the key difference: shoulder data is NOT randomly generated on its own
but for EACH value of height, we generate a RANDOM but UNIQUE value of shoulder width
associated with this random height value. The mean and SD of this RANDOM but UNIQUE
shoulder height is therefore CORRELATED with the height  *)

s2=Table[RandomVariate[NormalDistribution[αinit (x-menheightμ)+menshoulμ,sd0]],{x,h1}] ;

mensim=Transpose[{h1,s2}] ;
{μsim,Σsim}={Mean @ mensim, Covariance @ mensim};
histsim=Histogram3D[mensim,{20,15},"PDF",ChartStyle->Hue[0.5,1,1,0.75], ChartElementFunction->"FadingCube"
,AxesStyle-> White, BoxStyle->GrayLevel[0.6]
,BoxRatios-> {1,1,1},Background-> Black, ImageSize->400] ;
mensimNDfit=Plot3D[pdfGauss3D[{x,y},μsim,Σsim],{x,145,200},{y,32,50.}
, PlotPoints->40 ,MeshFunctions->{#3&},Mesh->5, MeshStyle->{Thickness[0.005],Hue[0.75,0.7,1]}
,PlotStyle-> Hue[0.35,0.65,1,0.85]
,PlotRange-> All,BoxRatios->{1,1,0.66}
,ImageSize->350] ;
Show[histsim,mensimNDfit,Background-> Black, ImageSize->400]

your answer

End exercise on binormal distribution of human height and shoulder width

E .2.2  A geometric description of 2D normal distribution

E .2.2.1 General discussion

This section aims to help those who might feel a little uneasy whenever encounter things like “higher dimension” and “matrix”. It is generally true that most can easily grab the concept of single-variable Gaussian or normal distribution (ND) with the familiar bell-shape curve. Yet, the moment “covariant matrix” or ellipsoid are mentioned, things may suddenly appear mysterious.

Below is a simple and succinct approach that uses geometry to describe 2D (bivariate) ND that may help to overcome this sense of unfamiliarity.

code

Manipulate[
If[TrueQ[GaussianGeomBasic0== ],
σplaneLog=Graphics3D[{Hue[0.45,1,1,0.2]
,Cuboid[{-2σ31,-2σ32,-1.01},{2σ31,2σ32,-0.99}]}];
Grid[{{Show[Plot[(E^(-0.5(((x/σ31))^2))),{x,-7,7}
, PlotLabel->Style["linear scale - Gaussian",17,Black,Bold]]
,Graphics[{Red,PointSize[0.05],Point /@ {{-σ31,(E^(-0.5))},{σ31,(E^(-0.5))}}
,Hue[0.45,1,1,0.7],Rectangle[{-7,(E^(-0.5))-0.01},{7,(E^(-0.5))+0.01}]}]
,ImageSize-> 250]
,Show[Plot[-0.5(((x/σ31))^2),{x,-7,7},PlotRange->{-3,0}
,  PlotLabel->Style["log scale - inverted parabola",17,Black,Bold]]
,Graphics[{Red,PointSize[0.05],Point /@ {{-σ31,-0.5},{σ31,-0.5}}
,Hue[0.45,1,1,0.7],Rectangle[{-7,-0.52},{7,-0.48}]}],ImageSize-> 250]
,Item[TextCell["in 1-D, two red points uniquely define the shape of
the curve. In 2-D, 4 points are needed (below), which
form an ellipsoid that uniquely defines the shape of
the distribution. A line (teal) for 1D becomes a plane
for 2D, which cuts an ellipsoidal cross section.
The ellipsoid is what needed to describe higher-
dimensional normal distribution.
Vary σx and σy to see the shape changes",16,FontFamily->"Calibri", Italic]
,Background->Hue[0.32,0.3,1]]}
,{Show[Plot3D[Exp @(-0.5((((x/σ31))^2)+(((y/σ32))^2))),{x,-7,7},{y,-7,7}
, MeshFunctions-> {#3&},MeshStyle->{Thickness[0.01],Red}
,  PlotLabel->Style["linear scale - 2 D Gaussian",17,Black,Bold]
,BoxRatios->{1, 1, 1}, PlotRange-> All,ImageSize-> 250]
,σplane]
,Show[ParametricPlot3D[{r Cos[ϕ],r Sin[ϕ]
,-0.5((((r Cos[ϕ]/σ31))^2)+(((r Sin[ϕ]/σ32))^2))},{r,0,2*Max[σ31,σ32]},{ϕ,0,2 π}
,PlotRange-> {{-2σ31,2σ31},{-2.σ32,2.σ32},{-2,0}}
, MeshFunctions-> {#3&}, Mesh->5,MeshStyle->{Thickness[0.01],Red}
,  PlotLabel->Style["log scale - inverted paraboloid",17,Black,Bold]
,BoxRatios->{σ31/σ32, 1, 1},ImageSize-> 250]
,σplaneLog]
,Show[ContourPlot[((((x/σ31))^2)+(((y/σ32))^2)),{x,-2σ31,2σ31},{y,-2.σ32,2.σ32}
,ContourShading-> None,Contours->{0.5,1,2,3}, ContourStyle->Red
,AspectRatio->σ32/σ31
,  PlotLabel->Style["equi-prob. dens.\ncontours - ellipsoid",17,Black,Bold]
,ImageSize-> 250]
,Graphics[{Hue[0.45,1,1,0.4],Ellipsoid[{0,0},{σ31,σ32}]
,Red,Opacity[1],PointSize[0.05],Point /@ {{-σ31,0},{σ31,0},{0,-σ32},{0,σ32}}}]]}}
,Alignment-> Top]
,"slide ON to start demo, slide OFF when done to prevent CPU slow down"]
,{{GaussianGeomBasic0,,},{,},ControlType-> Toggler}
,{{σ31,2,"σx"},1,3},{{σ32,1,"σy"},1,3}
,Initialization:>{
σplane=Graphics3D[{Hue[0.45,1,1,0.2]
,Cuboid[{-7,-7,(E^(-0.5))-0.001},{7,7,(E^(-0.5))+0.001}]}];}]

The key word is variance (or covariance) ellipsoid, which is the essence of a normal distribution and is shown in the plots of the bottom row. The 2D description is generalizable to multi-dimension: in (n^th)-dimension normal distribution, it will be an nth-order ellipsoid surface.

Similarly to one-dimension ND, σ is the distance from the mean where the PDF decreases to (e^(-(1/2))) or  (1/(Sqrt[e])). It is where:                        (((((x - μ)/σ)))^2)==1  so that:  (e^(-(1/2)(((((x - μ)/σ)))^2)))=(e^(-(1/2))) =(1/(Sqrt[e]))

In 2D and higher, the locust of all points that allow an equivalent condition:
              (((((x - (Subscript[μ, X]))/(Subscript[σ, X]))))^2)+(((((y - (Subscript[μ, Y]))/(Subscript[σ, Y]))))^2) ==1 so that:  (e^(-(1/2)((((((x - (Subscript[μ, X]))/(Subscript[σ, X]))))^2)+(((((y - (Subscript[μ, Y]))/(Subscript[σ, Y]))))^2) )))=(e^(-(1/2))) =(1/(Sqrt[e]))
form an ellipse. The variance ellipsoid is the surface where the same condition occurs. Recall this: in an x-y plane, a circle is defined by:            ((((x/r)))^2)+((((y/r)))^2)=1

An ellipsoid is defined by:               ((((x/a)))^2)+((((y/b)))^2)=1

To help connecting what we learn in geometry to this case, instead of using notation (Subscript[σ, X]), (Subscript[σ, Y]), we will use notation {a, b} for major-axis-half-length a and minor-axis-half-length b often.

A circle is an ellipse with a=b=r, the radius. However, there is one thing that the ellipsoid can do that the circle cannot: it can rotate and becomes different, while the circle remains the same if rotated. This simple aspect is actually very important for ND variance ellipsoid: it is related to the correlation of variables which is what you will study in the next section.

E .2.2.2 Explore the app and learn the basic of bivariate normal distribution

The app is not imbedded here since it runs better externally to this lecture. Below is only the icon. Open your app folder to run the stand-alone app (it should be in your app folder).

This is not an app, only the icon of an app. Look in your folder for this app
you will need to run this app to do exercises in E .2.4 and others.

E .2.3 Supplementary math about covariance and the app above

You don’t have to read or study this. This is only for the sake of completeness in explaining the various formula displayed in the app.

From the App above, you see that the PDF of a bivariate normal distribution can always be transformed with a rotation transformation such that:
      (1/(2 π (Sqrt[||Σ||])))(e^(-(1/2) (({{x, y}})) (((({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}})))^(-1))(({{x}, {y}})) ))
                        =(1/(2 π (Sqrt[||Σ||])))(e^(-(1/2) (({{x, y}})). (((({{Cos[ϕ], Sin[ϕ]}, {-Sin[ϕ], Cos[ϕ]}})))^T) . (({{(1/(a^2)), 0}, {0, (1/(b^2))}})) . (({{Cos[ϕ], Sin[ϕ]}, {-Sin[ϕ], Cos[ϕ]}}))(({{x}, {y}})) ))   (E .2.3.1a)
                          =(1/(2 π a b))(e^(-(1/2) (({{u, v}})).(({{(1/(a^2)), 0}, {0, (1/(b^2))}})) . (({{u}, {v}})) ))                                                       (E .2.3.1b)
                          =(1/(2 π a b))(e^(-((u^2)/(2 (a^2)))  )) (e^(-((v^2)/(2 (b^2)))  ))                                                                  (E .2.3.1c)
                                                            
 In other words:
                        (((({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}})))^(-1))= (R^T) (({{(1/(a^2)), 0}, {0, (1/(b^2))}})) R                                                    (E .2.3.2a)
 and                  (({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}}))= (R^(-1)) (({{(a^2), 0}, {0, (b^2)}})) (R^(-T))                                                  (E .2.3.2b)
where:                        R≡(({{Cos[ϕ], Sin[ϕ]}, {-Sin[ϕ], Cos[ϕ]}}))                                                      (E .2.3.2c)
Explicitly:
                      (({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}}))≡(({{((Subscript[σ, X])^2), (Subscript[σ, XY])}, {(Subscript[σ, XY]), ((Subscript[σ, Y])^2)}}))
    =(({{(a^2) (cos^2)(ϕ)+(b^2) (sin^2)(ϕ), (1/2) ((a^2)-(b^2)) sin(2 ϕ)}, {(1/2) ((a^2)-(b^2)) sin(2 ϕ), (b^2) (cos^2)(ϕ)+(a^2) (sin^2)(ϕ)}}))                  (E .2.3.3)

In essence, when you do this rotation in the app:

you can think of having a new system of coordinates:
     (({{u}, {v}}))=(({{Cos[ϕ], Sin[ϕ]}, {-Sin[ϕ], Cos[ϕ]}}))(({{x}, {y}}))   ;     (({{x}, {y}}))=(({{Cos[ϕ], -Sin[ϕ]}, {Sin[ϕ], Cos[ϕ]}}))(({{u}, {v}}))           (E .2.3.4)

We will use this result later:
         x y= (u Cos[ϕ]-v Sin[ϕ])(u Sin[ϕ]+v Cos[ϕ])
       = ((u^2)-(v^2)) Cos[ϕ]Sin[ϕ] +u v (((Cos[ϕ])^2)-((Sin[ϕ])^2))
       =(1/2)((u^2)-(v^2)) Sin[2ϕ] + u v Cos[2 ϕ]                             (E .2.3.5)

For simplicity, we have implicitly performed a translation such that (Subscript[μ, X]) and (Subscript[μ, Y]) vanish and we can dispense them from all formulas where they are not explicitly needed.
 
Note that because transformation matrix  R≡(({{Cos[ϕ], -Sin[ϕ]}, {Sin[ϕ], Cos[ϕ]}})) is a unitary matrix:
                   ||Σ||=||(R^(-1))|| ||(({{(a^2), 0}, {0, (b^2)}}))||  ||(R^(-T))|| = (a^2) (b^2)                                (E .2.3.6)

Thanks to Eq. (E .2.3.1c), we can perform any integration dx dy in the {u, v} space instead:
            dxdy =Jacobian[{x,y};{u,v}] dudv =dudv                                      (E .2.3.7)

For one-dimensional or one-variable distribution, we define the (n^th)-moment as
                                  E[(x^n)]= (∫_(-∞)^∞) (x^n) PDF[x]dx 
 (E stands for expectation - don’t worry for now, it is just a notation convention we follow)
 for which, the second moment is defined as the variance:
                                 variance≡((Subscript[σ, x])^2)= (∫_(-∞)^∞) (x^2) PDF[x]dx                                     (E .2.3.8)
With more than one variable, say (Subscript[x, 1]), (Subscript[x, 2]),... (Subscript[x, n]), clearly variances of each are not enough to describe the all the quadratic moments that include cross-terms: (Subscript[x, k])(Subscript[x, j]) ,  k≠j

Thus, besides 
                  ((Subscript[σ, (Subscript[x, k])])^2)= (∫_(-∞)^∞) ((Subscript[x, k])^2) PDF[x]dx          where  x={(Subscript[x, 1]), (Subscript[x, 2]),...,(Subscript[x, n])}            (E .2.3.9)
we need the covariance term:
               (Subscript[σ, (Subscript[x, k])(Subscript[x, j])])= (∫_(-∞)^∞) (Subscript[x, k]) (Subscript[x, j])PDF[x]dx                  j≠k                                    (E .2.3.10)
Hence, all variances and covariances form a covariance matrix:
                    Σ =(({{(Subscript[σ, 11]), (Subscript[σ, 12]), ⋯, (Subscript[σ, 1n])}, {□, (Subscript[σ, 22]), ⋯, (Subscript[σ, 2n])}, {□, □, ⋱, ⋮}, {□, □, □, (Subscript[σ, n n])}}))  = (({{((Subscript[σ, 1])^2), (Subscript[σ, 12]), ⋯, (Subscript[σ, 1n])}, {□, ((Subscript[σ, 2])^2), ⋯, (Subscript[σ, 2n])}, {□, □, ⋱, ⋮}, {□, □, □, ((Subscript[σ, n])^2)}}))                (E .2.3.11a)
More formally in tensor notation, this is also how it is expressed:
                Σ=E[x⊗x]=Expectation[(({{((Subscript[x, 1])^2), (Subscript[x, 1])(Subscript[x, 2]), ⋯, (Subscript[x, 1])(Subscript[x, n])}, {□, ((Subscript[x, 2])^2), ⋯, (Subscript[x, 2])(Subscript[x, n])}, {□, □, ⋱, ⋮}, {□, □, □, ((Subscript[x, n])^2)}}))]                    (E .2.3.11b)

which, for a bivariate distribution, becomes
           Σ =E[(({{((Subscript[x, 1])^2), (Subscript[x, 1])(Subscript[x, 2])}, {(Subscript[x, 2])(Subscript[x, 1]), ((Subscript[x, 2])^2)}}))]=(({{(Subscript[σ, XX]), (Subscript[σ, XY])}, {(Subscript[σ, YX]), (Subscript[σ, YY])}}))  = (({{((Subscript[σ, X])^2), (Subscript[σ, XY])}, {(Subscript[σ, XY]), ((Subscript[σ, Y])^2)}}))                     (E .2.3.12)
We can write (Subscript[σ, XY]) for (Subscript[σ, YX]) because they are obviously the same for scalar x, y.

For descriptive statistics, if we have data { {(Subscript[x, 1]),(Subscript[y, 1])},{(Subscript[x, 2]),(Subscript[y, 2])}, ...   ,{(Subscript[x, N]),(Subscript[y, N])}}
then the estimate of the covariance matrix based on (E .2.3.10) is:
             (OverHat[Σ]) = (({{((Subscript[(OverHat[σ]), X])^2), (Subscript[(OverHat[σ]), XY])}, {(Subscript[(OverHat[σ]), XY]), ((Subscript[(OverHat[σ]), Y])^2)}})) = (({{(1/N)(∑_(k=i)^N)((((Subscript[x, k])-(Subscript[(OverHat[μ]), X])))^2), (1/N)(∑_(k=i)^N)((Subscript[x, k])-(Subscript[(OverHat[μ]), X]))((Subscript[y, k])-(Subscript[(OverHat[μ]), Y]))}, {(Subscript[(OverHat[σ]), XY]), (1/N)(∑_(k=i)^N)((((Subscript[y, k])-(Subscript[(OverHat[μ]), Y])))^2)}}))         
                                             = (({{(OverBar[(x^2)])-((OverBar[x])^2), (OverBar[x y]) -(OverBar[x]) (OverBar[y])}, {(Subscript[(OverHat[σ]), XY]), (OverBar[(y^2)])-((OverBar[y])^2)}}))                                           (E .2.3.13)
Notice here that we have to put the mean (Subscript[(OverHat[μ]), X]), (Subscript[(OverHat[μ]), Y]) back into the expression because these are raw data and we have to use different symbols for x and y if we were to make a translation transformation to have new variable x’ y’ for example.

It is well-known that:
                                          (1/( σ(Sqrt[2 π])))(∫_(-∞)^∞)(((x-μ))^2) (e^(-((((x-μ))^2)/(2 (σ^2)))  ))dx  =  (σ^2)                  (E .2.3.14)
which is why the estimate for variance is:
                                  ((OverHat[σ])^2)=(1/N)(∑_(k=i)^N)((((Subscript[x, k])-(Subscript[(OverHat[μ]), X])))^2)                                                    (E .2.3.15)

However, if we define the estimate:
                                  (Subscript[(OverHat[σ]), XY])=(1/N)(∑_(k=i)^N)((Subscript[x, k])-(Subscript[(OverHat[μ]), X]))((Subscript[y, k])-(Subscript[(OverHat[μ]), Y]))                                  (E .2.3.16)
How do we integrate:
               (1/(2 π (Sqrt[||Σ||])))(∫_(-∞)^∞)(∫_(-∞)^∞) dx  dy (x y (e^(-(1/2) (({{x, y}})) (((({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}})))^(-1))(({{x}, {y}})) )))    ?                  (E .2.3.17)

It is straightforward to integrate in {u,v} space instead:
        (1/(2 π (Sqrt[||Σ||])))(∫_(-∞)^∞)(∫_(-∞)^∞) dx  dy (x y (e^(-(1/2) (({{x, y}})) (((({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}})))^(-1))(({{x}, {y}})) )))
             =(1/(2 π a b))(∫_(-∞)^∞)(∫_(-∞)^∞) du  dv (x[u,v] y[u,v] (e^(-((u^2)/(2 (a^2)))  )) (e^(-((v^2)/(2 (b^2)))  )))                                       (E .2.3.18)
Making use of Eq. (E .2.3.5) for x y
             =(1/(2 π a b))(∫_(-∞)^∞)(∫_(-∞)^∞) du  dv ((1/2)((u^2)-(v^2)) Sin[2ϕ] + u v Cos[2 ϕ]) (e^(-((u^2)/(2 (a^2)))  )) (e^(-((v^2)/(2 (b^2)))  ))

             = (1/2) ((a^2)-(b^2)) sin(2 ϕ)                                                                           (E .2.3.19)
which is     =(Subscript[σ, XY]) per Eq. (E .2.3.3).

Hence, this proves (E .2.3.13) is the Bayesian estimate for the covariance matrix.

E .2.4 Exercise of 2D normal distribution

Exercise on shoulder girth and chest girth

Use the data given in E .2.0. Create a data set based on pair {shoulder girth, chest girth}, which are variable 7 and 8. Do one set for men and one set for women. Obtain the covariance matrix for each, which is:
                          covariance≡(({{(Subscript[σ, XX]), (Subscript[σ, XY])}, {(Subscript[σ, XY]), (Subscript[σ, YY])}}))≡ (({{((Subscript[σ, X])^2), (Subscript[σ, XY])}, {(Subscript[σ, XY]), ((Subscript[σ, Y])^2)}})) ≡ Σ ≡ (({{(Subscript[Σ, 11]), (Subscript[Σ, 12])}, {(Subscript[Σ, 21]), (Subscript[Σ, 22])}}))   
The regression slope between x and y is:         slope= ((Subscript[σ, XY])/(Subscript[σ, XX])) =((Subscript[Σ, 12])/(Subscript[Σ, 11]))   

Then enter the values ((Subscript[σ, X]), (Subscript[σ, Y]) and slope) into the app above () to obtain the ellipsoid representation (copy and paste output of the app into your answer.  Show both the ellipsoid for men and women data on the same graph by using show and select plotrange to be all.

You can read the code below. However, you may not copy and paste. You should write your own code or even type the code below line-by-line, but NO COPY and PASTE: NO Control+x, Control+v

menShCh=Table[{m[[7]],m[[8]]},{m,menbodstat}] ;
womenShCh=Table[{w[[7]],w[[8]]},{w,womenbodstat}] ;
{μmShCh=Mean @ menShCh
,ΣmShCh=Covariance @ menShCh
,σxM=Sqrt[ΣmShCh[[1,1]]]
,σyM=Sqrt[ΣmShCh[[2,2]]]
,slopeMen=((ΣmShCh[[2,1]])/(ΣmShCh[[1,1]])) }

{μwShCh=Mean @ womenShCh
,ΣwShCh=Covariance @ womenShCh
,σxW=Sqrt[ΣwShCh[[1,1]]]
,σyW=Sqrt[ΣwShCh[[2,2]]]
,slopeWomen=((ΣwShCh[[2,1]])/(ΣwShCh[[1,1]])) }

If you show both ellipsoid, this is what you will see (but you must obtain it yourself, this is shown so that you know you are correct).

Show[  , 
,PlotRange-> All, ImageSize-> 400]

your answer

Exercise on shoulder girth and chest girth - bivariate normal fit

Plot the bivariate normal distribution fit for each population based on the parameters (mean and covariance) you obtain above. Then put the two normal distributions in the same graphics. You should select different colors for the genders. Better yet, it preferrable that you write your own Plot3D code to plot each or both together. You should obtain something that looks similar to the below. Do you think the distinction between them is large enough to do classification? and what you think how it is compared with just using height alone like what we did in the game?

The formula to use with Plot3D is:
                                      (1/(2 π (Sqrt[Det[Σ]])))(e^(-0.5 {{x,y}-{μx,μy}} . Σinv . {{x,y}-{μx,μy}} ))
where Σ is the covariance matrix and Σinv is its inverse. Det[Σ] is its determinant.

Note: to those who need a refresher on matrix and linear algebra: go to Review Supplementary Lecture folder for files on on these topitcs

Explicitly:
       {{x,y}-{μx,μy}} . Σinv . {{x,y}-{μx,μy}}= 
              
                         ((({{x, y}}))-(({{μx, μy}}))) · (({{(Subscript[Σinv, 11]), (Subscript[Σinv, 12])}, {(Subscript[Σinv, 21]), (Subscript[Σinv, 22])}})) ·  ((({{x}, {y}})) -(({{μx}, {μy}})) )
=(({{x-μx, y-μy}})) · (({{(Subscript[Σinv, 11]), (Subscript[Σinv, 12])}, {(Subscript[Σinv, 21]), (Subscript[Σinv, 22])}})) · (({{x-μx}, {y-μy}}))

your answer

Exercise on shoulder girth and chest girth - simulation

Obtain the histogram3D of each set (use the app) based on the parameters of mean and covariance you obtained. Put the two histograms in the same graphics.

your answer

End exercise

E .2.5 Higher-order normal distribution

This is just a brief note: as mentioned, everything you learn in E .2.3 is generalized to multi-dimension. Hence, instead of a 2x2 matrix, we have an n × n matrix (or tensor of rank n) which is symmetric (see E .2.3.2 for more details).

                         Σ =(({{(Subscript[σ, 11]), (Subscript[σ, 12]), ⋯, (Subscript[σ, 1n])}, {□, (Subscript[σ, 22]), ⋯, (Subscript[σ, 2n])}, {□, □, ⋱, ⋮}, {□, □, □, (Subscript[σ, n n])}}))  = (({{((Subscript[σ, 1])^2), (Subscript[σ, 12]), ⋯, (Subscript[σ, 1n])}, {□, ((Subscript[σ, 2])^2), ⋯, (Subscript[σ, 2n])}, {□, □, ⋱, ⋮}, {□, □, □, ((Subscript[σ, n])^2)}}))

The Mathematica function to calculate from given data is:
                                                       Covariance[data]
It will do (RefLink[PrincipalComponents, paclet:ref/PrincipalComponents])[matrix]  to obtain the unscaled principal components of variables.

(we’ll learn more about principal component analysis later). But it is instructive to run Eigensystem of Σ as well to get eigenvalues and eigenvectors. We’ll see some graphics of 3D ellipsoid in later section.

Below is a simple illustration of ellipsoid3D.

code

Manipulate[
If[TrueQ[ellipsoidDemo0== ]
,Manipulate[
RotM=(({{Cos[θ] Cos[ϕ], Cos[θ] Sin[ϕ], Sin[θ]}, {-Sin[ϕ], Cos[ϕ], 0}, {-Cos[ϕ] Sin[θ], -Sin[θ] Sin[ϕ], Cos[θ]}}));
axisvect=RotM . u0V ;
Σ3d= Transpose[RotM] . (({{(a^2), 0, 0}, {0, (b^2), 0}, {0, 0, (c^2)}})) . RotM  ;
Graphics3D[{axesNplanes[3.3,1.1],poincare[3.15],latitude[0.5 Pi-θ,3.15],longitude[ϕ,3.15]
,Hue[0.85,0.7,1,1],Sphere[3.15*{Cos[ϕ]Cos[θ],Sin[ϕ]Cos[θ],Sin[θ]},0.3]
,Opacity[1],Red,Arrowheads[0.07]
,Arrow[Tube[{-axisvect[[1]],axisvect[[1]]},0.05]]
,Green, Arrow[Tube[{-axisvect[[2]],axisvect[[2]]},0.05]]
,Blue, Arrow[Tube[{-axisvect[[3]],axisvect[[3]]},0.05]]
,White,Ellipsoid[{0,0,0},Σ3d]}
,PlotRange->ConstantArray[range3d1,3] 
,Background->Black
,ViewVector->{15*{Cos[0.65]Cos[Pi/6.],Sin[0.65]Cos[Pi/6.],Sin[Pi/6.]},{0,0,0}}]
,{{a,2},0.5,2.5},{{b,1},0.5,2.5},{c,0.5,2.5},{ϕ,0,2 π},{{θ,0},-Pi/2, π/2}
,Initialization:>{
range3d1={-3.5,3.5};vectN=3 ;
u0V=vectN{{1,0,0}, {0,1,0},{0,0,1}};
poincare[r_]:= {(* Hue[0.15,1,1,0.25],*) White,Opacity[0.3],Sphere[{0,0,0},r]
,Hue[0.5,1,1,0.1](* ,Cuboid[{-3.5,-3.5,-0.001},{3.5,3.5,0.001}] *)
(* ,White,Opacity[1],Thickness[0.003]
,Line[Table[r*{Cos[u],Sin[u],0.},{u,0,2π,π/24.}]]
,Line[Table[r*{Sin[u],0.,Cos[u]},{u,0,2π,π/24.}]]*)};
latitude[θ_,r_]:={Hue[0.03,0.9,1,1],Thickness[0.005]
,Line[Table[r*{Cos[u]Sin[θ],Sin[u]Sin[θ],Cos[θ]},{u,0,2π,π/24.}]]};
longitude[ϕ_,r_]:={Hue[0.52,1,1,1],Thickness[0.005]
,Line[Table[r*{Cos[ϕ]Sin[u],Sin[ϕ]Sin[u],Cos[u]},{u,0,2π,π/24.}]]};

axesNplanes[d_,s_]:={Hue[0.12,1,1,0.3]
,Polygon[{{-d,-d,0},{d,-d,0},{d,d,0},{-d,d,0},{-d,-d,0}}]
,Hue[0.3,1,1,0.3]
,Polygon[{{0,-d,-d},{0,d,-d},{0,d,d},{0,-d,d},{0,-d,-d}}]
,Hue[0.5,0.75,1,0.45]
,Polygon[{{-d,0,-d},{d,0,-d},{d,0,d},{-d,0,d},{-d,0,-d}}]
,White,Arrowheads[0.05],Arrow[Tube[{{-d s,0,0},{d s,0,0}},0.02]]
,Arrow[Tube[{{0,-d s,0},{0,d s,0}},0.02]]
,Arrow[Tube[{{0,0,-d s},{0,0,d s}},0.02]]
}
}]
,Button[,ellipsoidDemo0=]]
,{{ellipsoidDemo0,},{,},ControlType-> Toggler}]

You can steer it in any direction by moving azimuthal angle ϕ and elevation angle θ.

Here is an example of 3D normal distribution similar to the above. The code is deliberately shown line by line so that you can follow.

(* below, we use an diagonal ellipsoid: its axes are aligned with the
cartesian axes. Of course, you can use the rotation matrix

           (({{Cos[θ] Cos[ϕ], Cos[θ] Sin[ϕ], Sin[θ]}, {-Sin[ϕ], Cos[ϕ], 0}, {-Cos[ϕ] Sin[θ], -Sin[θ] Sin[ϕ], Cos[θ]}}))

with azimuthal ϕ and elevation angle θ in the app above to generate
any arbitrary ellipsoid *)

μ3D0={0.,0.,0.}; Σ3D0=(({{3, 0, 0}, {0, 1.8, 0}, {0, 0, 1.}})) ; nsample3D0=1000; (* you can have more pts: larger nsample3D0 with fast CPU *)
range3D0={-7,7};
(* generate sim data *)
example3D=RandomVariate[MultinormalDistribution[μ3D0,Σ3D0],nsample3D0]; 

(* obtain descriptive stats *)
cov3D0=Covariance[example3D];
mean3D0=Mean[example3D];

(* let mean point be a little red sphere  *)
radiusMP=0.2;
meanPt3D0=Graphics3D[{Red,Opacity[0.9],Sphere[mean3D0,radiusMP]}];

(* let draw a 2-sigma ellipsoid and a 3-sigma ellipsoid *)
covarEll3D0=Graphics3D[{Hue[0.85,1,1,0.2],Ellipsoid[mean3D0,4cov3D0]
,Hue[0.5,1,1,0.2],Ellipsoid[mean3D0,9cov3D0]}];

Grid[{{data3Dptplot=ListPointPlot3D[example3D,PlotRange->  {range3D0,range3D0,range3D0}
,ColorFunction->"BrightBands"
,BoxRatios->{1, 1, 1}
,Background->Black, ImageSize->350]

,Show[data3Dptplot,meanPt3D0,covarEll3D0
,PlotRange-> {range3D0,range3D0,range3D0},BoxRatios->{1, 1, 1}, ImageSize->350
,Background->Black]
}}]

The best way to see your data is to fly through it

code

Block[{rotV,tFly,tFly0,ϕT,ϕT0, ϕV0,orbit,tinit,Pv,Rv
,am0, m0,rm0,p0,θVparm,ϕF,θVf
,orbitParm,ϕVx,Rv0x,rmx,px,ϕrx,θVx,amx,mx
,θVold,amold,mold,ϕVold,Rv0old,rmold,pold,ϕrold
},
Manipulate[
If[TrueQ[FLY],
Column[{

Grid[{{Button["orbit",{If[TrueQ[ORBIT],ORBIT=False,ORBIT=True]}]
,Button["fly",{If[TrueQ[FLYVIEW],FLYVIEW=False,FLYVIEW=True]}]}
,{If[TrueQ[ORBIT],
Manipulate[
If[!TrueQ[{θVold,amold,mold,ϕVold,Rv0old,rmold,pold,ϕrold}== {θV,am,m,ϕV,Rv0,rm,p,ϕr}],
orbit= ParametricPlot3D[Rv0*(1+rm Cos[2 π p s+ϕr]){Cos[  2 π s]Sin[θVf[s,θVparm]]
, Sin[ 2 π s]Sin[θVf[s,θVparm]]
,Cos[θVf[s,θVparm]]}
,{s,0.,1}, PlotStyle->{Thickness[0.01],Blue}];
{θVold,amold,mold,ϕVold,Rv0old,rmold,pold,ϕrold}= {θV,am,m,ϕV,Rv0,rm,p,ϕr};
θVparm={θVold,amold,mold};
orbitParm={ϕVold,{Rv0old,rmold,pold,ϕrold}}  ;
,];
Show[orbit,Graphics3D[{Cuboid[pcorner1,pcorner2]
(*,Sphere[Pv,0.6] *)}]
, PlotRange-> {{-50,50},{-50,50},{-50,50}}
,ImageSize-> 300
]

,Grid[{{Control[{{am,am0},0.,0.6}],Control[{{m,m0},Range[4]-1}]}
,{Control[{{rm,rm0},0.,1.1}],Control[{{p,p0},Range[4]-1}]},{Control[{ϕr,0.9,2 π}],}}]
,Grid[{{Control[{{ϕV,-2., "view azith"},-π,π,ImageSize-> 100}] ,Control[{{θV,1.22, "view polar"},0.,π,ImageSize-> 100}] }
,{Control[{{Rv0,25, "view dist"},0.1,50,ImageSize-> 100}]
,}}]]
,]

,If[TrueQ[FLYVIEW],

Column[{
Manipulate[
nx=n
,{{n,4},3,8,1} ]
,Manipulate[
If[!TrueQ[orbinit],{ϕVx,{Rv0x,rmx,px,ϕrx}}={ϕVold,{Rv0old,rmold,pold,ϕrold}} (*orbitParm *) ;
{θVx,amx,mx}={θVold,amold,mold}  (* θVparm *) ; 
orbinit=True
,]; 
tFly=t/nx ;
ϕF= rotV*(tFly-tFly0)+((ϕVx+ϕV0 )/(2 π));
Rv=Rv0x (1+rmx Cos[ px 2 π ϕF+ϕrx]);
Pv=Rv*{Cos[2 π  ϕF]Sin[θVf[ϕF,θVparm]]
, Sin[2 π  ϕF]Sin[θVf[ϕF,θVparm]]
,Cos[θVf[ϕF,θVparm] ]};

ϕT=Mod[ 2 π (tFly-tFly0)+ϕVx+ϕV0,2 π]   ;
{
Show[datacloud
, PlotRange-> {range3D0,range3D0,range3D0}
,ImageSize-> 300
,ViewVector-> {Pv,viewcenter}
,ViewAngle-> 0.32] 
,Column[{
Button["show flight path",If[TrueQ[SHOWfly],SHOWfly=False,SHOWfly=True]],
If[TrueQ[SHOWfly],Show[orbit,Graphics3D[{Cuboid[pcorner1,pcorner2]
,Sphere[Pv,4]}]
, PlotRange-> {{-50,50},{-50,50},{-50,50}}
,ImageSize-> 300
],]
}]

}
,Grid[{{Control[{t,tinit,tinit+5,0.001,ControlType->  Animator,AnimationRunning-> True
,DefaultDuration->45,DisplayAllSteps-> True}],Spacer[10]
,Button[If[TrueQ[rotV==1],,],
{tinit=t;(* am0=amx; m0=mx;rm0=rmx; p0=px; *)
If[TrueQ[rotV==1],rotV=0; ϕT0= ϕT  ;tFly0=tFly;ϕV0=ϕT0-ϕVx
,rotV=1 ;ϕV0=Mod[ϕV0-(ϕT-ϕT0),2 π]]}]
,Button["new orbit",orbinit=False]}}]
]

}]
,]}},Alignment-> Top]
}]
,]
,{{FLY,False,TextCell[Style["the best way to see your data is to fly through it -> ",20,White,FontFamily->"Century Gothic"]
,Background->Black]},{True,False}}
,Initialization:>{
datacloud=;
range3D0={-7,7};
{rotV,tFly0,ϕT0, ϕV0}={1,0.,0.,0.};
viewcenter={0.,0.,0.};
{pcorner1,pcorner2}={{-0.5,-0.5,-0.5},{0.5,0.5,0.5}};
tinit=0.;am0=0.1; m0=1;rm0=1.05;p0=2;
θVf[s_,{θV_,am_,m_}]:=θV (1+am Cos[2 π m s]);
SHOWfly=False;ORBIT=False

}]
]

Here is an example that we will look later: we’ll use height, shouldwidth and chestgirth to distinguish the gender (must execute to read in data - this data is the same as in E .2.0)

Data on human body measurements (open up to see details if needed - but not necessary - just shift+enter)

menbodstat={{21.`,1,174.`,65.6`,42.9`,26.`,106.2`,89.5`,71.5`},{23.`,1,175.3`,71.8`,43.7`,28.5`,110.5`,97.`,79.`},{28.`,1,193.5`,80.7`,40.1`,28.2`,115.1`,97.5`,83.2`},{23.`,1,186.5`,72.6`,44.3`,29.9`,104.5`,97.`,77.8`},{22.`,1,187.2`,78.8`,42.5`,29.9`,107.5`,97.5`,80.`},{21.`,1,181.5`,74.8`,43.3`,27.`,119.8`,99.9`,82.5`},{26.`,1,184.`,86.4`,43.5`,30.`,123.5`,106.9`,82.`},{27.`,1,184.5`,78.4`,44.4`,29.8`,120.4`,102.5`,76.8`},{23.`,1,175.`,62.`,43.5`,26.5`,111.`,91.`,68.5`},{21.`,1,184.`,81.6`,42.`,28.`,119.5`,93.5`,77.5`},{23.`,1,180.`,76.6`,40.3`,29.`,117.1`,97.7`,81.9`},{22.`,1,177.8`,83.6`,43.7`,29.`,123.5`,99.5`,82.6`},{20.`,1,192.`,90.`,47.4`,29.6`,116.5`,103.`,85.`},{26.`,1,176.`,74.6`,40.3`,27.5`,113.`,99.6`,85.6`},{23.`,1,174.`,71.`,41.`,26.8`,107.5`,101.5`,78.`},{22.`,1,184.`,79.6`,45.`,27.`,112.`,104.1`,82.`},{30.`,1,192.7`,93.8`,39.9`,30.`,112.2`,100.`,88.3`},{22.`,1,171.5`,70.`,43.`,26.5`,120.`,93.8`,73.6`},{29.`,1,173.`,72.4`,43.1`,28.6`,109.`,98.5`,78.5`},{22.`,1,176.`,85.9`,43.6`,29.3`,118.5`,104.`,87.3`},{22.`,1,176.`,78.8`,42.`,27.5`,116.`,100.`,92.`},{20.`,1,180.5`,77.8`,43.8`,28.`,111.`,100.`,80.`},{22.`,1,172.7`,66.2`,42.3`,26.4`,117.7`,99.`,74.5`},{24.`,1,176.`,86.4`,42.7`,29.9`,123.9`,101.`,90.6`},{26.`,1,173.5`,81.8`,44.8`,27.8`,120.6`,101.6`,81.4`},{24.`,1,178.`,89.6`,46.`,30.1`,129.5`,108.8`,89.5`},{21.`,1,180.3`,82.8`,45.4`,31.8`,115.`,100.`,85.`},{24.`,1,180.3`,76.4`,40.5`,28.3`,116.`,88.`,73.5`},{23.`,1,164.5`,63.2`,39.4`,25.5`,107.8`,88.7`,75.8`},{19.`,1,173.`,60.9`,40.2`,27.2`,100.2`,84.5`,74.`},{23.`,1,183.5`,74.8`,44.2`,30.3`,113.`,93.6`,77.5`},{25.`,1,175.5`,70.`,41.`,23.6`,117.9`,105.`,74.`},{23.`,1,188.`,72.4`,44.`,31.`,112.5`,90.9`,74.`},{23.`,1,189.2`,84.1`,41.6`,32.`,110.5`,91.2`,82.`},{23.`,1,172.8`,69.1`,41.`,25.1`,112.`,98.4`,73.`},{20.`,1,170.`,59.5`,41.5`,24.5`,104.`,85.`,70.5`},{22.`,1,182.`,67.2`,41.1`,27.8`,114.8`,97.2`,75.`},{24.`,1,170.`,61.3`,38.8`,27.2`,108.`,91.5`,72.1`},{22.`,1,177.8`,68.6`,36.2`,27.5`,111.2`,91.2`,78.8`},{24.`,1,184.2`,80.1`,42.1`,27.5`,118.3`,101.1`,77.5`},{21.`,1,186.7`,87.8`,40.3`,29.4`,115.2`,104.3`,91.5`},{23.`,1,171.4`,84.7`,41.7`,27.1`,129.9`,110.8`,84.9`},{24.`,1,172.7`,73.4`,37.8`,27.1`,112.9`,96.3`,79.1`},{35.`,1,175.3`,72.1`,39.2`,26.1`,112.2`,102.7`,77.9`},{29.`,1,180.3`,82.6`,41.5`,30.8`,117.1`,103.9`,91.7`},{25.`,1,182.9`,88.7`,42.5`,27.8`,118.7`,105.6`,86.6`},{23.`,1,188.`,84.1`,39.4`,26.1`,109.2`,95.8`,84.7`},{20.`,1,177.2`,94.1`,43.6`,33.1`,128.1`,111.2`,90.3`},{25.`,1,172.1`,74.9`,38.9`,24.9`,113.3`,100.`,79.7`},{29.`,1,167.`,59.1`,37.6`,24.4`,108.4`,91.6`,73.1`},{23.`,1,169.5`,75.6`,39.4`,28.3`,118.7`,108.`,79.8`},{23.`,1,174.`,86.2`,38.5`,26.1`,126.3`,109.6`,81.6`},{36.`,1,172.7`,75.3`,40.1`,27.8`,124.2`,105.7`,76.8`},{25.`,1,182.2`,87.1`,40.3`,28.`,126.7`,109.1`,85.9`},{24.`,1,164.1`,55.2`,37.6`,26.6`,103.3`,88.8`,73.3`},{20.`,1,163.`,57.`,38.3`,25.2`,101.2`,86.1`,69.9`},{52.`,1,171.5`,61.4`,39.7`,28.6`,104.3`,91.3`,72.7`},{50.`,1,184.2`,76.8`,42.2`,29.`,113.2`,100.6`,82.7`},{46.`,1,174.`,86.8`,41.1`,30.4`,121.9`,105.5`,90.1`},{51.`,1,174.`,72.2`,40.5`,29.3`,113.1`,97.5`,82.9`},{28.`,1,177.`,71.6`,41.5`,28.6`,108.5`,94.4`,77.9`},{48.`,1,186.`,84.8`,43.4`,32.4`,113.9`,99.6`,92.5`},{35.`,1,167.`,68.2`,43.5`,26.`,112.6`,98.1`,77.8`},{23.`,1,171.8`,66.1`,41.3`,27.1`,110.2`,93.6`,72.7`},{23.`,1,182.`,72.`,40.3`,29.5`,108.7`,93.4`,75.`},{62.`,1,167.`,64.6`,36.3`,29.2`,104.`,92.`,76.`},{21.`,1,177.8`,74.8`,39.9`,28.3`,115.2`,99.2`,82.7`},{26.`,1,164.5`,70.`,39.8`,28.8`,111.9`,97.6`,80.`},{33.`,1,192.`,101.6`,43.5`,33.2`,127.`,108.8`,107.1`},{36.`,1,175.5`,63.2`,41.2`,26.6`,111.2`,91.9`,76.2`},{41.`,1,171.2`,79.1`,44.`,28.4`,122.`,105.2`,90.2`},{40.`,1,181.6`,78.9`,41.8`,28.5`,114.5`,98.3`,89.4`},{27.`,1,167.4`,67.7`,42.9`,27.5`,109.5`,92.5`,80.9`},{27.`,1,181.1`,66.`,38.7`,24.6`,110.8`,92.5`,73.5`},{23.`,1,177.`,68.2`,41.4`,26.4`,118.8`,101.6`,70.9`},{31.`,1,174.5`,63.9`,39.6`,27.5`,108.`,94.6`,76.1`},{26.`,1,177.5`,72.`,40.5`,27.5`,114.3`,92.5`,81.`},{23.`,1,170.5`,56.8`,34.1`,28.1`,105.4`,88.2`,72.`},{24.`,1,182.4`,74.5`,43.5`,28.8`,115.`,91.`,76.8`},{24.`,1,197.1`,90.9`,44.1`,29.2`,119.5`,106.`,86.`},{34.`,1,180.1`,93.`,42.2`,32.6`,130.`,115.`,98.5`},{21.`,1,175.5`,80.9`,42.2`,30.1`,113.3`,100.`,79.`},{25.`,1,180.6`,72.7`,43.`,26.5`,113.2`,94.7`,77.5`},{34.`,1,184.4`,68.`,39.8`,28.7`,106.9`,92.5`,75.2`},{31.`,1,175.5`,70.9`,37.7`,29.7`,113.8`,96.7`,82.`},{40.`,1,180.6`,72.5`,39.6`,27.9`,117.3`,97.4`,79.6`},{21.`,1,177.`,72.5`,43.2`,26.3`,124.2`,106.7`,75.2`},{33.`,1,177.1`,83.4`,44.3`,28.2`,123.`,106.2`,88.6`},{25.`,1,181.6`,75.5`,43.3`,28.2`,117.8`,103.6`,81.5`},{29.`,1,176.5`,73.`,42.8`,27.5`,118.8`,98.3`,79.9`},{27.`,1,175.`,70.2`,41.5`,30.`,112.`,87.8`,73.5`},{44.`,1,174.`,73.4`,42.`,27.6`,113.`,99.8`,80.3`},{26.`,1,165.1`,70.5`,41.2`,27.1`,116.`,104.6`,81.5`},{22.`,1,177.`,68.9`,43.8`,29.5`,112.8`,86.5`,74.`},{37.`,1,192.`,102.3`,46.2`,31.`,125.`,110.`,104.`},{38.`,1,176.5`,68.4`,40.4`,28.6`,108.3`,93.2`,76.2`},{20.`,1,169.4`,65.9`,40.8`,27.1`,108.2`,90.`,76.5`},{21.`,1,182.1`,75.7`,43.9`,27.`,113.`,98.4`,81.`},{24.`,1,179.8`,84.5`,44.2`,27.9`,115.`,107.2`,88.8`},{45.`,1,175.3`,87.7`,41.6`,28.`,123.`,108.3`,94.`},{25.`,1,184.9`,86.4`,38.1`,30.1`,120.2`,105.7`,83.4`},{22.`,1,177.3`,73.2`,42.`,28.`,114.`,88.5`,77.`},{29.`,1,167.4`,53.9`,37.`,27.3`,102.9`,79.3`,75.4`},{37.`,1,178.1`,72.`,41.6`,27.5`,112.5`,90.9`,80.3`},{20.`,1,168.9`,55.5`,40.1`,19.4`,104.5`,90.2`,68.`},{20.`,1,157.2`,58.4`,38.7`,25.2`,111.3`,91.6`,80.6`},{32.`,1,180.3`,83.2`,37.4`,29.9`,117.2`,105.2`,88.6`},{23.`,1,170.2`,72.7`,41.7`,28.`,112.8`,97.`,81.1`},{25.`,1,177.8`,64.1`,38.`,27.1`,104.8`,85.3`,70.8`},{27.`,1,172.7`,72.3`,40.5`,24.9`,117.7`,99.6`,73.3`},{21.`,1,165.1`,65.`,35.6`,28.5`,107.7`,94.3`,75.9`},{27.`,1,186.7`,86.4`,43.6`,30.2`,125.2`,111.8`,86.2`},{25.`,1,165.1`,65.`,37.6`,24.4`,109.1`,94.3`,75.`},{38.`,1,174.`,88.6`,41.1`,31.7`,122.6`,106.1`,101.`},{44.`,1,175.3`,84.1`,42.1`,30.6`,117.3`,102.`,90.`},{27.`,1,185.4`,66.8`,40.5`,28.3`,109.1`,94.8`,75.`},{37.`,1,177.8`,75.5`,40.9`,28.5`,116.7`,102.9`,75.9`},{28.`,1,180.3`,93.2`,43.`,30.6`,124.9`,115.8`,96.`},{33.`,1,180.3`,82.7`,40.5`,27.8`,118.6`,105.4`,84.`},{25.`,1,177.8`,58.`,41.9`,25.4`,108.8`,87.1`,67.1`},{21.`,1,177.8`,79.5`,42.1`,28.5`,121.9`,104.1`,82.5`},{30.`,1,177.8`,78.6`,43.8`,29.2`,117.3`,95.8`,83.7`},{26.`,1,177.8`,71.8`,42.1`,28.5`,115.`,98.6`,76.7`},{27.`,1,177.8`,116.4`,43.4`,32.`,134.8`,118.7`,105.2`},{33.`,1,163.8`,72.2`,38.7`,26.8`,113.8`,100.9`,90.6`},{29.`,1,188.`,83.6`,39.6`,28.7`,119.4`,98.5`,85.7`},{27.`,1,198.1`,85.5`,43.4`,30.6`,117.9`,96.9`,82.5`},{34.`,1,175.3`,90.9`,40.5`,29.7`,127.3`,110.7`,94.7`},{42.`,1,166.4`,85.9`,40.3`,30.4`,118.8`,108.`,105.2`},{29.`,1,190.5`,89.1`,44.2`,30.6`,122.4`,109.`,86.`},{41.`,1,166.4`,75.`,41.3`,26.8`,111.5`,104.2`,90.9`},{43.`,1,177.8`,77.7`,39.8`,25.6`,113.2`,100.5`,92.4`},{43.`,1,179.7`,86.4`,41.3`,29.`,115.3`,105.7`,96.5`},{29.`,1,172.7`,90.9`,38.9`,27.5`,122.5`,112.4`,98.4`},{27.`,1,190.5`,73.6`,41.1`,25.6`,114.4`,96.2`,76.7`},{62.`,1,185.4`,76.4`,41.5`,30.6`,112.8`,97.5`,94.8`},{33.`,1,168.9`,69.1`,38.5`,27.8`,112.2`,90.9`,80.1`},{45.`,1,167.6`,84.5`,39.4`,29.7`,119.4`,108.4`,97.4`},{30.`,1,175.3`,64.5`,40.9`,26.1`,108.4`,94.3`,73.7`},{20.`,1,170.2`,69.1`,41.1`,23.`,122.4`,109.1`,76.1`},{22.`,1,190.5`,108.6`,43.6`,28.`,128.8`,115.`,95.6`},{51.`,1,177.8`,86.4`,39.8`,29.`,118.`,104.4`,101.`},{34.`,1,190.5`,80.9`,42.1`,27.8`,116.5`,100.1`,84.5`},{44.`,1,177.8`,87.7`,41.1`,27.1`,120.4`,108.4`,98.`},{46.`,1,184.2`,94.5`,44.2`,30.4`,123.1`,107.3`,101.6`},{34.`,1,176.5`,80.2`,38.9`,26.8`,117.2`,101.8`,87.8`},{32.`,1,177.8`,72.`,40.1`,28.7`,113.`,94.5`,80.`},{28.`,1,180.3`,71.4`,38.7`,26.8`,109.4`,91.7`,81.8`},{31.`,1,171.4`,72.7`,35.6`,26.4`,105.7`,95.9`,84.4`},{29.`,1,172.7`,84.1`,40.5`,26.8`,119.7`,110.5`,85.`},{42.`,1,172.7`,76.8`,41.1`,25.4`,118.`,104.`,90.`},{29.`,1,177.8`,63.6`,38.7`,26.1`,104.3`,86.8`,72.9`},{31.`,1,177.8`,80.9`,38.9`,27.1`,114.1`,106.7`,81.`},{30.`,1,182.9`,80.9`,39.4`,29.7`,119.`,102.5`,86.5`},{27.`,1,170.2`,85.5`,37.6`,27.8`,113.8`,103.`,93.9`},{25.`,1,167.6`,68.6`,39.8`,25.9`,118.`,95.`,77.`},{24.`,1,175.3`,67.7`,40.3`,27.3`,116.`,99.`,75.`},{33.`,1,165.1`,66.4`,40.3`,25.2`,108.3`,89.7`,80.6`},{45.`,1,185.4`,102.3`,43.8`,30.4`,129.2`,111.5`,100.5`},{37.`,1,181.6`,70.5`,41.1`,27.8`,109.2`,94.1`,81.2`},{44.`,1,172.7`,95.9`,41.7`,30.6`,124.3`,118.3`,103.4`},{34.`,1,190.5`,84.1`,45.4`,30.8`,122.6`,106.5`,90.3`},{55.`,1,179.1`,87.3`,43.`,30.8`,122.4`,110.4`,98.`},{43.`,1,175.3`,71.8`,41.1`,25.4`,114.9`,102.3`,86.5`},{24.`,1,170.2`,65.9`,41.1`,29.2`,111.1`,98.5`,77.9`},{22.`,1,193.`,95.9`,45.2`,32.2`,126.`,111.6`,89.1`},{38.`,1,171.4`,91.4`,39.8`,34.7`,115.5`,106.7`,93.9`},{24.`,1,177.8`,81.8`,39.6`,28.7`,124.7`,110.4`,85.3`},{29.`,1,177.8`,96.8`,42.3`,30.2`,125.3`,114.`,98.5`},{25.`,1,167.6`,69.1`,40.9`,29.`,118.2`,101.8`,79.5`},{37.`,1,167.6`,82.7`,39.8`,28.`,124.3`,109.6`,94.9`},{30.`,1,180.3`,75.5`,42.3`,27.1`,118.3`,100.7`,76.5`},{26.`,1,182.9`,79.5`,42.3`,26.8`,122.3`,104.3`,88.4`},{35.`,1,176.5`,73.6`,40.5`,28.7`,116.5`,104.2`,84.2`},{29.`,1,186.7`,91.8`,42.7`,28.5`,123.`,107.4`,87.6`},{30.`,1,188.`,84.1`,43.6`,30.8`,117.6`,101.`,83.7`},{37.`,1,188.`,85.9`,42.5`,31.3`,117.5`,103.`,92.1`},{34.`,1,177.8`,81.8`,41.3`,30.8`,117.3`,107.2`,89.9`},{28.`,1,174.`,82.5`,41.3`,24.7`,114.5`,99.`,88.7`},{27.`,1,177.8`,80.5`,42.3`,26.6`,122.9`,100.3`,83.9`},{32.`,1,171.4`,70.`,36.9`,25.9`,115.5`,100.2`,79.5`},{28.`,1,185.4`,81.8`,40.3`,28.5`,116.1`,99.8`,84.5`},{22.`,1,185.4`,84.1`,40.1`,26.4`,121.6`,107.5`,89.2`},{44.`,1,188.`,90.5`,43.2`,31.3`,131.6`,110.1`,90.7`},{25.`,1,188.`,91.4`,45.`,29.`,124.5`,107.`,88.8`},{49.`,1,182.9`,89.1`,42.1`,29.7`,115.6`,105.6`,103.6`},{54.`,1,176.5`,85.`,40.9`,28.7`,117.`,103.6`,98.5`},{49.`,1,175.3`,69.1`,41.3`,27.3`,108.6`,97.1`,82.9`},{60.`,1,175.3`,73.6`,42.1`,29.7`,120.2`,109.8`,90.5`},{42.`,1,188.`,80.5`,45.2`,29.7`,116.2`,103.3`,84.5`},{52.`,1,188.`,82.7`,42.1`,31.1`,115.4`,103.7`,86.`},{23.`,1,175.3`,86.4`,41.2`,29.8`,120.`,108.5`,84.2`},{33.`,1,170.5`,67.7`,41.7`,29.2`,110.3`,97.8`,85.7`},{46.`,1,179.1`,92.7`,43.`,29.4`,119.7`,112.7`,112.1`},{43.`,1,177.8`,93.6`,41.7`,28.5`,123.5`,111.4`,99.7`},{56.`,1,175.3`,70.9`,38.`,29.7`,107.8`,95.1`,84.7`},{21.`,1,182.9`,75.`,41.9`,27.8`,118.7`,100.2`,80.3`},{18.`,1,170.8`,93.2`,40.7`,28.`,120.7`,106.3`,98.6`},{21.`,1,188.`,93.2`,41.3`,29.7`,118.7`,109.5`,90.`},{45.`,1,180.3`,77.7`,40.9`,28.7`,118.`,106.3`,86.6`},{22.`,1,177.8`,61.4`,41.7`,26.8`,105.`,91.5`,80.2`},{55.`,1,185.4`,94.1`,41.3`,31.1`,110.6`,104.9`,109.2`},{42.`,1,168.9`,75.`,41.1`,27.8`,123.1`,109.6`,88.4`},{29.`,1,185.4`,83.6`,43.4`,27.3`,121.`,102.5`,81.`},{40.`,1,180.3`,85.5`,40.7`,27.8`,111.7`,101.2`,88.8`},{24.`,1,174.`,73.9`,42.5`,25.2`,111.`,98.7`,78.1`},{62.`,1,167.6`,66.8`,40.3`,28.3`,112.`,96.`,81.5`},{26.`,1,182.9`,87.3`,39.8`,27.8`,115.9`,104.2`,87.6`},{35.`,1,160.`,72.3`,39.8`,28.3`,121.`,103.`,92.5`},{37.`,1,180.3`,88.6`,40.5`,29.9`,123.6`,107.`,97.`},{34.`,1,167.6`,75.5`,41.1`,26.8`,120.`,101.`,82.`},{25.`,1,186.7`,101.4`,42.5`,29.4`,128.7`,112.1`,99.5`},{30.`,1,175.3`,91.1`,42.5`,29.4`,124.5`,103.4`,93.8`},{32.`,1,175.3`,67.3`,38.5`,24.4`,112.4`,100.3`,79.1`},{27.`,1,175.9`,77.7`,43.8`,29.2`,112.2`,95.7`,85.8`},{42.`,1,175.3`,81.8`,41.5`,29.`,127.`,108.`,90.8`},{44.`,1,179.1`,75.5`,40.3`,27.8`,115.3`,101.`,85.4`},{46.`,1,181.6`,84.5`,40.3`,30.2`,111.5`,98.6`,91.6`},{19.`,1,177.8`,76.6`,42.1`,27.1`,118.3`,101.6`,79.7`},{43.`,1,182.9`,85.`,42.1`,31.3`,118.`,99.`,86.1`},{28.`,1,177.8`,102.5`,38.9`,29.4`,127.`,116.7`,113.2`},{39.`,1,184.2`,77.3`,44.4`,24.`,124.4`,105.`,79.5`},{30.`,1,179.1`,71.8`,40.9`,24.4`,112.4`,95.1`,85.4`},{36.`,1,176.5`,87.9`,42.1`,28.7`,125.8`,106.7`,97.9`},{48.`,1,188.`,94.3`,43.`,27.1`,131.7`,116.6`,94.7`},{48.`,1,174.`,70.9`,38.`,27.1`,117.3`,103.5`,86.1`},{53.`,1,167.6`,64.5`,37.1`,24.2`,107.6`,90.4`,84.9`},{45.`,1,170.2`,77.3`,41.1`,24.`,122.4`,107.5`,92.2`},{39.`,1,167.6`,72.3`,40.9`,24.4`,117.`,100.8`,83.7`},{43.`,1,188.`,87.3`,38.9`,27.1`,119.`,104.2`,97.8`},{65.`,1,174.`,80.`,40.9`,28.3`,123.5`,104.9`,98.6`},{45.`,1,176.5`,82.3`,39.2`,26.8`,121.4`,112.8`,89.5`},{37.`,1,180.3`,73.6`,41.7`,26.6`,112.3`,95.7`,82.9`},{55.`,1,167.6`,74.1`,39.4`,26.6`,113.2`,104.9`,90.1`},{33.`,1,188.`,85.9`,40.1`,26.4`,121.7`,109.1`,78.9`},{25.`,1,180.3`,73.2`,38.9`,25.6`,116.6`,105.4`,80.7`},{35.`,1,167.6`,76.3`,38.9`,26.4`,117.8`,104.3`,94.3`},{28.`,1,183.`,65.9`,41.7`,26.4`,118.`,100.5`,70.2`},{26.`,1,183.`,90.9`,43.2`,26.8`,131.1`,111.8`,83.6`},{43.`,1,179.1`,89.1`,40.5`,29.2`,121.4`,109.5`,91.9`},{30.`,1,170.2`,62.3`,39.2`,23.5`,116.3`,101.2`,71.8`},{26.`,1,177.8`,82.7`,40.9`,25.4`,121.8`,103.3`,85.`},{51.`,1,179.1`,79.1`,41.7`,27.3`,118.2`,101.6`,85.7`},{30.`,1,190.5`,98.2`,43.8`,32.2`,126.3`,103.1`,96.5`},{24.`,1,177.8`,84.1`,41.9`,28.`,121.`,104.6`,82.4`},{35.`,1,180.3`,83.2`,43.`,27.8`,123.1`,104.3`,86.3`},{37.`,1,180.3`,83.2`,41.5`,28.5`,114.9`,95.9`,83.2`}};

womenbodstat={{22.`,0,161.2`,51.6`,37.6`,25.`,95.`,83.`,66.5`},{20.`,0,167.5`,59.`,36.7`,26.4`,99.5`,78.5`,61.5`},{19.`,0,159.5`,49.2`,34.8`,25.9`,88.`,75.`,61.2`},{25.`,0,157.`,63.`,36.6`,27.9`,97.`,86.5`,78.`},{21.`,0,155.8`,53.6`,35.5`,28.2`,103.3`,91.`,70.5`},{23.`,0,170.`,59.`,37.`,28.`,93.5`,79.5`,66.5`},{26.`,0,159.1`,47.6`,35.5`,26.5`,93.3`,77.`,58.`},{22.`,0,166.`,69.8`,37.4`,30.2`,94.5`,88.`,74.5`},{28.`,0,176.2`,66.8`,37.8`,29.`,98.6`,85.`,73.5`},{40.`,0,160.2`,75.2`,38.6`,28.8`,115.5`,98.8`,90.5`},{32.`,0,172.5`,55.2`,37.6`,28.5`,97.9`,79.`,66.5`},{25.`,0,170.9`,54.2`,36.`,25.6`,97.7`,77.6`,61.`},{25.`,0,172.9`,62.5`,39.5`,30.`,100.5`,85.`,69.5`},{29.`,0,153.4`,42.`,34.`,25.`,88.7`,76.7`,62.`},{22.`,0,160.`,50.`,35.`,26.5`,96.6`,76.7`,63.4`},{25.`,0,147.2`,49.8`,35.6`,25.8`,92.`,82.`,71.`},{23.`,0,168.2`,49.2`,36.2`,27.4`,90.`,79.`,59.`},{37.`,0,175.`,73.2`,39.`,28.4`,104.`,89.5`,74.`},{19.`,0,157.`,47.8`,32.6`,25.6`,90.1`,73.5`,60.5`},{23.`,0,167.6`,68.8`,37.6`,30.`,104.`,90.`,75.`},{25.`,0,159.5`,50.6`,36.3`,27.5`,91.`,80.`,65.`},{26.`,0,175.`,82.5`,38.`,29.6`,111.4`,94.5`,82.2`},{24.`,0,166.8`,57.2`,37.`,27.9`,96.2`,83.8`,70.2`},{29.`,0,176.5`,87.8`,42.6`,31.8`,117.1`,95.2`,85.`},{22.`,0,170.2`,72.8`,37.5`,29.2`,101.5`,91.`,75.`},{30.`,0,174.`,54.5`,36.1`,28.2`,95.1`,80.`,63.`},{23.`,0,173.`,59.8`,39.1`,27.5`,97.1`,81.7`,70.`},{38.`,0,179.9`,67.3`,39.6`,28.6`,101.4`,89.6`,72.6`},{23.`,0,170.5`,67.8`,40.5`,29.6`,103.7`,90.9`,78.7`},{19.`,0,160.`,47.`,35.`,26.`,89.2`,78.5`,61.`},{46.`,0,154.4`,46.2`,34.5`,26.4`,86.`,78.`,64.2`},{20.`,0,162.`,55.`,35.6`,27.9`,98.1`,80.2`,63.1`},{22.`,0,176.5`,83.`,39.1`,29.7`,114.`,99.`,85.`},{25.`,0,160.`,54.4`,36.6`,28.2`,95.`,80.`,66.`},{21.`,0,152.`,45.8`,34.8`,26.3`,87.`,75.5`,65.`},{23.`,0,162.1`,53.6`,36.7`,22.1`,100.8`,82.6`,63.2`},{31.`,0,170.`,73.2`,39.7`,31.6`,112.2`,94.5`,83.6`},{29.`,0,160.2`,52.1`,35.5`,24.3`,98.7`,83.9`,68.`},{19.`,0,161.3`,67.9`,36.`,28.`,100.1`,92.8`,75.7`},{21.`,0,166.4`,56.6`,35.8`,26.4`,100.3`,85.3`,65.5`},{23.`,0,168.9`,62.3`,37.6`,27.3`,100.5`,84.4`,66.9`},{24.`,0,163.8`,58.5`,37.6`,28.7`,101.2`,87.6`,67.9`},{20.`,0,167.6`,54.5`,34.9`,28.`,96.`,81.`,67.8`},{19.`,0,160.`,50.2`,33.3`,24.9`,92.8`,84.1`,63.2`},{20.`,0,161.3`,60.3`,36.2`,27.1`,95.5`,88.2`,73.1`},{19.`,0,167.6`,58.3`,33.3`,29.2`,98.7`,88.1`,65.3`},{20.`,0,165.1`,56.2`,36.`,25.2`,96.9`,84.9`,65.6`},{19.`,0,160.`,50.2`,34.`,27.3`,91.`,81.2`,62.7`},{22.`,0,170.`,72.9`,36.2`,28.7`,106.3`,91.6`,81.8`},{39.`,0,157.5`,59.8`,34.9`,27.1`,99.8`,88.4`,72.1`},{18.`,0,167.6`,61.`,37.4`,28.3`,105.`,87.6`,68.6`},{19.`,0,160.7`,69.1`,33.8`,28.7`,106.2`,91.3`,80.`},{26.`,0,163.2`,55.9`,34.`,27.3`,97.7`,87.2`,64.9`},{20.`,0,152.4`,46.5`,34.4`,23.5`,97.4`,82.2`,61.7`},{20.`,0,157.5`,54.3`,34.7`,27.8`,96.3`,82.1`,64.`},{26.`,0,168.3`,54.8`,35.6`,26.4`,98.`,82.6`,58.6`},{21.`,0,180.3`,60.7`,33.8`,29.7`,94.5`,86.5`,68.3`},{21.`,0,165.5`,60.`,37.8`,26.6`,101.4`,85.3`,69.5`},{38.`,0,165.`,62.`,38.3`,30.4`,95.1`,84.7`,70.5`},{23.`,0,164.5`,60.3`,40.3`,29.2`,101.1`,86.8`,69.8`},{37.`,0,156.`,52.7`,38.9`,27.5`,97.4`,85.2`,69.`},{19.`,0,160.`,74.3`,39.4`,29.2`,104.8`,93.9`,81.`},{25.`,0,163.`,62.`,35.`,27.`,94.5`,84.5`,71.`},{20.`,0,165.7`,73.1`,40.7`,29.`,103.2`,90.7`,73.6`},{41.`,0,161.`,80.`,39.6`,30.4`,110.8`,97.4`,96.3`},{26.`,0,162.`,54.7`,36.9`,28.3`,94.6`,83.3`,65.`},{21.`,0,166.`,53.2`,35.6`,25.7`,96.6`,82.1`,62.8`},{47.`,0,174.`,75.7`,38.2`,30.`,102.8`,92.2`,83.`},{19.`,0,172.7`,61.1`,36.9`,29.`,96.9`,83.6`,67.6`},{44.`,0,167.6`,55.7`,36.9`,26.9`,95.6`,82.6`,65.4`},{35.`,0,151.1`,48.7`,34.8`,26.4`,92.4`,77.`,61.6`},{32.`,0,164.5`,52.3`,36.6`,27.5`,93.7`,79.3`,63.2`},{46.`,0,163.5`,50.`,36.9`,27.4`,96.1`,84.3`,59.4`},{22.`,0,152.`,59.3`,36.9`,26.4`,100.1`,85.6`,62.7`},{49.`,0,169.`,62.5`,36.9`,30.2`,98.8`,85.`,66.6`},{52.`,0,164.`,55.7`,36.`,28.6`,92.2`,79.1`,64.6`},{25.`,0,161.2`,54.8`,36.2`,30.2`,97.3`,85.`,65.7`},{48.`,0,155.`,45.9`,35.1`,28.1`,90.5`,79.`,63.`},{41.`,0,170.`,70.6`,38.8`,27.2`,110.5`,96.2`,78.5`},{18.`,0,176.2`,67.2`,36.4`,26.2`,103.`,86.`,68.2`},{30.`,0,170.`,69.4`,38.6`,24.2`,109.`,89.8`,68.5`},{20.`,0,162.5`,58.2`,36.5`,26.`,104.8`,84.5`,68.8`},{24.`,0,170.3`,64.8`,37.5`,27.4`,109.2`,88.2`,69.`},{23.`,0,164.1`,71.6`,39.9`,20.`,117.`,99.5`,78.`},{30.`,0,169.5`,52.8`,34.4`,26.1`,93.9`,76.1`,62.`},{23.`,0,163.2`,59.8`,38.7`,23.5`,105.5`,85.8`,65.8`},{45.`,0,154.5`,49.`,32.6`,24.6`,99.4`,82.`,65.`},{20.`,0,159.8`,50.`,34.5`,25.6`,89.5`,77.5`,64.9`},{20.`,0,173.2`,69.2`,36.7`,28.2`,98.5`,85.7`,71.5`},{23.`,0,170.`,55.9`,36.5`,27.`,94.9`,78.8`,61.4`},{21.`,0,161.4`,63.4`,34.2`,28.`,96.3`,88.`,75.4`},{28.`,0,169.`,58.2`,37.8`,28.6`,96.8`,80.2`,67.2`},{45.`,0,166.2`,58.6`,35.7`,25.5`,102.5`,85.6`,69.5`},{24.`,0,159.4`,45.7`,33.9`,24.3`,95.2`,81.3`,57.9`},{25.`,0,162.5`,52.2`,35.2`,24.1`,103.`,84.6`,64.4`},{19.`,0,159.`,48.6`,37.1`,24.3`,99.1`,82.2`,62.3`},{20.`,0,162.8`,57.8`,37.7`,26.2`,104.1`,84.9`,68.7`},{29.`,0,159.`,55.6`,37.8`,28.1`,99.5`,81.5`,68.`},{24.`,0,179.8`,66.8`,39.3`,24.5`,110.2`,89.9`,66.`},{24.`,0,162.9`,59.4`,37.2`,24.4`,107.1`,89.8`,71.2`},{25.`,0,161.`,53.6`,36.1`,26.8`,95.7`,80.8`,64.8`},{31.`,0,151.1`,73.2`,35.2`,25.1`,103.4`,88.4`,78.`},{22.`,0,168.2`,53.4`,35.8`,27.7`,94.6`,80.2`,60.7`},{20.`,0,168.9`,69.`,35.`,25.6`,104.5`,89.5`,75.`},{32.`,0,173.2`,58.4`,37.8`,29.9`,97.7`,83.7`,68.6`},{25.`,0,171.8`,56.2`,35.7`,27.`,96.4`,82.5`,67.1`},{19.`,0,178.`,70.6`,39.5`,29.8`,103.`,85.5`,68.`},{23.`,0,164.3`,59.8`,38.8`,26.3`,103.4`,88.3`,71.`},{22.`,0,163.`,72.`,37.9`,29.`,109.5`,91.5`,76.`},{20.`,0,168.5`,65.2`,37.7`,25.`,110.7`,92.2`,70.3`},{27.`,0,166.8`,56.6`,38.2`,25.9`,102.2`,80.5`,69.5`},{34.`,0,172.7`,105.2`,40.`,31.`,129.5`,108.`,101.5`},{25.`,0,163.5`,51.8`,35.7`,28.3`,99.2`,80.`,67.2`},{26.`,0,169.4`,63.4`,35.7`,25.9`,104.7`,89.5`,68.7`},{19.`,0,167.8`,59.`,36.`,27.6`,98.9`,84.9`,66.`},{26.`,0,159.5`,47.6`,35.`,25.`,98.5`,80.8`,67.5`},{25.`,0,167.6`,63.`,37.`,26.9`,102.2`,81.`,65.2`},{20.`,0,161.2`,55.2`,36.7`,23.5`,100.2`,88.7`,64.2`},{21.`,0,160.`,45.`,32.8`,26.2`,85.9`,74.5`,61.`},{18.`,0,163.2`,54.`,34.8`,20.3`,99.8`,81.9`,60.2`},{19.`,0,162.2`,50.2`,35.`,23.7`,93.3`,75.8`,62.6`},{27.`,0,161.3`,60.2`,38.7`,27.1`,107.3`,88.`,72.7`},{26.`,0,149.5`,44.8`,32.8`,20.9`,90.`,72.6`,58.5`},{36.`,0,157.5`,58.8`,36.7`,23.`,101.5`,88.`,67.5`},{20.`,0,163.2`,56.4`,38.8`,26.5`,105.1`,86.`,66.1`},{28.`,0,172.7`,62.`,36.4`,24.9`,101.`,85.5`,68.`},{32.`,0,155.`,49.2`,34.`,27.8`,91.9`,80.4`,64.`},{32.`,0,156.5`,67.2`,38.2`,27.5`,112.1`,98.1`,90.1`},{23.`,0,164.`,53.8`,35.1`,23.4`,98.2`,82.`,64.1`},{20.`,0,160.9`,54.4`,36.`,25.2`,102.5`,89.`,72.4`},{20.`,0,162.8`,58.`,35.9`,25.1`,98.4`,85.8`,71.`},{20.`,0,167.`,59.8`,35.`,27.1`,96.8`,85.9`,69.1`},{23.`,0,160.`,54.8`,35.2`,24.4`,103.9`,82.5`,66.1`},{20.`,0,160.`,43.2`,34.9`,26.2`,92.7`,74.5`,59.5`},{28.`,0,168.9`,60.5`,36.`,28.1`,105.`,89.4`,71.5`},{23.`,0,158.2`,46.4`,36.4`,27.7`,94.`,80.3`,65.`},{19.`,0,156.`,64.4`,35.5`,27.7`,101.5`,85.6`,71.5`},{28.`,0,160.`,48.8`,34.1`,18.7`,92.`,83.`,63.`},{19.`,0,167.1`,62.2`,37.1`,25.`,108.5`,88.2`,70.`},{29.`,0,158.`,55.5`,35.2`,26.`,93.8`,85.5`,70.4`},{32.`,0,167.6`,57.8`,37.5`,26.`,99.8`,80.6`,64.3`},{20.`,0,156.`,54.6`,36.3`,24.9`,100.3`,81.`,66.`},{28.`,0,162.1`,59.2`,37.2`,26.`,101.5`,83.6`,70.5`},{36.`,0,173.4`,52.7`,37.6`,27.7`,94.7`,79.4`,62.`},{22.`,0,159.8`,53.2`,33.6`,24.3`,103.1`,82.9`,67.6`},{20.`,0,170.5`,64.5`,34.5`,29.2`,94.5`,83.2`,65.`},{22.`,0,159.2`,51.8`,36.`,27.1`,97.1`,78.1`,64.`},{32.`,0,157.5`,56.`,35.4`,27.`,98.`,82.4`,70.5`},{40.`,0,161.3`,63.6`,35.8`,28.3`,102.4`,90.`,79.2`},{40.`,0,162.6`,63.2`,38.3`,28.3`,109.1`,92.4`,71.1`},{42.`,0,160.`,59.5`,33.8`,28.7`,94.7`,86.7`,74.7`},{40.`,0,168.9`,56.8`,36.9`,31.1`,98.2`,84.`,62.9`},{44.`,0,165.1`,64.1`,34.9`,28.`,101.5`,86.`,70.6`},{30.`,0,162.6`,50.`,35.1`,28.3`,96.6`,84.5`,61.6`},{28.`,0,165.1`,72.3`,37.4`,30.2`,106.1`,91.2`,74.2`},{37.`,0,166.4`,55.`,36.9`,27.5`,100.1`,81.1`,65.5`},{40.`,0,160.`,55.9`,36.`,28.`,105.3`,87.6`,67.7`},{45.`,0,152.4`,60.4`,32.9`,26.6`,99.8`,88.2`,72.9`},{35.`,0,170.2`,69.1`,38.3`,31.7`,103.9`,88.2`,72.1`},{41.`,0,162.6`,84.5`,37.6`,30.7`,111.`,104.2`,93.4`},{27.`,0,170.2`,55.9`,36.7`,28.`,99.`,84.8`,60.7`},{20.`,0,158.8`,55.5`,38.9`,25.2`,102.5`,84.3`,69.2`},{24.`,0,172.7`,69.5`,37.8`,28.`,105.6`,91.`,75.5`},{36.`,0,167.6`,76.4`,38.`,31.7`,99.5`,90.5`,85.6`},{27.`,0,162.6`,61.4`,38.7`,30.4`,106.5`,89.6`,71.6`},{32.`,0,167.6`,65.9`,37.1`,27.1`,104.1`,89.3`,75.5`},{64.`,0,156.2`,58.6`,35.8`,30.2`,99.7`,90.`,73.7`},{21.`,0,175.2`,66.8`,38.5`,30.4`,106.6`,88.2`,67.9`},{32.`,0,172.1`,56.6`,38.5`,30.8`,97.2`,83.5`,71.2`},{35.`,0,162.6`,58.6`,36.`,30.2`,100.8`,91.`,69.3`},{41.`,0,160.`,55.9`,34.`,26.4`,100.7`,88.2`,75.6`},{40.`,0,165.1`,59.1`,38.3`,26.6`,99.1`,82.2`,63.8`},{29.`,0,182.9`,81.8`,38.7`,33.3`,108.9`,98.9`,83.6`},{40.`,0,166.4`,70.7`,36.9`,29.`,109.8`,97.9`,84.9`},{24.`,0,165.1`,56.8`,35.8`,26.6`,99.5`,81.7`,66.`},{23.`,0,177.8`,60.`,36.7`,29.`,100.5`,86.1`,68.3`},{41.`,0,165.1`,58.2`,36.7`,28.`,97.4`,87.1`,63.8`},{44.`,0,175.3`,72.7`,37.6`,31.3`,105.`,76.8`,73.6`},{53.`,0,154.9`,54.1`,35.1`,23.7`,102.9`,87.9`,76.3`},{19.`,0,158.8`,49.1`,35.3`,23.3`,93.9`,81.6`,58.8`},{24.`,0,172.7`,75.9`,38.5`,26.6`,114.2`,92.3`,78.`},{25.`,0,168.9`,55.`,37.8`,29.4`,95.9`,81.3`,64.5`},{20.`,0,161.3`,57.3`,35.1`,25.6`,98.7`,82.2`,65.8`},{34.`,0,167.6`,55.`,32.4`,30.2`,91.2`,78.6`,62.5`},{32.`,0,165.1`,65.5`,39.2`,31.3`,105.1`,94.3`,77.5`},{24.`,0,175.3`,65.5`,38.3`,30.8`,102.3`,89.5`,70.`},{29.`,0,157.5`,48.6`,32.9`,20.9`,93.1`,81.`,59.4`},{31.`,0,163.8`,58.6`,38.`,28.3`,101.7`,85.4`,68.3`},{34.`,0,167.6`,63.6`,37.8`,32.`,105.`,86.2`,77.9`},{36.`,0,165.1`,55.2`,34.2`,29.2`,96.4`,85.3`,68.3`},{32.`,0,165.1`,62.7`,37.6`,31.3`,103.5`,86.1`,72.`},{39.`,0,168.9`,56.6`,35.3`,25.4`,99.8`,84.5`,62.7`},{37.`,0,162.6`,53.9`,34.9`,27.3`,87.`,72.6`,58.`},{52.`,0,164.5`,63.2`,37.4`,32.`,105.2`,90.`,72.7`},{24.`,0,176.5`,73.6`,36.2`,31.1`,102.1`,95.8`,85.4`},{33.`,0,168.9`,62.`,38.9`,29.`,101.3`,85.5`,67.3`},{42.`,0,175.3`,63.6`,36.`,30.4`,99.6`,85.7`,70.8`},{34.`,0,159.4`,53.2`,33.3`,25.9`,99.4`,85.4`,67.4`},{37.`,0,160.`,53.4`,37.4`,29.4`,99.4`,79.1`,66.`},{39.`,0,170.2`,55.`,34.7`,29.4`,99.`,84.4`,63.6`},{41.`,0,162.6`,70.5`,38.7`,28.`,108.2`,90.`,71.7`},{36.`,0,167.6`,54.5`,36.2`,28.3`,96.4`,82.9`,73.6`},{19.`,0,162.6`,54.5`,37.6`,27.8`,101.4`,87.3`,66.9`},{22.`,0,160.7`,55.9`,34.9`,26.1`,98.2`,85.3`,65.5`},{23.`,0,160.`,59.`,34.7`,24.7`,100.6`,87.3`,70.4`},{36.`,0,157.5`,63.6`,34.`,26.8`,108.4`,93.2`,80.3`},{45.`,0,162.6`,54.5`,37.8`,28.5`,100.8`,84.7`,65.`},{25.`,0,152.4`,47.3`,35.1`,27.8`,94.8`,78.`,60.4`},{67.`,0,170.2`,67.7`,39.2`,29.9`,108.2`,90.7`,75.3`},{26.`,0,165.1`,80.9`,35.1`,29.9`,110.7`,95.`,83.4`},{21.`,0,172.7`,70.5`,37.1`,29.2`,102.6`,88.7`,72.2`},{33.`,0,165.1`,60.9`,35.8`,29.4`,98.1`,86.6`,70.1`},{25.`,0,170.2`,63.6`,35.3`,26.8`,92.`,82.5`,69.8`},{24.`,0,170.2`,54.5`,37.6`,26.8`,98.6`,81.4`,66.4`},{21.`,0,170.2`,59.1`,35.8`,29.`,96.1`,79.9`,61.7`},{35.`,0,161.3`,70.5`,36.`,29.2`,107.7`,91.1`,76.4`},{27.`,0,167.6`,52.7`,35.6`,28.3`,95.4`,80.1`,63.8`},{27.`,0,167.6`,62.7`,37.1`,27.8`,99.3`,86.4`,70.2`},{26.`,0,165.1`,86.3`,35.6`,30.2`,115.2`,105.2`,88.2`},{25.`,0,162.6`,66.4`,35.1`,29.4`,96.7`,91.1`,75.8`},{44.`,0,152.4`,67.3`,35.8`,26.8`,109.`,96.7`,81.5`},{29.`,0,168.9`,63.`,37.4`,29.4`,95.1`,80.5`,67.4`},{26.`,0,170.2`,73.6`,38.9`,28.5`,108.4`,90.4`,78.3`},{23.`,0,175.2`,62.3`,37.4`,29.`,98.2`,84.1`,65.9`},{32.`,0,175.2`,57.7`,37.6`,28.3`,99.7`,84.2`,62.4`},{32.`,0,160.`,55.4`,35.1`,26.6`,94.4`,82.5`,65.6`},{43.`,0,165.1`,104.1`,38.`,33.3`,127.1`,106.9`,96.2`},{32.`,0,174.`,55.5`,36.7`,25.2`,94.9`,79.9`,62.5`},{41.`,0,170.2`,77.3`,35.6`,29.9`,98.9`,93.`,80.5`},{33.`,0,160.`,80.5`,35.6`,30.8`,106.4`,96.3`,86.1`},{28.`,0,167.6`,64.5`,35.6`,27.3`,102.2`,86.8`,71.3`},{28.`,0,167.6`,72.3`,37.8`,29.`,110.3`,95.3`,79.4`},{25.`,0,167.6`,61.4`,40.9`,28.7`,107.3`,93.`,72.3`},{38.`,0,154.9`,58.2`,34.`,25.9`,95.`,86.4`,67.4`},{37.`,0,162.6`,81.8`,34.9`,31.3`,115.6`,109.`,94.2`},{25.`,0,175.3`,63.6`,35.8`,31.5`,99.3`,86.2`,67.`},{37.`,0,171.4`,53.4`,36.5`,27.5`,93.1`,85.3`,69.5`},{27.`,0,157.5`,54.5`,32.9`,26.8`,94.9`,84.2`,66.4`},{27.`,0,165.1`,53.6`,36.9`,28.5`,100.`,83.7`,67.6`},{20.`,0,160.`,60.`,35.8`,29.4`,98.6`,86.5`,66.6`},{19.`,0,174.`,73.6`,39.4`,28.3`,107.2`,98.2`,69.7`},{32.`,0,162.6`,61.4`,36.5`,28.3`,98.3`,88.`,72.`},{26.`,0,174.`,55.5`,35.8`,27.3`,92.4`,80.4`,64.5`},{56.`,0,162.6`,63.6`,34.4`,29.7`,93.`,86.`,72.3`},{23.`,0,161.3`,60.9`,36.5`,26.6`,99.5`,86.4`,69.1`},{19.`,0,156.2`,60.`,38.5`,25.6`,92.8`,87.6`,74.7`},{31.`,0,149.9`,46.8`,35.3`,25.4`,95.9`,80.9`,60.8`},{34.`,0,169.5`,57.3`,36.2`,28.7`,96.1`,82.1`,66.9`},{34.`,0,160.`,64.1`,34.9`,28.7`,98.5`,89.3`,68.8`},{24.`,0,175.3`,63.6`,38.7`,29.7`,103.8`,85.3`,63.7`},{22.`,0,169.5`,67.3`,37.6`,25.2`,105.`,89.`,71.2`},{34.`,0,160.`,75.5`,34.7`,29.4`,100.2`,94.1`,79.6`},{30.`,0,172.7`,68.2`,37.8`,29.7`,99.1`,90.8`,77.9`},{32.`,0,162.6`,61.4`,39.8`,27.5`,107.6`,97.`,69.6`},{40.`,0,157.5`,76.8`,36.5`,29.7`,104.`,95.4`,86.`},{29.`,0,176.5`,71.8`,38.`,30.4`,108.4`,91.8`,69.9`},{21.`,0,164.4`,55.5`,35.3`,28.7`,99.3`,87.3`,63.5`},{33.`,0,160.7`,48.6`,34.7`,24.9`,91.9`,78.1`,57.9`},{33.`,0,174.`,66.4`,38.5`,29.`,107.1`,90.9`,72.2`},{38.`,0,163.8`,67.3`,35.6`,29.`,100.5`,97.1`,80.4`}};

menHSC=Table[{m[[3]],m[[5]],m[[8]]},{m,menbodstat}] ;
womenHSC=Table[{m[[3]],m[[5]],m[[8]]},{m,womenbodstat}] ;
{μmHSC=Mean @ menHSC
,ΣmHSC=Covariance @ menHSC
,ΣinvmHSC=Inverse[ΣmHSC]
}
{μwHSC=Mean @ womenHSC
,ΣwHSC=Covariance @ womenHSC
,ΣinvwHSC=Inverse[ΣwHSC]
}

pointplot3D=ListPointPlot3D[{menHSC,womenHSC},PlotStyle->{{PointSize[0.01]
,Hue[0.5,1,1,1]},{PointSize[0.01],Hue[0.15,1,1]}}
,AxesStyle->White, BoxStyle->GrayLevel[0.6]
, BoxRatios->{1, 1, 1},Background->Black]
normdist2σplot=Graphics3D[{Hue[0.9,1,1,0.4],Ellipsoid[μwHSC,4ΣwHSC]
,Hue[0.35,1,1,0.4],Ellipsoid[μmHSC,4ΣmHSC]
}, BoxRatios->{1,1, 1}]
meanlineplot=Graphics3D[{Hue[0.06,1,1,1],Tube[{{μmHSC,μwHSC}},0.5]}];
discriminantsurface=ContourPlot3D[({x,y,z}-μmHSC) . ΣinvmHSC . ({x,y,z}-μmHSC) +Log[(((2 π))^3) Det[ΣmHSC]]
== ({x,y,z}-μwHSC) . ΣinvwHSC . ({x,y,z}-μwHSC) +Log[(((2 π))^3) Det[ΣwHSC]]
,{x,μmHSC[[1]]-3(Sqrt[ΣmHSC[[1,1]]]),μwHSC[[1]]+3(Sqrt[ΣwHSC[[1,1]]])}
,{y,μmHSC[[2]]-3(Sqrt[ΣmHSC[[2,2]]]),μwHSC[[2]]+3(Sqrt[ΣwHSC[[2,2]]])}
,{z,μmHSC[[3]]-3(Sqrt[ΣmHSC[[3,3]]]),μwHSC[[3]]+3(Sqrt[ΣwHSC[[3,3]]])}
]

Show[pointplot3D,normdist2σplot,meanlineplot,discriminantsurface]

There may be a thing new here that you haven’t learned before: ContourPlot3D and ContourPlot. Both are designed to plot a contour given by an equation or condition. See this example, the contour of function
                                          f[x,y]=((((x/r)))^2)+((((y/r)))^2)
for                                 f[x,y]=positive constant
is the set of {x,y} satisfying that equation, which we know, is a circle:

ContourPlot[((((x/2)))^2)+((((y/2)))^2)==1,{x,-3,3},{y,-3,3}]

For a variance ellipsoid:

ContourPlot[((((x/3)))^2)+((((y/1.5)))^2)==1,{x,-3,3},{y,-3,3}]

And for 3D, ContourPlot3D gives a surface, and in the above, we use it to plot the estimated variance ellipsoid of the data.

ContourPlot3D[((((x/3)))^2)+((((y/1.5)))^2)+((((z/1)))^2)==1,{x,-3,3},{y,-3,3},{z,-3,3}]

We can calculate the point along the axis of the two mean points, where the two PDF are equal:

{sp,pj}={s,(s (μmHSC-μwHSC)) . ΣinvmHSC . (s (μmHSC-μwHSC)) +Log[(((2 π))^3) Det[ΣmHSC]]} /. FindRoot[(s (μmHSC-μwHSC)) . ΣinvmHSC . (s (μmHSC-μwHSC)) +Log[(((2 π))^3) Det[ΣmHSC]]
==(s (μmHSC-μwHSC)). ΣinvwHSC .(s (μmHSC-μwHSC)) +Log[(((2 π))^3) Det[ΣwHSC]]
,{s,0.5}]

{pj,Exp[-0.5 pj]}

equiprobcontour=ContourPlot3D[{({x,y,z}-μwHSC) . ΣinvwHSC . ({x,y,z}-μwHSC) +Log[(((2 π))^3) Det[ΣwHSC]]==pj
,({x,y,z}-μmHSC) . ΣinvmHSC . ({x,y,z}-μmHSC) +Log[(((2 π))^3) Det[ΣmHSC]]==pj} 
,{x,μwHSC[[1]]-2.5(Sqrt[ΣwHSC[[1,1]]]),μmHSC[[1]]+2.5(Sqrt[ΣmHSC[[1,1]]])}
,{y,μwHSC[[2]]-2.5(Sqrt[ΣwHSC[[2,2]]]),μmHSC[[2]]+2.5(Sqrt[ΣmHSC[[2,2]]])}
,{z,μwHSC[[3]]-2.5(Sqrt[ΣwHSC[[3,3]]]),μmHSC[[3]]+2.5(Sqrt[ΣmHSC[[3,3]]])}
,ContourStyle->{{Opacity[0.6],Hue[0.9,1,1,0.4]}
,{Opacity[0.6],Hue[0.35,1,1,0.4]}}, Mesh->None]

Show[pointplot3D,equiprobcontour,meanlineplot,discriminantsurface]

This shows show to discriminate the two clusters. The yellow surface is the Bayes’ decision, it is 50-50% on it and a point belongs to the green cluster if on one side and pink cluster on the other. This is what we will study next.

5. Conditional probability and Bayes’ rule

5.1 Conditional probability

The concept of conditional probability was discussed above for the case of joint distribution men height and shoulder width. For the below, we can make statement such as:
    If a man’s height is between 175-180 cm, then the probability for shoulder width is slice #4:
                       p[shoulder|h∈[175-180] ]=... (slice # 4)

Another example: If we want ace of ♠,
               p[ace of ♠] = 1/52

We take a sneak peak and saw this: A
the question now is:  what is the probability that it is A♠, given that we have A? This is how we write it:
                      p[A♠ if A] or p[A♠ | A]

Intuitively, we know our chance is now much better than 1/52:
                  p[A♠ |A]=((p[A⋂♠])/(p[A]))

which is 1/2. Likewise, suppose we take a sneak peak and find ♠. There are only 13 cards of spade and one of them is ace, hence: 
               p[A♠ |♠]=((p[A⋂♠])/(p[♠]))

Now we can formally define conditional probability:
                  p[A|B]=((p[A⋂B])/(p[B]))

Another example: suppose we draw 2 cards, one of it is an ace, what is the probability of having a blackjack? Surely, we must feel better than not knowing what that card is.
Let A: probability of BJ; B: one of the two cards is an ace.
p[A|B]=probability of the other card is a 10: (16/51)
Use the formula: p[A|B]=((p[A⋂B])/(p[B])).
p[A⋂B]=p[A]: this is because A is a subset of B
p[A⋂B]=p[A]=((4×16)/(26×51)). 
p[B]=((4×51)/(26×51))
Thus: p[A|B]=((p[A⋂B])/(p[B]))=((p[A])/(p[B]))=((4×16)/(26×51)) ((26×51)/(4×51))= (16/51), which agrees as above.

5.2 Bayes' rule (theorem) and Bayes’ inference

5.2.1 Bayes’ rule

Since: p[A|B]=((p[A⋂B])/(p[B] )) and p[B|A]=((p[B⋂A])/(p[A]))=((p[A⋂B])/(p[A])), we have:
                  p[A|B]p[B]=p[B|A]p[A]  or:
                        p[B|A]=((p[A|B]p[B])/(p[A]))

We will see that the application of Bayes' theorem to do inference is not without ambiguity. It's not just a formula that we can use blindly because there are implicit assumptions that we may overlook. Hence, we should take a step back and think what it means to do inference.

5.2.2 Bayes’ inference

Everyone likes making decision when we have absolute certainty on the information. We face challenge only when the information is ambiguous. We don't have a problem telling the sound from a cat or a dog. A "meow" is pretty distinctive from a "ruff". But there are two dogs, and we are not that familiar with them, whose bark is that?

Bayes’ inference, or Bayesian theory of decision making deals with this type of uncertainty based on Baye’s rule above. In fact, this can be consider as the root of modern day classification algorithms, aka machine learning, machine intelligence. Why do we call “machine intelligence”? Because we think of ourselves as “intelligent” (! :) !!!) and call an algorithm intelligent when it can imitate our hard-wired algorithm in our nervous system that does Bayesian-like inference. If an event, e. g. X has consequence c. When we see “c”, we infer that there may be “X”.

If the pavement and road are wet everywhere, there must have been a rain. This is an inference. Bayesian inference is a quantitative rule to ensure that our inference is quantitatively most rational.

Let’s use this example of US men and women heigth distribution.

This is what you should see from the app.

Suppose a witness sees a person leaving a building. Supposed that the lighting is poor and the sighting is so fleeting that the witness cannot tell if it were a man or a woman. However, the person height is known since he/she was seen to pass under some obstacle of known clearance, such as 63”. We would infer that the person is a woman because after doing the integration, we will find that it is more likely than the probability for a man.

But now someone told us that it was an all-male gathering in that building, would we still make that inference? (assuming that the person has to be one of the people at the gathering). What would be a better inference? A man. With 100% certainty.

Why is it? What changes here? Supposed we know that 90% of attendees were men, only 10% were women, what would be the best guess now? It’s getting difficult isn’t it? A lot of ambiguity. What if the fraction of men is 80% or what if 99%, or 70%, should there be a formula what would be a best guess in each case? Yes, using Bayes’ rule.

Mathematically this is what we need: the probability for a person from that building to be a man or woman AND having height x. The key word here is AND. 
1. Let the probability for the person to be a man is p[man], based on the man attendence rate.
Probability for a the person to be a woman is p[woman]=1-p[man].
The prob of a person height =x if we know that the person is man is:
                    p[x|man]=(1/((Subscript[σ, m])(Sqrt[2 π])))(e^(-(((x-m))^2)/2 ((Subscript[σ, m])^2)))    
Likewise for women:   p[x|woman]=(1/((Subscript[σ, w])(Sqrt[2 π])))(e^(-(((x-w))^2)/2 ((Subscript[σ, w])^2)))   
The probability for a person from that building to be a man AND having height x is:
                                                            p[x,man]=p[x|man] p[man]    
The probability for a person from that building to be a woman AND having height x is: 
                                              p[x,woman]=p[x|woman] p[woman] 
The probability for any person from that building to have a height of  x is:
                               p[x]=p[x|man] p[man]+p[x|woman] p[woman]
Now we can make an inference: the prob of a person to be a man, given that we know having a height x is:
                                     p[man|x]=p[x|man] ((p[man])/(p[x])) 
by Bayes' rule. This is the essence of Bayesian inference. The key terms here are p[man] which is prior knowledge of the gathering, and p[x] which is the distribution of the feature we are interested for that sample population.
Similarly for woman:    p[woman|x]=p[x|woman] ((p[woman])/(p[x]))

5.3 Additional examples/exercise

5.3.1 Communication bit-0 and bit-1

5.3.2 Card game

Exercise

Consider the following problem:
Suppose we play a game of in which you will draw 5 cards. The hand is said to be RED or BLACK if a majority of the cards is red or black. You are supposed to bet RED or BLACK. What is the probability for you to have a RED or BLACK hand?
By symmetry of the number of red and black cards, the odd should be 50-50, right?

Supposed you can buy the chance to flip one card open and then bet, for example, you flip one card and find it red. What is the probability for you to have a red hand? Is it still 50%, or better? What would you bet?

The point here is that something changes: it is still the same hand before; but the fact that you know that one card seems to improve your betting chance. Why does the knowledge of one card suddenly change your chance? would you increase your bet? Calculate the probability of winning if you know one card.

Answer

Let B be the event of having a red hand, A: event of one card flipped up is red.

We want to know: p[B|A]. We can use Bayes’ theorem:
                                                     p[B|A]=((p[A|B]p[B])/(p[A]))
We need to know p[A|B], which is the probability of one card flipped open is red given that it is a red hand. If it is a red hand, the number of red cards is either 3, 4, or 5. The probability of open one card red is (3/5), (4/5), or 1.
Consider “naive Bayes approach”: (not accurate, but useful approximation). Suppose that each possibility above has equal probability, that is 1/3, then the chance for the card flipped to be red, knowing that you have a red hand is: (1/3)((3/5)+(4/5)+1)=(4/5) 
Or                               p[A|B]=(4/5)

What is p[B]? Probability to have a red hand= (1/2), hence p[B]=(1/2). What is p[A]? It is the probability to flip up one card red regardless of hand? this is a problem because we don’t really know:
- If all 5 are red, it is 1; 
- If all 4 are reds, it is (4/5); and so on, ... 
Again, we use naive Bayes approach. Suppose that all 6 possibilities (0,1,2,3,4,5) have equal probability, then                                              
                        p[A]=(1/6)((((∑_(m=0)^5)m)/5))=((5×3)/(6×5))=(1/2)

Now, we can put all together:
                            p[B|A]=((p[A|B]p[B])/(p[A]))=(4/5)=0.8
Thus by flipping one card, your chance improves from 0.5 to 0.8: this is a tremendous odd in betting, except that it is not accurate, because the naive Bayes assumption is only a rough guess. We don’t know what are in the card deck: it can be 200 cards, 500 cards with unknown portions of red or black card.

For a 52-card deck, the various terms can be calculated exactly.

Let p[3,4, or 5 cards red], then the probability n red cards for M-card hand is:
                     pcard[n,M]=(({{26}, {n}}))(({{26}, {M-n}}))/(({{52}, {M}}))

pCard[n_,M_]:=Binomial[26,n]Binomial[26,M-n]/Binomial[52,M];
pRednList=Table[pCard[n,5],{n,3,5}]  (* prob for 3, 4, and 5 red card *)
pAifBList=Table[n/5,{n,3,5}]  (* p[A|B]: 
                            prob 1 card red if the hand has 3, 4, 5 red *)
pAifB=pAifBList . pRednList  (* sum p[A|B]*p[A] *)
{pBifA=(pAifB/(Total[pRednList])),N[pBifA]}

Hence, for a 52-deck, the chance improves from 0.5 to 0.68

code for Monte Carlo sim

Manipulate[
If[TrueQ[deal],hand=Table[carddeal[ncard],{m,nhand}];
ngame=ngame+nhand;
outRB=Table[If[Length[Select[u,#≤ 26 &]]≥ 3,1,0],{u,hand}];
flipcard=Table[If[u[[1]]≤ 26,1,0],{u,hand}];
corr=Select[Transpose[{flipcard,outRB}],#[[1]]==1 &];
corr2=Length @ Select[corr,#[[2]]==1 &];
corrcumul=corrcumul+{corr2,Length[corr]};
rh={Total[outRB],Length[outRB]};rhcumul=rhcumul+rh;
corr={};
outRBdisp=Table[If[u==1,Item[Style["RED",18,Bold,White],Background->Red]
,Item[Style["BLACK",18,Bold,White],Background->Black]],{u,outRB}];
handdisp=Table[cardface /@ Sort[u],{u,hand}];
AppendTo[rhpList,{ngame,If[TrueQ[rhcumul[[2]]>0]
,1.*rhcumul[[1]]/rhcumul[[2]],0.5]}];

AppendTo[rhifRlist,{ngame,If[TrueQ[corrcumul[[2]]>0]
,1.*corrcumul[[1]]/corrcumul[[2]],0.68]}];

deal=False,];
Grid[{{Column[{Grid[{{Grid[{{,"# red","# games","win ratio"}
,Join[{"cumul"},rhcumul,If[TrueQ[rhcumul[[2]]>0]
,{1.*rhcumul[[1]]/rhcumul[[2]]},{0.5}]]
,Join[{"recent"},rh,{1.* rh[[1]]/rh[[2]]}]}
,BaseStyle->{18,FontFamily->"Calibri"}, Frame-> All]}
,{Grid[{{"# flip red","# red","ratio"}
,Join[corrcumul,If[TrueQ[corrcumul[[2]]>0]
,{1.*corrcumul[[1]]/corrcumul[[2]]},{}]]}
,BaseStyle->{18,FontFamily->"Calibri"},Frame->All]}}
,Alignment->Top]
,Grid[MapThread[Append,{handdisp,outRBdisp}],Background->GrayLevel[0.9],Frame-> All]
}],ListLinePlot[rhifRlist,ImageSize->200]}},Alignment->Top]

,Grid[{{Control[{{ncard,5},1,10,1, ImageSize->80 }],Button["deal new round",deal=True]}
,{Control[{{nhand,10,"# games per round"},{10,20,50,100}}],}}]
,Initialization:>{SeedRandom[];
rhcumul={0,0};corrcumul={0,0};
rhpList={};rhifRlist={};ngame=0;
deal=True;
carddeal[n_]:=Block[{deck,u}
,deck=Range[52];
Reap[Do[u=RandomChoice[deck];
deck=Complement[deck,{u}];
Sow[u]
,{i,n}]][[2,1]]
];
cardface[n_]:=Block[{f,s}
,s={♡,♢,♠,♣}[[Floor[(n-1)/13]+1]];
f=Mod[n-1,13]+1;
Style[Row[{If[f==1,"A",If[f==11,"J",If[f==12,"Q",If[f==13,"K",f]]]],s}]
,Bold,24,FontFamily->"Arial",Hue[0,1,1-Floor[(n-1)/26]]]
]
}]

Exercise

Let’s say we play with a 52-card deck. The game rule is that one can buy a chance to flip a card with $X (e. g. $100), and after that, one can bet any amount from $0 up to $ q X (e. g. if q=2, q X=$200). If one wins, one gets $ ρ *bet (e. g.  ρ=0.8, the house takes a 20% cut), and if one loses, one loses all of course. Calculate the odd for your strategy. (This is the introduction to the concept of calculation of investment return and market strategy).

Your answer

See supplementary file of Lesson set 6 for answer.

5.3.3 Fair coin

Let’s say we play coin flip games. A fair coin is defined to be 50-50% chance for head and tail. But how do we know if the coin is fair? We do an experiment, flipping it, say 10 times, and get 6 heads, 4 tails. Can we conclude that it’s fair? Or that the probability for head, (Subscript[p, Head])=0.6 and that it is not a fair coin?

Clearly, this is not for a cut-and-dry answer. The correct formulation for the answer is that “given the results (6 H, 4 T), the probability for (Subscript[p, Head]) is...” In other words, we can only answer with a probability:
                            p[(Subscript[p, Head])==r | given {n heads,M-ntails}],

Exercise - fair coin analysis

Analyze the problem and calculate   p[(Subscript[p, Head])==r | given {n heads,M-ntails}]

Answer

To calculate 
             p[(Subscript[p, Head])==r | given {n heads,M-ntails}],
we use Bayes’ theorem:
     p[(Subscript[p, Head])==r |{n heads,M-ntails}]=((p[{n,M-n}|(Subscript[p, Head])==r] * p[(Subscript[p, Head])==r] )/(p[{n,M-n}]))

First, we have this result, which is just based on binomial distribution we learn before:
      p[{n,M-n}|(Subscript[p, Head])=r]=(r^n) (((1-r))^(M-n)) (({{M}, {n}}))  
We need: p[(Subscript[p, Head])=r]  and p[{n,M-n}].
Here, it is clear that the problem with using Bayes' theorem is that we don't really have any information about p[(Subscript[p, Head])=r]  and p[{n,M-n}] without additional assumptions.

First, exactly what p[(Subscript[p, Head])=r] means? it means that if we take a coin from a general coin population, which can include all the fair and unfair coins in the world, and test each coin infinite number of times with fair tosses to obtain (Subscript[p, Head]) of each, plot on a PDF histogram and let the population -> ∞, then the histogram PDF will asympotically approaches (Subscript[p, Head]) distribution.

This is the prior probability knowledge that makes Bayes’ theorem ambiguous. In this case, we will just assume that there is no known property of the coin and that the coin bias can range uniformly from 0 (never head, always tail) to 1 (always head, never tail) as illustrated below:

Plot[UnitBox[x-0.5],{x,0,1}, PlotRange->{{-0.25,1.25},All}
,PlotStyle->{Thickness[0.005],Red}
,Filling-> {1-> {0,Hue[0.,1,1,0.5]}}
,AxesLabel->{"(Subscript[p, HEAD])","PDF ((Subscript[p, HEAD]))"}
, ImageSize->350
,AspectRatio->0.5]

And for p[{n,M-n}]
           p[{n,M-n}]=(({{M}, {n}})) (∫_0^1)(r^n) (((1-r))^(M-n)) dr

(∫_0^1)(r^n) (((1-r))^(M-n)) \[DifferentialD]r

Hence:
    p[(Subscript[p, Head])==r |{n,M-n}]=((p[{n,M-n}|(Subscript[p, Head])==r] * p[(Subscript[p, Head])==r] )/(p[{n,M-n}]))
                                           =((Gamma[M+2])/((Gamma[n+1]) (Gamma[M-n+1]))) (r^n) (((1-r))^(M-n))

code

Manipulate[
nx=Min[M,Floor[nρ*M+0.5]];
pNorm=((Gamma[2+M])/(Gamma[1.+M-nx] Gamma[1+nx]));
pn=Quiet[ (((((0.5 M )/nx)))^nx) (((((0.5 M)/(M-nx))))^(M-nx))];
Column[{Grid[{{"tosses=",M,"# Head=",nx}
,{"fairness","((prob[pHead = 0.5])/(prob[pHead = n/M])) =",pn}}
,BaseStyle->{18,Black,FontFamily->"Calibri"}]
,Plot[Quiet[pNorm (r^nx) (((1.-r))^(M-nx)) ],{r,0.,1}
,PlotRange-> {{0.,1},All}
,PlotStyle->{Thickness[0.005],Hue[0.65,1,1]}
,Filling-> {1-> {0,Hue[0.5,1,1,0.5]}}
,Frame->True,GridLines->Automatic
,FrameLabel->(Style[#,18,Black,FontFamily->"Calibri"] &/@{"(Subscript[p, Head])","PDF[(Subscript[p, Head])|"<>"{"<>ToString[M]<>","<>ToString[nx]<>"}]"})
,ImageSize->375]
}]
,{{nρ,0.5,"fraction of Head"},0,1},{{M,10,"# tosses"},{10,20,50,100,200,500,1000},ControlType->SetterBar}]

Discussion

Consider 10 tosses, 5 H, 5T. Is it good enough to declare the coin fair?

The plot above shows us what the chance is for real (Subscript[p, Head]) to be any value from 0-1, knowing that we get (5H,5T) result. We see that the distribution is quite broad. It means that getting 5-5 is not very convincing to say that the coin is really fair.
Let's do it for 100 times. If we get 50-50, what is the chance to have a fair coin now?

Now it looks a bit more convincing. But is it good enough to tell the difference between 0.48 and 0.51? Still not enough. Try it for 1000.

Are we anymore confident to tell 0.501 vs 0.5? Not quite isn't it? This simply shows the nature of statistical deviation. What this mean is that it is not at all easy to measure some small effects without large number of samples.
This is where we get the feeling of "too good to be true". If an experiment comes out too great a result, we don't feel comfortable if the expected statistical fluctuation is not there. Later on, we will see that's where chi-square test and a whole field of searching for outliers come in. It is "statistics" about statistics.

Consider 100 tosses and get 70 heads, 30 tails, can we say anything?

We can say that the ratio of the chance for it to be a fair coin (50-50) vs. a bias coin (70-30) is 0.00027. More precisely, if we get 70 H and 30 T, we can say this:

M=100; nx=70;
pNorm=((Gamma[2+M])/(Gamma[1.+M-nx] Gamma[1+nx])) ;
pNorm*NIntegrate[(r^nx) (((1.-r))^(M-nx)),{r,0.5,1}]

The probability for the coin to be bias toward head is 99.997%.

6. A numerical exercise on Bayes’ decision with cost

In the following, we will use examples similar to the one below we are already familiar with to review probability

6.1 Demonstration with a game

As mentioned, while we humans can beat spam bots easily with the highly complex calculation task of visual pattern recognition, we aren’t as good as the computer when it comes to even a simplistic numerical calculation.

We can demo with a simple game as shown below:

Take a random adult individual in the US. You are told of his/her height. We can bet that person a man or a woman. If we bet $100 and win, we get $50 pay off. If we lose, we lose the whole $100. Unfair? All casinos must have this “house advantage” to make a living. As usual, there is a cap, a limit how high you can bet. Say $100 max. You don’t have to bet, you can pass if you don’t like the odd. Is that a good game? assuming that the individual is totally random. Do you want to play?

Once you start, you will find out how good you are at probability inference and you would make a fortune until the house escorts you off the premise.

Why? because the odd is very good that you win. But it is meaningless just to win without any benchmark. Beating or at least equal to the computer is the proof-in-pudding of understanding of probability. Let’s start and see what you get. Please follow instructions and do all asked, this is not just a game but it is used to illustrate key points of the lessons.

You can run this game as an independent app - external to the lecture. It is available in the associated App folders along with your lectures. Mathematica is less prone to crash. You can also just copy, cut and paste onto a new notebook. Close or minimize this notebook window while running the app.

Exercise - play game - learn probability inference and loss function

Play against the computer. Here is the info you need to compete against it (no, the computer doesn’t cheat): If you don’t quite understand what the chart below indicates, we have a supplementary topical lecture on normal distribution that you can learn.

Play at least 10 rounds and preferrably more against the computer and record, observe whether you win or lose against the computer. Make an analysis of your performance, study how the computer bets, and derive your strategy. you can click this  to see your gamestats vs. computer.
If you can be as good as the computer, then, you understand probability and know normal (Gaussian) distribution well. Explain the theory behind your strategy - which is the optimal approach that the computer uses. If not, it’s OK to continue and we’ll discuss about taking the supplementary topical lecture on normal distribution and probability (go to Course Note page, look inder Supplementary topical lessons).

Be complete in reporting your performance and analyze against computer performance.

Your answer

End exercise of gender height guessing - part 1

Break note: After 6.1, before continuing with 6.2 below, if you need a refresher on Normal distribution and continuous-variable probability, please go either to the supplementary topical lecture or through Section Review Normal distribution below - including doing all exercises (successfully doing the exercises is the only way to confirm the required understanding) - then come back to section 6.2 after you feel confident (with high probability) that you know enough to go on. Otherwise, you might find difficulties in the sections below.

6.2 Probability inference and Bayes’ decision

6.2.1 Basic consideration and exercise

What did you learn from the exercise of playing the game above. How do you classify a person as a man or a woman based on his/her height? How do you think the computer does that? To explore, use the App below

You can run the app below as an independent entity - external to the lecture. It is available in the associated App folders along with your lectures. Mathematica is less prone to crash. You can also just copy, cut and paste onto a new notebook. Close or minimize this notebook window while running the app.

Exercise - basic calculation for Bayes’ decision

Use App Gender height Bayes’ decision above to answer the follow questions:

1- What kind of distribution is your best guess for US men’s and women’s height?
2- What are the mean and variance of each gender distribution based on your visual inspection of the curves. The objective of this question is for you to exercise your visual understanding of normal distribution by guessing approximately the mean and variance directly from the plot. It is not intended for you to be perfectly correct and do not try to spend time to calculate, Internet search, or do anything else. Click “show parm” to check your guesses. Roughly, to within how many % are you correct?
3- Use the app, what is the percentage of women population with height between 57 and 62 in.? what is that value for men?
you can vary the height cursor to the center of 57 and 62, then set the range to 5 inches.
4- What is the percentage of men population with height between 71 and 75 in.? what is the value for women?
5- Apply what you learn about normal distribution, show your calculation by doing integration as shown below to verify the values you obtain from the App. in both Q.3 and Q. 4 above.
                            probability for: a≤x≤ b=    (∫_a^b)(Subscript[f, pdf])[x;μ, σ]dx   
 for normal distribution, the formula is:    
                  probability for: a≤x≤ b=(1/(σ(Sqrt[2 π])))(∫_a^b)(e^(-((((x-μ))^2)/(2(σ^2)))))dx =(1/2) (Erf[((b-μ)/(σ(Sqrt[2])))]-Erf[((a-μ)/(σ(Sqrt[2])))])
In Mathematica, erf is Erf.
6- Given a person’s height of 62±0.25 in., how many percent of men with that height and how many percent are women in the general population?
7- Within the narrow selected population of both men and women of that height only, 62±0.25 in., how many percent are men and how many are women (within that population only)? (click on show Bayes’ decision to compare your answer). What is your formula?
8- Do the same as 7 for a person of height 68±0.25 in.
9- Vary the person height in any way you wish, move back and forth, observe the Bayes’ decision (also called Bayesian decision), what is the criterion to decide the person of the given height man or woman?

hidden answer

1- It is evident that both distributions are normal distribution.

2- Using the cursor, the mean for woman is ~ 63.6, SD σ ~ 3”. For men, μ ~ 69.5”, SD σ ~ 3”
The actual values are:
- For women:  μ= 63.6”, the estimate is exact. The SD σ = 2.8”. The estimate is off ~ 0.2/2.8 ~ 7%. 
- For men:  μ= 69.2”, the estimate is off by 0.3”, hence: 0.3/70 ~ 4%. The SD σ =3”. The estimate is exact. 

3- From the app: the % of women between 57 - 62” is 27.02% and for men: 0.82%

4- From the app: the % of men between 71 - 75” is 24.8% and for women: 0.43%

5- Calculation by using Erf
For women and men between 57 - 62, this is what we do:

μMen=69.2; σMen=3.; μWomen=63.6; σWomen=2.8;
upper1=62.; lower1=57.;
pWom57to62=0.5 (Erf[((upper1-μWomen)/(σWomen (Sqrt[2.])))]-Erf[((lower1-μWomen)/(σWomen (Sqrt[2.])))])
pMen57to62=0.5 (Erf[((upper1-μMen)/(σMen (Sqrt[2.])))]-Erf[((lower1-μMen)/(σMen (Sqrt[2.])))])

For women, surprisingly, the value here: 27.46% is slightly off from Q.3 result: 27.02% the difference is small, but it may mean some error somewhere either in the app or the parameters of the app are not what it says.  
For men, the result 0.817% is in good agreement.
Do the same for Q. 4:

μMen=69.2; σMen=3.; μWomen=63.6; σWomen=2.8;
upper2=75.; lower2=71.;
pWom71to75=0.5 (Erf[((upper2-μWomen)/(σWomen (Sqrt[2.])))]-Erf[((lower2-μWomen)/(σWomen (Sqrt[2.])))])
pMen71to75=0.5 (Erf[((upper2-μMen)/(σMen (Sqrt[2.])))]-Erf[((lower2-μMen)/(σMen (Sqrt[2.])))])

Again, we have excellent agreement with men, 24.77%, while for women, the result here, 0.409% is off from the app: 0.426%. The best guess is that the parameters of women as given in the App may be rounded off with a small difference from the actual values used by the app.

6. Given a person’s height of 62±0.25 in., how many percent of men with that height and how many percent are women in the general population? 
The app shows 5.996% of women are of that height range, and 0.375% of men.

7- Within the narrow selected population of both men and women of that height only, 62±0.25 in., how many percent are men and how many are women (within that population only)? (click on show Bayes’ decision to compare your answer). What is your formula?

It is quite straight forward. Let’s say the women population of the whole US is: (Subscript[p, W]) and that of men is (Subscript[p, M]), then the population with that height is:
                                          (Subscript[ρ, W]) (Subscript[p, W]) + (Subscript[ρ, M]) (Subscript[p, M]) 
where (Subscript[ρ, W]) =5.966% and (Subscript[ρ, M])=0.375%
Then, the percentage of men and women in that population are, respectively:
                          (Subscript[q, M])=(((Subscript[ρ, M]) (Subscript[p, M]))/((Subscript[ρ, W]) (Subscript[p, W]) + (Subscript[ρ, M]) (Subscript[p, M])))   ;     (Subscript[q, W])=(((Subscript[ρ, W]) (Subscript[p, W]))/((Subscript[ρ, W]) (Subscript[p, W]) + (Subscript[ρ, M]) (Subscript[p, M])))  
If the men’s and women’s populations are equal (good approximation but not quite true), then:
                           (Subscript[q, M])=((Subscript[ρ, M])/((Subscript[ρ, W])  + (Subscript[ρ, M])))   ;     (Subscript[q, W])=(((Subscript[ρ, W]) )/((Subscript[ρ, W]) + (Subscript[ρ, M])))

(Subscript[ρ, M])=0.00375 ; (Subscript[ρ, W])=0.05966 ;
(Subscript[q, M])=((Subscript[ρ, M])/((Subscript[ρ, W])  + (Subscript[ρ, M]))) 
 (Subscript[q, W])=(((Subscript[ρ, W]) )/((Subscript[ρ, W]) + (Subscript[ρ, M])))

Or, 94.1% are women, and 5.9% are men. These values are in good agreement with the Bayes’ decision calculation, showing that Bayes’ calculation implicitly assumes equal women and men population.

8- Do the same as 7 for a person of height 68±0.25 in.

For a person of height 68±0.25 in.:

use the same formula and the same assumption of equal populations:

(Subscript[ρ, M])=0.06132 ; (Subscript[ρ, W])=0.02123 ;
(Subscript[q, M])=((Subscript[ρ, M])/((Subscript[ρ, W])  + (Subscript[ρ, M]))) 
 (Subscript[q, W])=(((Subscript[ρ, W]) )/((Subscript[ρ, W]) + (Subscript[ρ, M])))

These proportions of men and women, 74.3% and 25.7% are in good agreement with the Bayes’ decision.

10- Vary the person height in any way you wish, move back and forth, observe the Bayes’ decision (also called Bayesian decision), what is the criterion to decide the person of given height man or woman?

It is obvious that the Bayes’ decision is simple: it decides a man or a woman based on the proportion or probability of man or woman to be >50%.

Exercise - odd and Bayes’ decision - intro to discriminate

Odd is a very common term - the odd is that you have heard the word “odd,” but exactly what is odd in betting and statistics? Odd is defined as:
                       Odd(some thing) =((probability for that thing to happen)/(probability for it NOT to happen)) = (probability/(1-probability)) 
This is different from “chance” because chance is probability. In other words:
                                       Odd(some thing) =(chance/(1-chance))    
but people are sometimes mistaken chance for odd when the chance is small, because (1-chance) ~ 1 for small chance. In this definition, you can understand the expression “the odd is 1-to-1,” which means the chance is 50-50.
In this exercise, we will examine the quantitative aspect of odd.
1- What is the odd for the person of 68” height to be a man (use the app). Without referring to the app and based on what you get for the odd of a 68” man, what is the odd for a 68” woman? (just ONE simple calculation)

2- If you plot the odd of something vs. the odd against it, which i the odd of not-that-something on a log-log scale, what do you expect? 

3- Plot the odd and log(odd) of a woman as a function of height. What is the meaning when log(odd) cross the zero point?

hidden answer

chance (woman;h)=(( (Subscript[ρ, w])(1/((Subscript[σ, w])(Sqrt[2 π])))(e^(-((((h-(Subscript[μ, w])))^2)/(2((Subscript[σ, w])^2))))))/((Subscript[ρ, w])(1/((Subscript[σ, w])(Sqrt[2 π]))) (e^(-((((h-(Subscript[μ, w])))^2)/(2((Subscript[σ, w])^2)))))+(Subscript[ρ, m])(1/((Subscript[σ, m])(Sqrt[2 π]))) (e^(-((((h-(Subscript[μ, m])))^2)/(2((Subscript[σ, m])^2)))))))

First, let’s assume  (Subscript[ρ, w])=(Subscript[ρ, m])

(Subscript[p, w])=FullSimplify[(( (Subscript[ρ, w])(1/((Subscript[σ, w])(Sqrt[2 π])))(E^(-((((h-(Subscript[μ, w])))^2)/(2((Subscript[σ, w])^2))))))/((Subscript[ρ, w])(1/((Subscript[σ, w])(Sqrt[2 π]))) (E^(-((((h-(Subscript[μ, w])))^2)/(2((Subscript[σ, w])^2)))))+(Subscript[ρ, m])(1/((Subscript[σ, m])(Sqrt[2 π]))) (E^(-((((h-(Subscript[μ, m])))^2)/(2((Subscript[σ, m])^2)))))))/. (Subscript[ρ, m])-> (Subscript[ρ, w])]

odd=((Subscript[p, w])/(1-(Subscript[p, w]))) // FullSimplify

Lodd=(1/2) (((((h-(Subscript[μ, m])))^2)/(Subscript[σ, m]^2))-((((h-(Subscript[μ, w])))^2)/(Subscript[σ, w]^2)))+Log[((Subscript[σ, m])/(Subscript[σ, w]))]

μMen=69.2; σMen=3.; μWomen=63.6; σWomen=2.8;

Plot[(((E^((1/2) (((((h-μMen))^2)/((σMen)^2))-((((h-μWomen))^2)/((σWomen)^2))))) σMen)/(σWomen)),{h,55,85}, PlotRange-> All]

μMen=69.2; σMen=3.; μWomen=63.6; σWomen=2.8;

Plot[(1/2) (((((h-μMen))^2)/((σMen)^2))-((((h-μWomen))^2)/((σWomen)^2)))+Log[((σMen)/( σWomen))],{h,55,80}, PlotRange-> All
,PlotStyle-> {Thickness[0.005],Black}
,Frame-> True, GridLines->Automatic
,FrameStyle-> Black, GridLinesStyle->GrayLevel[0.6]
,Filling-> {1-> {0,{Hue[0.,1,1,0.7],Hue[0.35,1,1,0.7]}}}]

End exercise on basic calculation for Bayes’ decision

6.2.2 Concept of discriminant function

The computer player sets up a threshold, called “discriminant” boundary shown as green line below. One can choose anywhere to set the discriminant line. Then, one can classify any one to the right of that line as man and the left, woman.

As you can see, it doesn’t matter where the discriminant line is, there are always errors: a fraction of women in the red integral will be misclassified as men for being taller than the discriminant height. Likewise, a fraction of men of the blue integral will be misclassified as women for being shorter than the discriminant height. 

Move the line to the right, you will make less error on calling “woman” (smaller red integral), but more on “men” (larger blue integral), and vice versa if you move to the left. There is a location for discriminant line that gives a minimum for the sum of both men and women errors, shown as the white dashed line.

Below are plots of the error as a function of the discriminant value.

Exercise - calculation of errors

Write your own code to reproduce the plots of error above. You don’t need to reproduce the style, cursors, markers, etc. Only:
- the curve of misclassified women error (orange above)
- the curve of misclassified women error (blue above)
- the total of both (yellow above)
as a function of the discriminant line location.

Reminder, use Mathematica function Erf or Erfc.

To calculate the error integral, remember this formula:
                  probability for: a≤x≤ b=(1/(σ(Sqrt[2 π])))(∫_a^b)(e^(-((((x-μ))^2)/(2(σ^2)))))dx =(1/2) (Erf[((b-μ)/(σ(Sqrt[2])))]-Erf[((a-μ)/(σ(Sqrt[2])))])
                  For     b-> ∞                    a≤x =  (∫_a^∞)(e^(-((((x-μ))^2)/(2(σ^2)))))dx =(1/2) (1-Erf[((a-μ)/(σ(Sqrt[2])))]) =(1/2)Erfc[((a-μ)/(σ(Sqrt[2])))] 
                  For a -> -∞       ∞≤x≤ b=(1/(σ(Sqrt[2 π])))(∫_∞^b)(e^(-((((x-μ))^2)/(2(σ^2)))))dx =(1/2) (Erf[((b-μ)/(σ(Sqrt[2])))]+1)

Plot[{0.5(1+Erf[x]),0.5 Erfc[x]},{x,-4,4.}]

LogPlot[{0.5(1+Erf[x]),0.5 Erfc[x]},{x,-4,4.},PlotRange-> {0.01,1}]

your answer

Exercise - prove that the minimum total error occurs at the pdf intercept

given answer

The total error is the sum of two things (u is the position of discriminant line):
           category 1 misclassified as cat. 2:  error rate for: u≤x≤ ∞=(∫_u^∞)(Subscript[pdf, 1])[x]dx 
           cat. 2 misclassified as cat. 1:          error rate for: -∞≤x≤ u=(∫_(-∞)^u)(Subscript[pdf, 2])[x]dx 
Total:                              Error[u]=(∫_u^∞)(Subscript[pdf, 1])[x]dx  + (∫_(-∞)^u)(Subscript[pdf, 2])[x]dx 
The minimum is where                    ((d )/(du))Error[u] = 0
Or:                        ((d )/(du))Error[u] =((d )/(du)) ((∫_u^∞)(Subscript[pdf, 1])[x]dx )+((d )/(du)) ((∫_(-∞)^u)(Subscript[pdf, 2])[x]dx  ) =0 
which is:               ((d )/(du))Error[u] =           - (Subscript[pdf, 1])[u]           +       (Subscript[pdf, 2])[u]                     =0 
Hence, the minimum error occurs at:
                                                             (Subscript[pdf, 1])[u]    =  (Subscript[pdf, 2])[u]      
or where the two curves intercept. QED.

Exercise - calculation of errors in other applications

6.3 Concept of prior distribution and probability

Suppose the game you play above changes a little. Let’s say the person’s height is 68”. The app says:

The odd is almost 3:1 for a man.

But now, instead of a random person of the general US population, that person comes from women’s apparel stores. Do you keep the same guessing strategy, that it is a man, or do you change? Vice versa, consider one more example. Let’s say, a person’s height is 64”.

It appears that the odd is 83-17, or almost 5:1 that it is a woman.

But that random person is from a sport event with 90% being men. Is the odd still 5:1 woman? Let’s put it this way. If we know that sport event is attended by 90% men and we take just a random person, what is the odd of that person a man? it is a 9:1 odd. But now we know that person height. It is 64” should the odd suddenly becomes 5:1 the person is a woman? That doesn’t make any sense!
Or, let’s go to the extreme and say, you have to guess the gender of a person from group that is known to be 100% women or men, is the Bayes’ decision calculation in the App valid? How do we adjust for this?

Let’s step back and consider a simple calculation. Let say sample population of women’s apparel stores customers have 9000 women and 1000 men. Let’s say the person’s height is 68”.

as shown in the left plot, just among men, there is 6.132% of that height. Multiply by 1000, we have:

(6.132/100) * 1000

How many women? do the same thing:

(2.123/100) * 9000

We have 191 women to 61 men of that height from the population who go to women’s apparel stores. Now the probability for a man is only:

((61.32`)/(61.32`+191.07000000000002`))

In other words, the odd is 3 to 1 now that it is a woman. This chart:

makes this point. See this:

(1.226/(1.226+3.822))

The slight discrepancy is due to roundoff.

The women population outweights that of men by 9:1 ratio, hence, instead of 3:1 for men if both populations are equal, it flips all around. This is known as prior probability. 
({{"women height parameters"}, {prior pop factionprior pop faction}}) 
This slider: prior population fraction allows you to control that. It is initially set at 0.5, which means equal # or women and men. But if the game is changed so that the random person come from a different population ratio, the relative distribution curves are weighed by that factor.  The Bayes’ decision rule is still based on the same principle that if:
                                 P[either man or woman] >0.5, it decides as either man or woman accordingly.
But the number now changes compared with 50%-50% population assumption. In this case, you have to bet woman to have a chance to win.

Exercise - Bayes’ decision with prior probability on population

You will do a study on how the discriminant boundary (the position of the line that helps make decision on either man or woman) vay as a function of prior probability on population. If you are theoretical in math you can actually derive and plot. Otherwise, you can do this:
- vary the woman population from 0.1 - 0.9
- observed the location of discriminant boundary.
- plot the latter as a function of the former
observe and make your comment, discussion.

your answer

End exercise

6.4 Concept of cost and payoff

Finally, we get to things that matter: cost and payoff. Any statistical calculation in real life, such as financial planning, investment, insurance premium actuary calculation, payoff, etc. boils down to one thing: maximizing return, minimizing loss, lowering or hedging risk. So, we don’t just calculate probability. That’s not complete. It has to be:
         (Probability of event A) x (cost of event A) +   (Probability of event B) x (cost of B) + etc.

If cost is positive, it is a lost. If cost is negative, it is a gain. The objective is to maximize the net return.
If you notice, in the game above, the computer does NOT always put a bet. Why? because the payoff is not 50-50. This is an example what the computer thinks:

event A: chance to be a man = 60%
If I win:  I get only $50, hence the expected winning is:    60% x $50      =     $30
If I lose, I lose $100.  the expected loss is:                     40% x (- $100)    =   - $40
                                                     net expected return is                              =  - $10
The computer will pass. Why should it play when it expects to lose? In order for it to bet, it requires:
                                                            p × $50-(1-p)×$100 > 0

Solve[ p 50 -(1-p) 100 ==0, p]

In other words, it has to be > 0.667 winning probability for it to place a bet and expect a positive return. To the computer, there is NOT one discriminant line, but 2. This is the win-loss curve that the computer looks at:

The above chart shows positive expected payoff in green and loss in red. It will bet if the given height is to the left (bet woman) or the right (bet man) of the two white discriminat lines, but NOT in between the two lines because the expected payoff is negative (red) in that range. That little advantage is why the computer can statistically beat you when playing sufficiently many rounds. 
Below is the payoff table. The two curves are simply the two payoff functions in the table for the two strategies: bet woman or bet man for a given height.

({{□, if outcome is men, if outcome is woman, Expected return}, {payoff if bet man, ρ (house pay), -1, ( ρ P[m|h] - P[w|h] )}, {payoff if bet woman, -1, ρ, (-P[m|h] +ρ P[w|h] )}, { bet none, 0, 0, 0}})

So, in a real life practical calculation, the discriminants are calculated based on cost (or payoff) - not a simple Bayes’ decision like what we did above. Supposed the game rule is changed so that if you guess woman wrong, like guessing a woman’s age wrong, you have to pay down double the bet as a penalty, the strategy will be entirely different. Very few will bet on woman and the bet-woman curve will shift further to the left.

The math is still simple, everything is not done with just probability, but as we show above: 

         Net (gain/loss) = (Probability of event A) x (cost of event A)   
                                 +   (Probability of event B) x (cost of B) 
                                 + etc.

It is the expected return that matters. This is most relevant to investment or financial planning. It is also what insurance actuarians do all the time, from calculating your deductibles to premiums. All to maximize the return (minimizing cost).

Exercise - calculation with cost or payoff

If the game rule changes to this: if the result is a woman, but if you guess it were man, you will lose double of your bet. Everything else the same, what would be your betting strategy. This type of things happen all the time in business when prices change, law/regulation change etc. Companies and business must change how they operate to maintain profit.

your answer

End exercise