Chi-Square Test With More Than 2 Categories

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

In this article, we will do a Chi-square test with more than 2 categories. We will use the A/B test « Country » which has 3 categories which corresponds to 3 countries : German, Spain and France. Select « Gender Actual » tab, make a copy with a right-click and select « Duplicate ».

Name the tab « Gender Actual (2) » by « Country Actual ».

In « Dimensions », move the variable « Geography » over « Gender » in « Columns » to replace « Gender » with « Geography ».

Here’s how to do an A/B statistical test when there are 3 categories. We’ll start with the classic method and then I’ll show you another way to do Chi-square test with any number of categories.

Let’s start with the classical method. In this case, there are 3 categories so we can’t use the online tool of the previous article. In the previous article we used an online tool with only 2 categories « Sample1 » and « Sample2 ». That’s why we’re going to use another online tool, click here  .

In this online tool, we can enter the values without using the total values. That is, we enter only the number of observations in each category. We simply need to enter the values that are on our A/B test. And I’m going to show you how to turn our A/B test into a table. In this way, it will be easier to enter the values in the online tool without making any mistakes.

Go to the « Show me » tool at the top right.

Click on « text tables »

Click on « Swap Rows ans Columns » button.

Cool, now you have a table arranged in exactly the same way as the online tool.

In the online tool, we will select 2 rows and 3 columns.

As we have 3 categories and 2 possible results, we enter our values exactly as in the table we just created on Tableau.

Perfect, our table is ready. You can click on the « Calculate » button.

As you can see, we observe the same thing as the other online tool. There is our indicator « p » value which is less than 5%. Which means there is a meaning.

This statistical significance means that these results are valid for the total number of the bank’s clients and not just for the sample of 10 000 clients. We observe similar differences with A/B test « Country » whose results are based solely on the sample of 10 000 clients. We can conclude that in the total number of the bank’s clients, it’s the clients in Germany who are more likely to leave the bank. This is how we do things cleanly.

You saw, this online tool limited by 5 by 5 tables so you can’t use this tool when you have 6 categories or more. But fortunately it’s possible to do Chi-square test with any number of categories. It’s a special method and for you to understand that, I’ll give you a theoretical explanation.

Here we have 3 countries : German, Spain and France.

What we’re trying to compare is the clients number leaving the bank in each of these countries.

With our basic A/B test based on a sample of 10 000 clients, we obtained 16% for France, 32% for Germany and 17% for Spain. Now the question is : « Do we observe the same results on the total clients number of the bank ? », it means : « In general, does the country have a significant effect on the clients number leaving bank ? ». Germany has the largest number of clients leaving the bank so the idea is : « Why would we need to compare the 3 countries at the same time ? ».

If we do an A/B test statistical test with Germany and France and we get a significant difference in the clients number leaving the bank between these 2 countries, then that would mean that in general, the country has a significant effect on the clients number who bank. Indeed, if we find by comparing Germany and France that the Germans are more likely to leave the bank than the French, we can consider that Spain will not change anything. Germans will always be more likely to leave the bank than the French. Maybe there will be a different relationship between Germany and Spain but there will always be a statistically significant difference between France and Germany with a larger number of clients leaving the bank in Germany than France.

Here is a way to confirm that this logic is true. There is a test and the participants of this test are German, Spanish and French. Imagine that this test was done without looking at what is happening in Spain. Now you get the result and you ask yourself the question : « Would the results changed if you added Spain ? ». The answer is « no » because there is no interdependence between Germany, Spain and France. That is, the decision to leave the bank in France and Germany doesn’t depend on Spain. And therefore, it’s quite correct to separate the categories by putting 1 aside to compare the 2 others. And as now we have 2 categories, we can do a Chi-square test with the online tool that we used in the previous article.

So let’s go back to our worksheet and put a country aside to compare only 2 countries. Select « Country » tab.

What we observe is that the difference between Spain and France is very small, so it wouldn’t be interesting to do a Chi-square test between Spain and France. It’s more interesting to do a Chi-square test between Germany and France and to prove that there is a statistically significant difference between these 2 countries. This will be enough to conclude that the country has a statistically significant impact on the clients number who leave the bank.

Selects « Country Actual » tab.

We will use the online tool of the previous article, click here  .

We will make a copy of « Country Actual » to have a bar chart with absolute values. Select « Country Actual », right-click and select « Duplicate ».

In « Show Me », select « horizontal bars ».

Removes « SUM (Number of Records )» from « Columns » and removes « Exited » and « Geography » from « Rows ».

In « Dimensions », move « Geography » in « Columns ».

In « Measures », move « Number of Records » to « Rows ».

In « Measures », move « SUM(Number of Records) » in « Label ».

In « Dimensions », move « Exited » in « Label ».

In « Dimensions », move « Exited » in « Colors ».

We also need total absolute values, which means the total number of men and women. There is a very fast way to get that. Right-click on the vertical axis and select « Add Reference Line ».

Then in « Value », click on the drop-down on the right and select « Sum » to have the total sum of the observations.

And in « Scope », you select « Per Cell » option to specify that you want the total sums for each category, male and female.

Now, we have the total sum at the top of the bars. We will modify labels to have the absolute values. In « Label », we will change « Computation » to « Value » and click on the « OK » button.

Here’s how to enter the data :

For « Sample1 » in #success, you enter 810 because there are 810 people who left the bank. For « Sample1 » in #trials, you enter 5014 because there are 5014 people in total.

For « Sample2 » in #success, you enter 814 because there are 814 people who left the bank. For « Sample2 » in #trials, you enter 2509 because there are 2509 people in total.

Here is the verdict : « Sample2 is more successful ». « Sample2 » corresponds to German’s clients and #success is :« yes, the client left the bank ». This verdict means that of all the clients from German are more likely to leave the bank than clients from France. And look, there is something important, it’s « p<0.001 ». This means that the « p » is strictly less than 0.001. As you can see, « p » value is very small, which concludes that the tests are statistically significant.

Ooh, there’s another thing I wanted to show you with the tab « age » with the 2 bar charts in parallel.

As you can see, there are many categories (more than 5) because each category corresponds to a 5-year ago group with clients of the bank aged from 15 to 90 years old. This is a lot of comparison but it would be a good exercise for you to find what are the 2 categories to compare that shows that there is a significant statistic difference.

I give you a hint, compare slices from 50 to 54 years old or from 35 to 39 years olds. In fact, you should compare all peer categories where you observe difference on this basic A/B test. Do a basic A/B test with absolutes values. Then do a Chi-square test to check if the difference is statistically significant, I mean, if the result is valid for the total number of bank’s clients.

This is a way to statistically validate the insights we see onTableau. You see, it’s not very difficult and it’s effective. Here is a way to find insights on Tableau and validate them.

-Steph

Validate Data Mining In Tableau With A Chi-Square Test

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

In this article we will start using statistics. Don’t worry we’ll do something simple, we’ll use the Chi-square test in a basic way. There is a special section to learn how to do statistics at an advanced level.

I’ll explain why we’re going to learn how to use the Chi-square test. The results we have with theses 2 bar charts are good. We see on theses 2 bar charts that age has a significant impact on the rate of client leaving the bank. We also see in which age groups the clients leaves the bank the most and which age groups the clients leave the bank the least. With that we have good insights.

In the A/B test « Gender », we can see that there is a correlation between the male and female sex and the choice to leave the bank. But as I said before, this A/B test is basic. The results of a basic A/B test visually shows us what is probably happenning in reality but we aren’t 100% sure of these results. To validate these results, we need do to use statistical tests like Chi-square test.

Doing a report based on basic A/B test is very risky and you can have completely false insights. I don’t advise you to do it (unless you want to leave your job). It’s for this reason that using Chi-square will help us to have strong insights.

Chi-square will allow us to know if our results are statistically significant. Our results are based on a sample of 10 000 clients and Chi-square test will tell us if these results are due to chance effects or if these results can represent all the client of the bank.

For example in our A/B test « Gender », we observed that in our sample of 10 000 clients, women are more likely to leave the bank compared to men.

Now, we aren’t sure if the results of this sample represent the behavior of all the bank’s clients.

To use basic Chi-square test, we use an online tool. Click here  .

On internet, there are plenty of websites to do a Chi-square test but we’ll use this one so that you can understand how it works. To do a Chi-square test, we need to use absolute values and in our A/B test we have percentage.

Let’s go back to Tableau. We’ll create a new tab with a version of A/B test with absolute values. In this way, we keep the A/B test with the percentages. Do a right-click on the « Gender » tab and select « Duplicate ».

Name the new tab « Gender Actual » to specify that it’s absolute values.

To have the absolute values, move « Number of Records » in « Measures » to the « Marks » area and put it over top of « SUM(Number of Records ».

Move « Number of Records » in « Measures » to « Rows » over « SUM(Number of Records ».

Cool, we have our absolute values.

We also need total absolute values, which means the total number of men and women. There is a very fast way to get that. Right-click on the vertical axis and select « Add Reference Line ».

Then in « Value », click on the drop-down on the right and select « Sum » to have the total sum of the observations.

And in « Scope », you select « Per Cell » option to specify that you want the total sums for each category, male and female.

Now, we have the total sum at the top of the bars. We will modify labels to have the absolute values. In « Label », we will change « Computation » to « Value » and click on the « OK » button.

Perfect, we have the total amount of observation at the top of each bar : 4543 women and 5457 men. We have what we need to use our online tool.

OK, I’ll explain how this tool works. « Sample1 » and « Sample2 » correspond to the independent variable « Gender ». You choose in which order you enter the data, « Sample1 » for men or the opposite. In our case, we use « Sample1 » for women and « Sample2 » for men.

« #success » corresponds to the result Y=1, which means in our case « yes, the client left the bank ».

« #trials » is the total number of observations, which means the total number of women in « Sample1 » and the total number of men « Sample2 ».

That’s how you enter the data :

• For « Sample1 » in #success, you enter 1139 because there are 1139 women who left the bank. For « Sample1 » in #trials, you enter 4543 because there are 4543 women in total.

• For « Sample2 » in #success, you enter 898 because there are 898 men who left the bank. For « Sample2 » in #trials, you enter 5457 because there are 5457 men in total.

Here is the verdict : « Sample1 is more successful ». « Sample1 » corresponds to women and #success is :« yes, the client left the bank ». This verdict means that of all the bank’s client, women are more likely to leave the bank than men. And look, there is something important, it’s « p<0.001 ». This means that the « p » is strictly less than 0.001.

« p » is the value that indicates whether an independent variable has a statistically significant effect on a dependent variable. In our case, the independent variable is « Gender » and the dependent variable is « Exited », which is : « yes, the client left the bank ». So « p » is strictly less than 0.001, which means that the independent variable « Gender » has a statistically significant effect on the dependent variable « Exited ». This shows us that out of the total number of bank’s clients, women are more likely to leave the bank than men.

This is how we use Chi-square test with this online tool. This is the same principle on all online tools that you can find on Google or DuckDuckGo . You can repeat these instructions that I gave you with other tools, you will get the same results.

It’s cool with the Chi-square we validated the A/B test and to specify that this A/B test is validated, we’ll color the tab in green.

Right-click on the tab, select « Color » and select « Green ».

Perfect, now we’ll validate another A/B test. Selects « HasCreditCard » tab.

We’re going to create an A/B test « HasCreditCard » only with absolute values. To save time, right-click on « Gender Actual » tab and select « Duplicate ».

We’ll remove the green color on the tab « Gender Actual (2) ». Right-click on the tab and select « Color » and « None ».

You rename the tab « HasCreditCard Actual ».

Move the variable « HasCrCard » over « Gender » in « Columns ».

Excellent, everything is ready to do a Chi-square test. We’ll remove « Exited » labels to better see the absolutes values. Make a click and drag out.

Perfect, let’s go back to our online tool. In this case, « Sample1 » is « no », which means client who don’t have credit card and « Sample2 » for « yes », which means clients who have a credit card.

That’s how you enter the data :

• For « Sample1 » in #success, you enter 613 because there are 613 clients who left the bank. For « Sample1 » in #trials, you enter 2945 because there are 2945 clients who don’t have a credit card.
• For « Sample2 » in #success, you enter 1424 because there are 1424 clients who left the bank. For « Sample2 » in #trials, you enter 7055 because there are 7055 clients who have a credit card.

Let’s look at the verdict, it’s « No significant difference ». « p » value is very high, it’s above 5%. This confirms that the independent variable « HasCrCard » has no statistically significant effect on the dependent variable « Exited ». That was the conclusion we had made when we had done the A/B test with percentages.

We had seen that there was 21% of « Exited » (clients who left the bank) in the category « no » and 20% in the category « yes ». With these results we concluded that most likely the variable « HasCrCard » had no impact on the rate of clients who left the bank. Chi-square test confirms our conclusion and we can put the tab « HasCrCard » in green to say that it’s OK.

Right-click on the tab « HasCreditCard » => « Color » => « Green ».

Excellent, now, you can do a statistical A/B test with 2 categories. Soon, we will do statistical A/B tests with more than 2 categories.

-Steph

Abs Stretching

What’s up ? This is THE stephane ANDRE ! I read a Frederic Delavier’s book « Strength Training Anatomy » and I learned good stuff.

• Maintain this position for few seconds while breathing slowly to feel the stretching of your abs.

Variant

It’s possible to make this movement with your hands on a bench and your feet on the floor, or you’re lying on your back on a big ball (Swissball).

Note

Stretching of abs can be an important element in some sports like throwing sports, especially the javelin. In this type of sports, it’s essential to have good flexibility and a good abdominal amplitude to make the movement perfectly.

Attention

Abs stretching are to be avoided in case of lumbar pathology.

Note

The position tilted forward (anteversion) of women’s pelvis allows a portion of the child’s weight to be transferred to the abs. By analogy, abs muscles can be compared to a « hammock ».

-Steph

Good Position For Abs

Action on lumbar curvature of the psoas muscle

Psoas muscles have other functions than to be powerful flexors of hip. They put the lumbar spine in lordosis, which increases the arch.

I read a Frederic Delavier’s book « Strength Training Anatomy » and I learned good stuff.

Abs exercises (especially for rectus abdominis) must work with the round back (round your spine). It’s the opposite of other exercises.

For vertebral coil exercises, the mechanicals stresses on vertebral joints aren’t the same as for exercises such as squat, deadlift and other exercises with weight. For example, for squat, the spine isn’t arched at the lumbar level. The vertical pressure with the spine’s rounding pushes the nucleus pulposus intervertebral disc backwards, which can compress nerve elements and create sciatic herniated disc.

For abs exercises, it’s the opposite. If during the abs execution you forget to round your back with an intense contraction of abs and obliques, the powerful flexors of hips (psoas major) will increase the lumbar arch. This will move the intervertebral discs forward as they aren’t stabilized by the vertical pressure. Then an excess of pressure at the back of the lumbar vertebral joints can create lumbago or more serious, joints damage by compression and shear.

-Steph

Individual Variations In Hip Mobility

I read a Frederic Delavier’s book « Strength Training Anatomy » and I learned good stuff.

Without taking into account the individual differences in muscle elasticity and ligament laxity, it’s bone shape of the hip joint that determines the main variation in hip mobility.

It’s mainly in the amplitude of hip abduction that bone configuration plays an important role.

Examples

• An almost horizontal femoral neck (coxo vara) with an upper edge of the important cotyloid cavity and covering, will limit abduction movements.

• An almost vertical femoral neck (coxa valga) with an upper edge of the less important cotyloid cavity will facilitate abduction movements.

This means that it is useless to raise the leg very high laterally if the morphology doesn’t allow it.

Attention

If someone forces the hip’s abductions, femur’s neck will bump on the cotyloid cavity edge. And this person will compensate the lateral raise of the leg with a pelvic tilt on the femur head of the other leg. It should be added that forcing oneself to make abduction sets may, over time, create microtraumas in some people that will cause excessive development of the cotyloid cavity upper edge. This has the consequence of limiting the hip’s mobility and creating painful inflammations.

-Steph

How To Do Box Squat

I read a Frederic Delavier’s book « Strength Training Anatomy » and I learned good stuff.

Box squat is often used by powerlifters to gain strength to do squat.

This exercise involves doing a squat sitting on a bench for 1-2 seconds and returning to the standing position .

In classic squat the tension accumulated in the muscles during the negative phase when you get down (as a stretched elastic ) and this tension restored during the positive phase when you get up. With box squat, sitting on the bench relaxed thighs muscle, there is not tension accumulated when you get down to be used when you get up.

For the same weight, quadriceps should provide more effort for box squat than classic squat. It’s a great exercise to target work on thighs.

This exercise can be included in a training program for people who have long legs and don’t feel their quadriceps work with classic squat.

Starting squat in sitting position allows push automatisms for the classic squat which has the effect of having the positive phase to get up faster and more powerful.

Attention : It’s necessary to be careful for this exercise in controlling the movement to get down to sit gently on the bench. If get down too fast, the butt crash on the bench and this can create serious trauma due to shock and excessive compression of spinal joints.

Note: There are special benches adaptable for different morphologies with a very padded seat to limit the risk of spinal injuries and the possibility of adjusting the height. To have a good execution of the movement, it’s necessary to have your back slightly incline. If your back is too vertical at start of the bench, the exercise will be impossible to do.

-Steph

How To Do Chin-Ups

I read a Frederic Delavier’s book « Strength Training Anatomy » and I learned good stuff.

In suspension at the fixed bar with your hands apart with a pronated grip:

• Inhale and pulls to bring your chest almost to the level of the bar

• Exhale at the end of the movement

This exercise works latissimus dorsi, teres major and when approaching the shoulder blades at the end of the movement, it’s the rhomboids and trapezius (middle and inferior part). This exercise works a little bit biceps brachii, brachialis, brachioradialis.

This exercise works the back in thickness.

Variants

By pulling out your chest, you can pull to the chin.

If lifting your bodyweight is too easy, you can attach weights to a belt.

From a biomechanical point of view, do this exercise with your elbows along your body work the outer fibers of the latissimus dorsi and develop your back in width.

By pulling out your chest with your elbows back to pull to your chin, work the upper and middle fibers of the latissimus dorsi and those of the teres major.

Note

Pectoralis major works a little bit to be in synergy with the latissimus dorsi and teres major to close the angle between your arm and your core.

Evolution

Latissimus dorsi and teres major have an important role in the four-legged movement of our distant ancestors. They have the function of pushing the front legs backward.

During arboreal life, these muscles were transformed into muscles specialized in vertical displacement.

During life on the ground, our ancestors bought the biped but retained the possibility of climbing.

That’s why we have powerful back’s muscles to tow our bodies and climb trees.

Note

The difference that human beings have with our close relatives, the monkeys, is the development of lower limbs specializing in bipedalism. Our torso and upper limbs have the same structure and proportions. The truth is that monkeys don’t have long arms, it’s us who have long legs.