Generate a sample data set and fit a piecewise distribution with a Pareto tail to the data by using paretotails. Find the number of segments in the fitted distribution by using the object function nsegments.
Generate a sample data set containing 10% outliers in the right tail.
rng('default'); % For reproducibility
right_tail = exprnd(5,100,1);
center = randn(900,1);
x = [center;right_tail];
Create a paretotails object by fitting a piecewise distribution to x. Specify the boundaries of the tails using the lower and upper tail cumulative probabilities. Pass in 0 and 0.9 so that a fitted object does not contain a lower tail segment, and consists of the empirical distribution for the lower 90% of the data set and a generalized Pareto distribution (GPD) for the upper 10% of the data set.
pd = paretotails(x,0,0.9)
pd =
Piecewise distribution with 2 segments
-Inf < x < 1.73931 (0 < p < 0.9): interpolated empirical cdf
1.73931 < x < Inf (0.9 < p < 1): upper tail, GPD(0.643752,1.62246)
Return the number of segments in pd by using the nsegments function.
n = nsegments(pd)
n =
2
You can also get the number of segments by using the NumSegments property. Access the NumSegments property by using dot notation.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.