Quantifying the Approximation of Normal Distribution using QQ Plot in MATLAB

Quantifying the Approximation of Normal Distribution using QQ Plot in MATLAB

As a newcomer to MATLAB, you may be wondering how to quantify the approximation of your data as a normal distribution. One way to do this is by creating a quantile-quantile (QQ) plot and analyzing its regression line.

In this article, we will explore how to create a QQ plot using MATLAB, quantify the data's prediction of the regression line, and determine the fit of the data to a normal distribution.

Creating a QQ Plot

To create a QQ plot in MATLAB, you can use the qqplot function. This function takes two inputs: the first is your data, and the second is the probability distribution (PD) that you want to compare it to. In this case, we will use the normal distribution.

Here's an example code snippet:

% Load the data
load('your_data.mat');

% Create a QQ plot of the data using the normal distribution as the PD
qqplot(your_data, 'norm');

This will generate a plot showing the quantiles of your data against the quantiles of the normal distribution.

Quantifying the Data's Prediction of the Regression Line

To quantify the data's prediction of the regression line, you can use the polyfit function to fit a polynomial curve to the QQ plot. This will give you an estimate of the slope and intercept of the regression line.

Here's an example code snippet:

% Load the data
load('your_data.mat');

% Create a QQ plot of the data using the normal distribution as the PD
[qq_x, qq_y] =.qqplot(your_data, 'norm');

% Fit a polynomial curve to the QQ plot (e.g. degree 1)
[poly_coef, ~] = polyfit(qq_x, qq_y, 1);

% Extract the slope and intercept of the regression line
slope = poly_coef(1);
intercept = poly_coef(2);

This will give you an estimate of the slope and intercept of the regression line that best fits your data.

Determining the Fit of the Data to a Normal Distribution

To determine the fit of your data to a normal distribution, you can use the normfit function to estimate the mean and standard deviation of the data. You can then compare these estimates to the true values (e.g. by checking if they are within a certain tolerance).

Here's an example code snippet:

% Load the data
load('your_data.mat');

% Estimate the mean and standard deviation of the data using normfit
[mean_est, std_est] = normfit(your_data);

% Compare the estimates to the true values (e.g. within a certain tolerance)
if abs(mean_est - true_mean) < tol && ...
 abs(std_est - true_std) < tol
 disp('Data is well-fit to a normal distribution');
else
 disp('Data is not well-fit to a normal distribution');
end

This will give you an estimate of the mean and standard deviation of your data, which you can use to determine whether it is well-fit to a normal distribution.


In this article, we have explored how to create a QQ plot using MATLAB, quantify the data's prediction of the regression line, and determine the fit of the data to a normal distribution. By following these steps, you should be able to gain insight into the properties of your data and determine whether it is well-fit to a normal distribution.

Happy coding!