简体   繁体   中英

QQ-plot python mean and standard deviation

I am trying to plot a QQ plot using python. I was checking scipy.stats.probplot, and the input seems to be the measurement against a normal distributiom.

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. For example : N(0, 1) a normal distribution whose mean = 0 and sigma = 1

In OpenTURNS, it goes like that:

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) .

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:

BestNormalDistribution = ot.NormalFactory().build(sample)

If you print(BestNormalDistribution) you get the parameters of this distribution: Normal(mu = 2.76832, sigma = 2.27773)

If we repeat the QQ_plot test of sample against BestNormalDistribution it would be much better在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM