主要内容

Working with Probability Distributions

概率分布是基于关于源总数的假设的理论分布。分布将随机变量具有特定,离散值或属于连续值的指定范围内的事件分配概率。

Statistics和Machine Learning Toolbox™提供了几种处理概率分布的方法。

  • Probability Distribution Objects— Create a probability distribution object by fitting a probability distribution to sample data or by specifying parameter values. Then, use object functions to evaluate the distribution, generate random numbers, and so on.

  • 应用and Interactive User Interfaces- 交互式拟合并探索概率分布Distribution Fitterapp,概率分布函数用户界面和随机数生成工具(randtool

  • 特定于分布的功能和通用分布功能- 这些功能对于生成随机数,计算循环或脚本内的摘要统计信息以及将CDF或PDF作为函数句柄传递给另一个函数很有用。您还可以使用这些功能在参数值数组中执行计算,而不是一组参数。

    • 使用特定于分布的功能,例如normpdfandNORMCDF,,,,with specified distribution parameters.

    • Use generic distribution functions (CDF,,,,ICDF,,,,PDF,,,,and随机的)带有指定的分发名称和参数。

有关统计和机器学习工具箱支持的分布列表,请参见金宝app金宝app支持的分布

Probability Distribution Objects

概率分布对象允许您拟合概率分布来示例数据,或通过指定参数值来定义分布。然后,您可以对分销对象执行各种分析。

创建概率分布对象

通过使用概率分布对象将概率分布对象拟合到数据菲迪斯特。You can fit a single specified parametric or nonparametric distribution to the sample data. You can also fit multiple distributions of the same type to the sample data based on grouping variables. For most distributions,菲迪斯特使用最大似然估计(MLE)来估计样品数据中的分布参数。有关更多信息和其他语法选项,请参见菲迪斯特

另外,您可以使用指定参数值创建一个概率分发对象制造者

Work with Probability Distribution Objects

Once you create a probability distribution object, you can use object functions to:

  • 分布参数的计算置信区间(paramci)。

  • Compute summary statistics, including mean (意思是),中位数(中位数),四分位数范围(IQR),差异(var)和标准偏差(std)。

  • 评估概率密度函数(PDF)。

  • Evaluate the cumulative distribution function (CDF)或反累积分布函数(ICDF)。

  • 计算负loglikelione(negloglik)and profile likelihood function (Proflik)for the distribution.

  • Generate random numbers from the distribution (随机的)。

  • 将分布截断为指定的上限和上限(截短)。

保存概率分配对象

将您的概率分配对象保存到.mat文件:

  • 在工具栏中,单击保存工作区。此选项保存工作空间中的所有变量,包括任何概率分发对象。

  • 在工作区浏览器中,右键单击概率分布对象,然后选择另存为。此选项仅保存所选概率分发对象,而不是工作空间中的其他变量。

另外,您可以使用save功能。saveenables you to choose a file name and specify the probability distribution object you want to save. If you do not specify an object (or other variable), MATLAB®保存所有的the variables in your workspace, including any probability distribution objects, to the specified file name. For more information and additional syntax options, seesave

使用概率分布对象分析分布

此示例显示了如何使用概率分布对象对拟合分布执行多步骤分析。

这analysis illustrates how to:

  • 将概率分布拟合到包含120名学生考试成绩的样本数据菲迪斯特

  • Compute the mean of the exam grades by using意思是

  • 绘制考试等级数据的直方图,并通过使用拟合分布的PDF的图覆盖阴谋andPDF

  • 通过使用来计算学生成绩前10%的边界ICDF

  • Save the fitted probability distribution object by usingsave

Load the sample data.

加载examgrades

这sample data contains a 120-by-5 matrix of exam grades. The exams are scored on a scale of 0 to 100.

创建一个包含考试成绩第一列的向量。

X= grades(:,1);

通过使用菲迪斯特创建概率分布对象。

pd = fitdist(x,'普通的'
pd = NormalDistribution Normal distribution mu = 75.0083 [73.4321, 76.5846] sigma = 8.7202 [7.7391, 9.98843]

菲迪斯特returns a probability distribution object,pd,类型正常分布。This object contains the estimated parameter values,muand西格玛,用于拟合的正态分布。参数估计值旁边的间隔是分布参数的95%置信区间。

使用拟合分配对象计算学生考试成绩的平均值,pd

M =平均值(PD)
M = 75.0083

考试等级的平均值等于mu参数估计菲迪斯特

绘制考试成绩的直方图。覆盖拟合的PDF的图,以将拟合的正态分布与实际考试等级进行比较。

X_pdf = [1:0.1:100]; y = pdf(pd,x_pdf); figure histogram(x,'正常化',,,,'PDF')线(x_pdf,y)

图包含一个轴对象。轴对象包含2个类型直方图的对象。

拟合分布的PDF遵循与考试等级的直方图相同的形状。

通过使用逆累积分布函数来确定学生考试上层10%的边界(ICDF)。This boundary is equivalent to the value at which the cdf of the probability distribution is equal to 0.9. In other words, 90 percent of the exam grades are less than or equal to the boundary value.

A = icdf(pd,0.9)
A = 86.1837

Based on the fitted distribution, 10 percent of students received an exam grade greater than 86.1837. Equivalently, 90 percent of students received an exam grade less than or equal to 86.1837.

保存拟合的概率分布,pd,作为命名的文件myObject.mat

节省('myobject.mat',,,,'PD'

应用and Interactive User Interfaces

应用程序和用户界面提供了一种与参数和非参数概率分布一起工作的交互式方法。

  • 使用Distribution Fitter应用程序以交互式拟合分布来示例数据,并将概率分布对象导出到工作空间。

  • 使用概率分布函数用户界面可在视觉上探索更改分布参数值的PDF和CDF的影响。

  • 使用随机数生成用户界面(randtool),从具有指定参数值的概率分布中进行交互生成随机数,并将其导出到工作区。

配电钳工应用程序

Distribution Fitterapp allows you to interactively fit a probability distribution to your data. You can display different types of plots, compute confidence bounds, and evaluate the fit of the data. You can also exclude data from the fit. You can save the data, and export the fit to your workspace as a probability distribution object to perform further analysis.

从“应用程序”选项卡或输入加载分销钳工应用程序DistributionFitter在命令窗口中。有关更多信息,请参阅使用Distribution Fitter应用程序模型数据

Default view of the Distribution Fitter app

概率分布函数Tool

概率分布函数用户界面视觉探索概率分布。您可以通过输入加载概率分布功能用户界面蒸汽在命令窗口中。

Default view of the Probability Distribution Function Tool

随机数生成工具

随机数生成用户界面从指定的分布生成随机数据,并将结果导出到工作空间。您可以使用此工具来探索更改参数和样本大小对分布的影响。

随机数生成用户界面允许您为分布设置参数值并更改其下限和上限;使用相同的大小和参数从同一分布中绘制另一个样本;并将当前的随机样本导出到您的工作区中,以进行进一步分析。对话框使您可以为样本提供名称。

随机数生成工具的默认视图

特定于分布的功能和通用分布功能

使用特定于分布的功能和通用分布功能可用于生成随机数,计算循环或脚本内的摘要统计信息,以及将CDF或PDF作为一个功能句柄to another function. You can also use these functions to perform computations on arrays of parameter values rather than a single set of parameters.

  • 特定于分布的功能 - 一些受支持的分布具有特定于分布的功能。金宝app这些功能使用以下缩写,如normpdf,,,,NORMCDF,,,,诺米夫,,,,NORMSTAT,,,,NORMFIT,,,,normlike,,,,andNORMRND

    • PDF- 概率密度功能

    • CDF- 累积分布功能

    • Inv- 累积分布函数s

    • stat- 分销统计功能

    • 合身- 配电钳工功能

    • 喜欢- 负loglikelihood函数

    • rnd- 随机数生成器

  • 通用分配功能 - 使用CDF,,,,ICDF,,,,mle,,,,PDF,,,,and随机的带有指定的分发名称和参数。

    • CDF- 累积分布函数

    • ICDF- 累积分布函数

    • mle— Distribution fitting function

    • PDF- 概率密度函数

    • 随机的— Random number generating function

使用特定于分布的功能分析分布

此示例显示了如何使用特定于分布的功能对拟合分布进行多步骤分析。

这analysis illustrates how to:

  • 将概率分布拟合到包含120名学生考试成绩的样本数据NORMFIT

  • 绘制考试等级数据的直方图,并通过使用拟合分布的PDF的图覆盖阴谋andnormpdf

  • 通过使用来计算学生成绩前10%的边界诺米夫

  • Save the estimated distribution parameters by usingsave

您可以使用概率分布对象执行相同的分析。看使用概率分布对象分析分布

Load the sample data.

加载examgrades

这sample data contains a 120-by-5 matrix of exam grades. The exams are scored on a scale of 0 to 100.

创建一个包含考试成绩第一列的向量。

X= grades(:,1);

通过使用NORMFIT

(μ、σmuCI sigmaCI] = normfit (x)
MU = 75.0083
Sigma = 8.7202
粘液=2×173.4321 76.5846
sigmaci =2×17.7391 9.9884

NORMFITfunction returns the estimates of normal distribution parameters and the 95% confidence intervals for the parameter estimates.

绘制考试成绩的直方图。覆盖拟合的PDF的图,以将拟合的正态分布与实际考试等级进行比较。

X_pdf = [1:0.1:100]; y = normpdf(x_pdf,mu,sigma); figure histogram(x,'正常化',,,,'PDF')线(x_pdf,y)

图包含一个轴对象。轴对象包含2个类型直方图的对象。

拟合分布的PDF遵循与考试等级的直方图相同的形状。

Determine the boundary for the upper 10 percent of student exam grades by using the normal inverse cumulative distribution function. This boundary is equivalent to the value at which the cdf of the probability distribution is equal to 0.9. In other words, 90 percent of the exam grades are less than or equal to the boundary value.

a = norminv(0.9,mu,sigma)
A = 86.1837

Based on the fitted distribution, 10 percent of students received an exam grade greater than 86.1837. Equivalently, 90 percent of students received an exam grade less than or equal to 86.1837.

将估计的分布参数保存为名称的文件myParameter.mat

节省('myparameter.mat',,,,'mu',,,,'Sigma'

将概率分布功能用作功能手柄

此示例显示了如何使用概率分布函数NORMCDF作为拟合测试的卡方优点中的功能手柄(chi2gof)。

该示例测试了无效的假设,即输入矢量中包含的样本数据,X,来自带有参数的正态分布µandσequal to the mean (意思是)和标准偏差(std)of the sample data, respectively.

rng('默认'%可再现性X= normrnd(50,5,100,1); h = chi2gof(x,'CDF',{@normcdf,mean(x),std(x)})
h = 0

返回的结果h = 0indicates thatchi2gof在默认的5%显着性水平上不会拒绝零假设。

下一个示例说明了如何在切片采样器中使用概率分布函数作为函数句柄(切片样本)。示例使用normpdf从标准正态分布中生成2,000个值的随机样品,并绘制结果值的直方图。

rng('默认'%可再现性x =切片样本(1,2000,'PDF',,,,@normpdf,'thin',5,'burnin',1000);直方图(x)

图包含一个轴对象。轴对象包含类型直方图的对象。

直方图显示,使用normpdf,所得的随机样品具有标准的正态分布。

If you pass the probability distribution function for the exponential distribution pdf (exppdf)as a function handle instead ofnormpdf, 然后切片样本从指数分布中生成2,000个随机样本,默认参数值为µequal to 1.

rng('默认'%可再现性x =切片样本(1,2000,'PDF',@exppdf,'thin',5,'burnin',1000);直方图(x)

图包含一个轴对象。轴对象包含类型直方图的对象。

这histogram shows that the resulting random sample when usingexppdf具有指数分布。

也可以看看

||||

Related Topics