Liwaiwai Liwaiwai
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • About
Liwaiwai Liwaiwai
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
    • Architecture
    • Design
    • Software
    • Hybrid Cloud
    • Data
  • About
  • Data
  • Programming

How To: Perform Tests for Normality in R

  • August 7, 2019
  • admin

Normality is one assumption that you will typically encounter in statistical methods that you will employ. A lot of the tests that were created have an underlying assumption that your data is normal.

A large number of parametric tests assume normality of data. Ordinary least squares regression assumes it for its error terms, too. You can diagnose your data for normality in the statistical programming language R. The companion software, RStudio, will make everything easier for you. The good news is, you can do it for free.

If you are an Ubuntu user, here’s how to install R.

Requirements

To perform the normality tests, you should have installed the following beforehand:

  • R (at least version 3.6.0)
  • RStudio (download it here)
  • R’s olsrr package

Performing the Tests

For the purpose of this tutorial, let’s generate a data set to perform the tests on by executing the following code:

> data <- rnorm(100)

This code will generate 100 random numbers that follow a standard normal distribution. Our data may differ with one another, but we will expect them to be normal.

Now, there are two ways to diagnose your data for normality:

  • Through visual inspection,
  • Through statistical tests.

You can’t just use one or the other. You have to use both methods to diagnose your data.

Visual Inspection

The first method is by visual inspection. The way to do this is to generate normal quantile-quantile plots (Q-Q plots). Q-Q  plots will compare your data with the theoretical normal behavior. If your data falls in a straight diagonal line, then your data is most likely normal.

Read More  Huawei Releases Top 10 Trends of Data Center Facility In 2025

We can do this by using R’s  qqnorm( ) function:

qqnorm(data)

 

Running this line of code will yield a plot similar to this:

Now we see that the data points follow an approximately straight line. You wouldn’t suspect it to be not normal.

A non-normal data would look like something like this:

Or something like this:

Now that we have concluded that our data is most likely normal, we can further confirm this by running some statistical tests.

Statistical Tests

There are a lots of normality tests. R’s olsrr package will let you perform several normality tests at once. If you haven’t installed it yet, do so by executing the following line:

> install.packages("olsrr")

 

After this, load the package using the next line:

require(olsrr)

 

Now that you have the olsrr package loaded, you’re ready to go. Execute the following line to conduct the normality tests:

> ols_test_normality(data)

 

Your output should be something similar:

How would you know if the data is normal according to the tests? The null hypotheses of these tests assume that the data is normal. Let’s assume that the set level of significance is 0.05, the typical level it is set to.

If the p-value is less than the set level of significance, then we are compelled to reject the null hypothesis of normality. Otherwise, we do not reject it.

Three of the tests yielded values that are above 0.05. All of them indicate that we should not reject normality. One test on the other hand, the Cramer-von Mises test, say that the data is not normal.

Read More  Google Cloud Next 2019 | Telemedicine: A Global Perspective

What happens now?

Most of the time, normality tests agree with one another regarding the normality of data. If not, just like in our case, then check your Q-Q plots in conjunction to the normality tests that you have conducted to see if it is safe to assume normality.

Given our data, despite one test suggesting non-normality, we are compelled to conclude that normality can be safely assumed. Given the visual plots and the number of normality tests which have agreed in terms of their p-values, there is not much doubt.

With this example, we see that statistics does not give perfect outputs. Statistical outputs only serve as guides. We have to use our creativity and the knowledge we have in our field so that we are guided well by the outputs our statistical tools give us.

admin

Related Topics
  • Dataset
  • Normality Test
  • Statistics
You May Also Like
View Post
  • Big Data
  • Data
  • Design

From Raw Data To Actionable Insights: The Power Of Data Aggregation

  • March 30, 2023
View Post
  • Data
  • Design
  • Engineering

Effective Strategies To Closing The Data-Value Gap

  • March 30, 2023
View Post
  • Artificial Intelligence
  • Data
  • Data Science
  • Machine Learning
  • Technology

Google Data Cloud & AI Summit : In Less Than 12 Hours From Now

  • March 29, 2023
View Post
  • Data
  • Machine Learning
  • Platforms

Coop Reduces Food Waste By Forecasting With Google’s AI And Data Cloud

  • March 23, 2023
View Post
  • Data
  • Engineering

BigQuery Under The Hood: Behind The Serverless Storage And Query Optimizations That Supercharge Performance

  • March 22, 2023
View Post
  • Data
  • Design
  • Engineering
  • Tools

Sumitovant More Than Doubles Its Research Output In Its Quest To Save Lives

  • March 21, 2023
View Post
  • Data
  • Platforms
  • Technology

How Osmo Is Digitizing Smell With Google Cloud AI Technology

  • March 20, 2023
View Post
  • Data
  • Engineering
  • Tools

Built With BigQuery: How Sift Delivers Fraud Detection Workflow Backtesting At Scale

  • March 20, 2023

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay Connected!
LATEST
  • 1
    DBS Singapore: The Best Boasting To Be The Best For So Long, Humbled By Hubris
    • March 31, 2023
  • 2
    Bard And ChatGPT — A Head To Head Comparison
    • March 31, 2023
  • 3
    Modernize Your Apps And Accelerate Business Growth With AI
    • March 31, 2023
  • 4
    Why Your Open Source Project Needs A Content Strategy
    • March 31, 2023
  • 5
    From Raw Data To Actionable Insights: The Power Of Data Aggregation
    • March 30, 2023
  • 6
    Effective Strategies To Closing The Data-Value Gap
    • March 30, 2023
  • 7
    Unlocking The Secrets Of ChatGPT: Tips And Tricks For Optimizing Your AI Prompts
    • March 29, 2023
  • 8
    Try Bard And Share Your Feedback
    • March 29, 2023
  • 9
    Google Data Cloud & AI Summit : In Less Than 12 Hours From Now
    • March 29, 2023
  • 10
    Talking Cars: The Role Of Conversational AI In Shaping The Future Of Automobiles
    • March 28, 2023

about
About
Hello World!

We are liwaiwai.com. Created by programmers for programmers.

Our site aims to provide materials, guides, programming how-tos, and resources relating to artificial intelligence, machine learning and the likes.

We would like to hear from you.

If you have any questions, enquiries or would like to sponsor content, kindly reach out to us at:

[email protected]

Live long & prosper!
Most Popular
  • 1
    Introducing GPT-4 in Azure OpenAI Service
    • March 21, 2023
  • 2
    Document AI Introduces Powerful New Custom Document Classifier To Automate Document Processing
    • March 28, 2023
  • 3
    How AI Can Improve Digital Security
    • March 27, 2023
  • 4
    ChatGPT 4.0 Finally Gets A Joke
    • March 27, 2023
  • 5
    Mr. Cooper Is Improving The Home-buyer Experience With AI And ML
    • March 24, 2023
  • /
  • Artificial Intelligence
  • Machine Learning
  • Robotics
  • Engineering
  • About

Input your search keywords and press Enter.