Median of probability distribution
Median of a Fitted Distribution
Load the sample data. Create a vector containing the first column of students' exam grade data.
load examgrades x = grades(:,1);
Create a normal distribution object by fitting it to the data.
pd = fitdist(x,'Normal')
pd = NormalDistribution Normal distribution mu = 75.0083 [73.4321, 76.5846] sigma = 8.7202 [7.7391, 9.98843]
Compute the median of the fitted distribution.
m = median(pd)
m = 75.0083
For a symmetrical distribution such as the normal distribution, the median is equal to the mean,
Median of Skewed Distribution
Create a Weibull probability distribution object.
pd = makedist('Weibull','A',5,'B',2)
pd = WeibullDistribution Weibull distribution A = 5 B = 2
Compute the median of the distribution.
m = median(pd)
m = 4.1628
For a skewed distribution such as the Weibull distribution, the median and the mean may not be equal.
Calculate the mean of the Weibull distribution and compare it to the median.
mean = mean(pd)
mean = 4.4311
The mean of the distribution is greater than the median.
Plot the pdf to visualize the distribution.
x = [0:.1:15]; pdf = pdf(pd,x); plot(x,pdf)
m — Median
Median of the probability distribution, returned as a scalar value. The
m is the 50th percentile of the probability
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
The input argument
pdcan be a fitted probability distribution object for beta, exponential, extreme value, lognormal, normal, and Weibull distributions. Create
pdby fitting a probability distribution to sample data from the
fitdistfunction. For an example, see Code Generation for Probability Distribution Objects.
For more information on code generation, see Introduction to Code Generation and General Code Generation Workflow.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Introduced in R2013a