- Generate your sample data from the distribution.
- Perform the Q-Q plot using qqplot.
- Calculate theoretical quantiles for the desired confidence intervals from the distribution.
- Calculate empirical quantiles from your sample data.
- Plot confidence intervals around the theoretical quantiles on the Q-Q plot.
Confidence intervals in QQplot
38 views (last 30 days)
Show older comments
I am using qqplot to demonstrate distribution fits, I think it would be beneficial to incude confidence intervals although I am not sure how to do this.
A minimum working example for the qqplot:
pd1 = makedist('Rician', 's', 1, 'sigma', 1);
figure(1)
qqplot(random(pd1,1e3,1), pd1)
0 Comments
Answers (1)
Hornett
on 18 Sep 2024
To include confidence intervals in a Q-Q plot for a distribution fit, you can follow these steps. MATLAB's qqplot function doesn't natively support confidence intervals directly, so you'll have to calculate and plot them manually. Here’s a conceptual approach to achieve this:
Here's how you can implement it with a Rician distribution example:
% Generate sample data
pd1 = makedist('Rician', 's', 1, 'sigma', 1);
sampleData = random(pd1,1e3,1);
% Perform the Q-Q plot
figure(1);
qqplot(sampleData, pd1);
% Calculate theoretical and empirical quantiles
p = (0.5:999.5)/1000; % Adjust the range based on your sample size
theoreticalQuantiles = icdf(pd1, p);
empiricalQuantiles = quantile(sampleData, p);
% Calculate confidence intervals for the theoretical quantiles
% This is a simple approach for demonstration; for actual confidence intervals,
% you may need a more specific method depending on the distribution and the data.
ci = 1.96 * std(sampleData) / sqrt(length(sampleData)); % 95% CI assuming normality
lowerBound = theoreticalQuantiles - ci;
upperBound = theoreticalQuantiles + ci;
% Plot confidence intervals
hold on;
plot(lowerBound, empiricalQuantiles, 'r--'); % Lower CI
plot(upperBound, empiricalQuantiles, 'r--'); % Upper CI
hold off;
This example uses a basic approach for calculating and plotting confidence intervals, assuming normality for simplicity and using 1.96 as the z-value for a 95% confidence interval. The confidence intervals are plotted as dashed red lines around the theoretical quantiles.
Note: The accuracy of these confidence intervals depends on the distribution of your data and the assumptions you're willing to make. For non-normal distributions or more accurate CI calculations, you might need to employ distribution-specific methods or bootstrapping techniques.
0 Comments
See Also
Categories
Find more on Descriptive Statistics and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!