Which Are Heavier? Dogs Or Cats?. Applied statistics for machine learning
By: Seyma Tas
Tags: Two Sample T Test, Hypothesis Testing, Data Science, Statistics, Bias

Are dogs heavier than cats? If you believe the answer is yes, how would you statistically prove it?

This question may seem simple to you if you are not familiar with the scientific process. You may just think of weighing 20 dogs and 20 cats, calculating the averages of both dogs and cats weights and comparing the results. If the mean for cats is 9 pounds and the mean for dogs is 18 pounds, you can say: “Dogs are heavier than cats.” This approach may work when things are clear. But what if the mean for cats is 9 and for dogs is 10, are you going to be sure that dogs are heavier than cats? What if you are comparing a mean of 9.1 with a mean of 9.2?

Cases are not always simple like comparing dogs and cats. There are many critical applications of the scientific process. Imagine you are working on a newly developed treatment for cancer patients, and the results are very close to each other, you are going to determine a threshold to decide if this treatment is making a statistically significant decrease in cancer cells. You are not going to expect to discover the miracle treatment for cancer. You just expect to find a significant improvement in the situation of the patients.

Let’s go back to our lovely dogs and cats.

Source Giphy by MOODMAN

Statistical Analysis

Our question is: Are dogs heavier than cats? Which kind of analysis are we doing by answering this question?

There are two kinds of analysis in statistics.

Descriptive analysis

Descriptive analysis gives information that describes the data in some manner. We present the data in a more meaningful way and make a simpler interpretation of the data.

We use two main types of measures to describe the data:

Measures of central tendency: Mean, median, and mode.

Measures of spread: Standard deviation, absolute deviation, variance, range, and quartiles.

Inferential analysis

Inferential analysis is to tell things about a population from a sample taken from it. It allows us to make inferences from the data. We take data from samples and make generalizations about a population.

In inferential statistics, we cannot prove something because we don’t have the population data, but we can disprove something by showing an exception from sample data.

Estimating parameters: We take a statistic from your sample and predict a population parameter.

Hypothesis tests: We make a null and an alternative hypothesis and use the sample data to answer population questions.

We are doing inferential analysis while we are answering the dogs and cats question. Because we are trying to make an inference about the population parameters of all the dogs and all the cats by generalizing the descriptive statistics of the two samples.

Hypothesis testing:

A hypothesis can be thought of as an idea we are testing. Hypotheses are always about the population parameters, not the sample statistics.

We are trying to prove that dogs are heavier than cats, we set the hypotheses in this way.

Null Hypothesis

The null hypothesis is the idea we are testing against.

“Dogs are not heavier than cats.”

“Dogs and cats have equal average weights”

“There is not a difference in the mean weights of cat and dogs.”

Alternative Hypothesis

The alternative hypothesis is the idea we are testing for.

“Dogs are heavier than cats.”

“Dogs have more average weight than cats”

“There is a significant difference in the mean weights of cat and dogs.”

Sampling

Determining sample size

When it comes to sample size we say “The more samples, the better results”. But more samples mean more complex studies, more money, and more time to finish our study

Therefore, we determine confidence level, margin of error and population size and calculate the minimum sample size to finish our study.

Here is an online sample size calculator to find the minimum number of samples for the statistical inference.

Biased Samples

Biased samples occur when one or more parts of the population are more likely to be selected in a sample than others. An unbiased sample must be representative of the entire population.

Image by Petr Ganaj from Pixabay

If we choose pet cats and street dogs from different countries, it is not impossible to decide that cats are heavier than dogs.

Image by Andreas Almstedt from Pixabay

Cat and Dog Breeds

What about breeds? There is not a high variance in weights of cat breeds(5 lb to 15 lb) but when it comes to dogs, weights can change from 3 to 6 pounds for a Chihuahua to 180 pounds for an Irish wolfhound.

Irish wolfhound and Chihuahua, Image by David Mark from Pixabay

Male and Female Weights

The weights of males are more than the weights of females. We need to be cautious about the subgroups of our population.

Sampling Methods

Simple random sampling (SRS)

Simple random sampling is a method in which every member of the population has an equal chance of being selected. SRS is the ideal sampling method but due to many reasons, we sometimes are not able to do random sampling from the population.

For the dogs and cats case, we can use random sampling but we need to make sure that we have enough samples from all breeds.

Stratified sampling

We take the population and we divide it into something called strata, groups of similar things. Within each stratum, we take an SRS and combine the SRSs to get the full sample.

Stratified sampling can be an easy-to-implement solution in the cats and dogs analysis. Our strata are the cat and dog breeds. We select enough number of random dogs and cats from every breed.

We need to make female and male strata, too. We take equal numbers of female and male animals to our samples if there are equal numbers of male and female dogs and cats in the world. Are there equal numbers of female and male cats or dogs in the world? This is the topic of another statistical analysis.

Cluster sampling

Cluster is a group of subjects that have something in common. In cluster sampling, we divide the population into natural groups. We suppose that these groups are representing the population. We can make clusters according to their location and do SRS. Cluster sampling is efficient and cost-effective but the cluster may not represent the population and this can cause high sampling error.

In cats and dogs case, we can choose a zip code, locate the veterinary clinics in this zip code, and find the weights of the cats and dogs which come to these veterinary clinics. This is easier than finding random vet clinics all around the world but different breeds and weights cause sampling bias. It is necessary to find as many clusters(zip codes) as possible.

Systematic sampling

Instead of completely random selection, we select in an order.

In our case, we can select the petshops in the zipcodes ending with zero and obtain the samples from there.

Convenient sampling

Convenient sampling is also known as grab sampling, opportunity sampling or accidental sampling. You choose the easiest way to get your samples.

In our case, if we go to the closest pet shop, veterinary clinic or animal shelter and get the weights of the cats and dogs, we do convenience sampling. It is easy to get the samples but there is a high possibility of getting a biased sample.

Sampling error

Sampling error is the difference between the sample and the population. Even if we use the best sampling methods, a sampling error may occur. To decrease the sampling error, we should increase the sample size and randomize the selection as much as possible.

Non-sampling error

Non-sampling error is the total of all forms of error other than sampling error.

We can make measuring error while finding the weights of the animals. We can even make processing error during the data entry.

We can make an adjustment error during the data cleaning process. For example, the weight units of the animals from countries other than the US are going to be in kilograms. We can make a mistake in converting kilograms to pounds. (I convert pounds to kilograms as a former physicist who got used to the metric system.)

Probability of error

In the scientific process, you can come to a result but you would need to clarify the probability of making this conclusion by chance.

Significance level

Significance level(Alpha Threshold) is the probability that you say the null hypothesis is wrong when it is true(Type-I error). An alpha value of 0.05 indicates that you are willing to accept a 5% chance that you are wrong when you reject the null hypothesis.

Summary statistics

Central tendency

We summarize the position of the data by calculating the mean, median, and mode. In each case, we should decide which summary values are the most indicative of the distribution.

In the cats and dogs question, calculating the mean seems to be the most appropriate statistic.

Measures of spread (variation)

Measures of spread tell us how data is spread around the middle. How can mean, median, and mode represent the data.

Range

The range takes the smallest number in the dataset and subtracts this number from the largest number in the dataset. The range gives us the distance between two extremes. The larger the range, the more the data is spread out.

In our case, the range of dog weights is bigger than the range of cat weights.

Interquartile range(IQR)

The IQR looks at the spread of the middle 50 percent of your data and gives an idea of the core values. IQR is the difference between the first and the third quartiles.

We can use an online calculator to find the IQR of our dog and cat weights.

Variance

Variance measures the dispersion of the data points around their mean.

Sample variance is equal to the sum of squared distances between the observed values and the sample mean divided by total number of observation minus 1.

The closer the data points to the mean the lower variance we will obtain. As we mentioned above, the variance of dogs is going to be bigger than the variance of cats.

Standard deviation

Standard deviation is the square root of variance. It is the most common variability for variability for a dataset.

In most statistics, standard deviation is much more meaningful than the variance. Because variance has squared units and the results are not as meaningful as standard deviation.

In the cats and dogs case, our variance unit is pound square and standard deviation unit is pounds. Therefore, standard deviation tells us more about the distribution of data in interpretable units.

Coefficient of variation (Relative standard deviation)

Coefficient of variation is equal to standard deviation divided by mean. We need standard relative standard deviation to compare the variance of two different datasets.

In our case, we compare the variations of cats weights and dogs weights using relative standard deviation.

Choosing the right statistics test

There are abundant statistical tests out there, some of them are student’s t-test, Mann Whitney-U test, Chi-square test, correlation test, and ANOVA.

We choose the right test by asking these questions:

Is the data nominal(categorical), ordinal or quantitative(interval-ratio)?

How many samples do we have?

What are we trying to prove? What is the purpose of our analysis?

In our case, weight is quantitative data. So we use student’s t-test if we have more than 30 samples and Mann- Whitney-U test if we have less than 30 samples. (This is controversial!)

The t-value measures the size of the difference in mean values relative to the variation in your sample data.

Mann — Whitney- U test compares differences between two independent groups when the dependent variable is continuous, but not normally distributed.

The magic number:

Why do we choose the test according to a number? T-test assumes that the data has a normal distribution. But we can not check normality if the sample size is less than 30.

Interpret the results

After finding the t-statistics and p-value, we compare p-value with the threshold we determined in the beginning of the analysis.

P- value is the probability of making type-I error. P-value tells us the probability of getting a result like this if the null hypothesis is true. For example, if the p-value is 0.01, it means that there is a 1 percent chance of rejecting the null hypothesis even if it was true.

If p-value is less than the threshold, we are able to reject the null hypothesis.

If p-value is more than the threshold, we can’t reject the null hypothesis.

Conclusion

You read an applied statistics review for data analysis. We asked a very simple question and overviewed many statistical concepts used in data science.

Are dogs heavier than cats? We didn’t even get the data yet! I am going to the closest animal shelter to weigh dogs and cats.

You should say to me: “Stop! You are making a convenience error!”