[英]QQ-plot python mean and standard deviation
I am trying to plot a QQ plot using python.我正在尝试使用 python 绘制 QQ 图。 I was checking scipy.stats.probplot, and the input seems to be the measurement against a normal distributiom.
我正在检查 scipy.stats.probplot,输入似乎是对正态分布的测量。
import numpy as np
import pylab
import scipy.stats as stats
measurements = np.random.normal(loc = 20, scale = 5, size=100)
stats.probplot(measurements, dist="norm", plot=pylab)
pylab.show()
and in my code, I had在我的代码中,我有
stats.probplot(mean, dist="norm", plot=plt)
to compare distributions.来比较分布。
But I am wondering where can I input standard deviation?但我想知道在哪里可以输入标准偏差? I thought that's a very important factor when comparing distributions but so far I can only input the mean.
我认为这是比较分布时的一个非常重要的因素,但到目前为止我只能输入平均值。
Thanks谢谢
Let's suppose you have a list on float假设您有一个浮动列表
X = [-1.31,
4.82,
2.18,
1.99,
4.37,
2.58,
7.22,
3.93,
6.95,
2.41,
2.02,
2.48,
-1.01,
2.3,
2.87,
-0.06,
2.13,
3.62,
5.24,
0.57]
If you want to make a QQ_plot test you need to compare X against a distribution.如果要进行 QQ_plot 测试,则需要将 X 与分布进行比较。 For example : N(0, 1) a normal distribution whose mean = 0 and sigma = 1
例如:N(0, 1) 正态分布,其均值 = 0 且 sigma = 1
In OpenTURNS, it goes like that:在 OpenTURNS 中,它是这样的:
import openturns as ot
sample = ot.Sample([[p] for p in X])
graph = ot.VisualTest.DrawQQplot(sample, ot.Normal(0,1))
View(graph);
Explanation: I tell OpenTURNS I have a sample of 20 points [p] coming from X and not 1 point in dimension 20. Then I call ot.VisualTest.DrawQQplot
with 2 arguments: sample
and the Normal distribution (0,1) ot.Normal(0,1)
.解释:我告诉 OpenTURNS 我有一个来自 X 的 20 个点 [p] 的样本,而不是维度 20 中的 1 个点。然后我用 2 个参数调用
ot.VisualTest.DrawQQplot
: sample
和正态分布 (0,1) ot.Normal(0,1)
。
We see on the graph that the test fails:我们在图表上看到测试失败:
The question now is: what is the best Normal Distribution fitting the sample?现在的问题是:拟合样本的最佳正态分布是什么? Thanks to
NormalFactory()
the answer is simple:感谢
NormalFactory()
答案很简单:
BestNormalDistribution = ot.NormalFactory().build(sample)
If you print(BestNormalDistribution)
you get the parameters of this distribution: Normal(mu = 2.76832, sigma = 2.27773)如果你
print(BestNormalDistribution)
你会得到这个分布的参数: Normal(mu = 2.76832, sigma = 2.27773)
If we repeat the QQ_plot test of sample
against BestNormalDistribution
it would be much better如果我们针对
BestNormalDistribution
重复sample
的 QQ_plot 测试会好得多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.