Test of Normality
Test of Normality
Gaussian distribution. The normal distribution, often referred to as the bell curve, is a symmetrical
probability distribution characterized by a mean (average) and a standard deviation.
There are several methods and tests available to assess the normality of data. Some of the common
tests for normality include:
1. Shapiro-Wilk Test: The Shapiro-Wilk test is a widely used test for normality. It calculates a test
statistic based on the sample data and compares it to a critical value to determine if the data
significantly deviates from a normal distribution.
The Shapiro-Wilk test is a statistical test used to determine whether a given sample of data
follows a normal distribution. It assesses whether the data significantly deviates from a normal
distribution. Here's an example of how to perform a Shapiro-Wilk test in Python using the
SciPy library:
In this example, the Shapiro-Wilk test is applied to the data array. The test statistic and p-value
are computed. You then compare the p-value to a chosen significance level (alpha) to make a
decision about whether to reject the null hypothesis. If the p-value is less than alpha, you
would reject the null hypothesis and conclude that the data does not follow a normal
distribution. If the p-value is greater than alpha, you would fail to reject the null hypothesis,
indicating that the data does follow a normal distribution.
What is the SciPy library?
SciPy is a scientific computation library that uses NumPy underneath. SciPy stands for Scientific
Python. It provides more utility functions for optimization, stats and signal processing. Like NumPy,
SciPy is open source so we can use it freely. SciPy was created by NumPy's creator Travis Olliphant.
1. One-sample Kolmogorov-Smirnov test: This version of the test assesses whether a sample
comes from a particular distribution. It calculates the maximum vertical difference (D-statistic)
between the empirical cumulative distribution function (ECDF) of the sample and the
cumulative distribution function (CDF) of the theoretical distribution. The null hypothesis is that
the sample follows the theoretical distribution.
2. Two-sample Kolmogorov-Smirnov test: This version is used to compare the distributions of
two independent samples. It computes the maximum vertical difference (D-statistic) between
the ECDFs of the two samples. The null hypothesis in this case is that the two samples are
drawn from the same distribution.
Here's a general outline of how you would use the Kolmogorov-Smirnov test:
The Kolmogorov-Smirnov test is a useful tool for testing the normality of data, comparing two
datasets, or determining if data follows a specific distribution. It's important to note that it has
limitations, and it might not be the best choice in all situations, especially when dealing with small
sample sizes or discrete data. Other tests and methods may be more appropriate in those cases.
It's important to note that no test of normality is perfect, and the results can be influenced by the
sample size. Additionally, real-world data often deviates from a perfect normal distribution, so the
decision to use parametric or non-parametric statistical tests should be based on the specific
characteristics of your data and your research objectives.
It then calculates a p value (probability value). The p-value estimates how likely it is that you would
see the difference described by the test statistic if the null hypothesis of no relationship were true.
If the value of the test statistic is more extreme than the statistic calculated from the null hypothesis,
then you can infer a statistically significant relationship between the predictor and outcome
variables.
If the value of the test statistic is less extreme than the one calculated from the null hypothesis, then
you can infer no statistically significant relationship between the predictor and outcome variables.
For a statistical test to be valid, your sample size needs to be large enough to approximate the true
distribution of the population being studied.
Statistical assumptions
Statistical tests make some common assumptions about the data they are testing:
If your data do not meet the assumption of independence of observations, you may be able to use a
test that accounts for structure in your data (repeated-measures tests or tests that include blocking
variables).
Types of variables
The types of variables you have usually determine what type of statistical test you can use.
Quantitative variables represent amounts of things (e.g. the number of trees in a forest). Types of
quantitative variables include:
Continuous (aka ratio variables): represent measures and can usually be divided into units smaller
than one (e.g. 0.75 grams).
Discrete (aka integer variables): represent counts and usually can’t be divided into units smaller than
one (e.g. 1 tree).
Categorical variables represent groupings of things (e.g. the different tree species in a forest).
Types of categorical variables include:
Choose the test that fits the types of predictor and outcome variables you have collected (if you are
doing an experiment, these are the independent and dependent variables). Consult the tables below
to see which test best matches your variables.
The most common types of parametric test include regression tests, comparison tests, and
correlation tests.
Regression tests
Regression tests look for cause-and-effect relationships. They can be used to estimate the effect of
one or more continuous variables on another variable.
Multiple linear Continuous Continuous What is the effect of income and minutes of exercise
regression 2 or more 1 outcome per day on longevity?
predictors
Logistic regression Continuous Binary What is the effect of drug dosage on the survival of a
test subject?
Comparison tests
Comparison tests look for differences among group means. They can be used to test the effect of a
categorical variable on the mean value of some other characteristic.
T-tests are used when comparing the means of precisely two groups (e.g., the average heights of
men and women). ANOVA and MANOVA tests are used when comparing the means of more than
two groups (e.g., the average heights of children, teenagers, and adults).
Paired t-test Categorical Quantitative What is the effect of two different test prep
1 predictor groups come from the programs on the average exam scores for students from
same population the same class?
Independent t- Categorical Quantitative What is the difference in average exam scores for
test 1 predictor groups come from students from two different schools?
different populations
ANOVA Categorical Quantitative What is the difference in average pain levels among
1 or more 1 outcome post-surgical patients given three different painkillers?
predictor
Correlation tests
Correlation tests check whether variables are related without hypothesizing a cause-and-effect
relationship.
These can be used to test whether two variables you want to use in (for example) a multiple
regression test are autocorrelated.
If your data does not meet these assumptions you might still be able to use a nonparametric
statistical test, which have fewer requirements but also make weaker inferences.
The test statistic tells you how different two or more groups are from the overall
population mean, or how different a linear slope is from the slope predicted by a null
hypothesis. Different test statistics are used in different statistical tests.
Statistical significance is arbitrary – it depends on the threshold, or alpha value, chosen by the
researcher. The most common threshold is p < 0.05, which means that the data is likely to
occur less than 5% of the time under the null hypothesis.
When the p-value falls below the chosen alpha value, then we say the result of the test is
statistically significant.
What is the difference between quantitative and categorical variables?
Quantitative variables are any variables where the data represent amounts (e.g. height,
weight, or age).
Categorical variables are any variables where the data represent groups. This includes
rankings (e.g. finishing places in a race), classifications (e.g. brands of cereal), and binary
outcomes (e.g. coin flips).
You need to know what type of variables you are working with to choose the right statistical
test for your data and interpret your results.
NULL HYPOTHESIS -In scientific research, the null hypothesis is the claim that no
relationship exists between two sets of data or variables being analyzed. The null
hypothesis is that any experimentally observed difference is due to chance alone, and
an underlying causative relationship does not exist, hence the term "null."