LoginSignup
23
23

More than 5 years have passed since last update.

さまざま分布のQQプロットを描画してみる

Posted at

https://qiita.com/kenmatsu4/items/59605dc745707e8701e0
http://www.ie-kau.net/entry/2016/03/10/%E6%AD%A3%E8%A6%8F%E5%88%86%E5%B8%83%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B%E3%82%92%E8%A6%8B%E6%A5%B5%E3%82%81%E3%82%8B3%E3%81%A4%E3%81%AE%E3%82%B9%E3%83%86%E3%83%83%E3%83%97%EF%BC%88Python%EF%BC%89

上記のURLにも載っていますが、いくつか載せてみます。

import numpy as np 
import scipy.stats as stats
import matplotlib.pyplot as plt

def qqplot(dist):
    plt.hist(dist, bins=30)
    plt.show()
    stats.probplot(dist, dist="norm", plot=plt)
    plt.show()

# 正規分布
qqplot(np.random.randn(10000))

image.png
image.png

# 一様分布
qqplot(np.random.rand(10000))

image.png
image.png

# 混合ガウス分布1
dist = [np.random.normal(-3,1) if np.random.randint(2) else np.random.normal(3,1) for _ in range(10000)]
qqplot(dist)

image.png
image.png

# 混合ガウス分布2
dist = [np.random.normal(-5,1) if np.random.randint(3) 
   else np.random.normal(3,5) for _ in range(10000)]
qqplot(dist)

image.png
image.png

# Beta分布
qqplot(np.random.beta(0.5,0.5,10000))

image.png
image.png

#t分布
qqplot(stats.t.rvs(5, size=100000))

image.png
image.png

# 対数正規分布
qqplot(np.exp(np.random.normal(100,0.5,10000)))

image.png
image.png

裾の重いt分布のプロットが面白いですね。

23
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
23