What is shapiro test? How to perform it in R

This recipe explains what is shapiro test This recipe helps you perform it in R

Recipe Objective

What is shapiro test?

How to perform it in R? Shapiro test is a statistical test used to check whether the considered data is normally distributed data or not. In shapiro test, The null hypothesis is states that the population is normally distributed i.e if the p-value is greater than 0.05, then the null hypothesis is accepted. The alternative hypothesis states that the population is not normally distributed i.e if the p-value is less than or equal to 0.05, then the null hypothesis is rejected. This recipe demonstrates an example on shapiro test in R.

Unlock The Top Reasons to Pursue a Machine Learning Career Now !

Step 1 - Define a hypothesis

Null Hypothesis : The population is normally distributed. Alternate Hypothesis : The population is not normally distributed.

Step 2 - Define a data

set.seed(10) data_1 <- rnorm(50) set.seed(30) data_2 <- rnorm(50)

Step 3 - Use the shapiro-test

shapiro.test(data_1) # As the test returns a p-value less than 0.05, we reject the null hypothesis and conclude that the population data is not normally distributed.

"Output of code is :"

	Shapiro-Wilk normality test

data:  data_1
W = 0.97492, p-value = 0.3625

hist(data_1, col='steelblue') # the histogram shows that the curve is mildly left skewed in nature shapiro.test(data_2) # As the test returns a p-value greater than 0.05, we accept the null hypothesis and conclude that the population data is normally distributed.

"Output of code is :"

	Shapiro-Wilk normality test

data:  data_2
W = 0.9888, p-value = 0.9143

hist(data_2, col='steelblue') # the histogram shows that the curve is normally distributed in nature {"mode":"full","isActive":false}

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

Build an End-to-End AWS SageMaker Classification Model
MLOps on AWS SageMaker -Learn to Build an End-to-End Classification Model on SageMaker to predict a patient’s cause of death.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.

ML Model Deployment on AWS for Customer Churn Prediction
MLOps Project-Deploy Machine Learning Model to Production Python on AWS for Customer Churn Prediction

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Avocado Machine Learning Project Python for Price Prediction
In this ML Project, you will use the Avocado dataset to build a machine learning model to predict the average price of avocado which is continuous in nature based on region and varieties of avocado.

Build Portfolio Optimization Machine Learning Models in R
Machine Learning Project for Financial Risk Modelling and Portfolio Optimization with R- Build a machine learning model in R to develop a strategy for building a portfolio for maximized returns.