フィルターのクリア

Confidence intervals in QQplot

17 ビュー (過去 30 日間)
Morten Nissov
Morten Nissov 2021 年 6 月 15 日
回答済み: Yash Sharma 2024 年 5 月 22 日
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)

回答 (1 件)

Yash Sharma
Yash Sharma 2024 年 5 月 22 日
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:
  1. Generate your sample data from the distribution.
  2. Perform the Q-Q plot using qqplot.
  3. Calculate theoretical quantiles for the desired confidence intervals from the distribution.
  4. Calculate empirical quantiles from your sample data.
  5. Plot confidence intervals around the theoretical quantiles on the Q-Q plot.
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.

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by