4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python と R の確率分布のmethod名と引数の扱いをいつも忘れる1か月後の自分へ

Posted at

この記事の目的

  • Python と R の分布関数の操作の対応について基本部分をまとめる
  • 年に3回くらい忘れる自分のための知識を誰かのために

summary という名の個人的感想

  • Python の method 名は直接的でわかりやすい
  • R は 分布パラメータの引数名が直感的だが、Python の a=, b=loc=, scale= の使い分けの指定は数式から変換する時に脳に負担がかかる。
  • どちらも慣れれば問題なし

Official Documents

主な methods

正規分布での例

事前準備 for Python: from scipy import stats

python r return value meanings
stats.norm.pdf(0) dnorm(x = 0) 0.3989423 y-axis height of distribution at x = 0; probability density function
stats.norm.ppf(0.99) qnorm(p = 0.99) 2.326348 x position that satisfy integral distribution from -Inf to x = 0.99; percent point function
stats.norm.cdf(2.326348) pnorm(q = 2.326348) 0.99 inverse of ppf; cumlative distribution function
stats.norm.rvs(size=5) rnorm(n = 5) 10 values make random variables

分布のパラメータについて

公式を読むべし
https://docs.scipy.org/doc/scipy/reference/tutorial/stats.html#shifting-and-scaling

pythonは全distributionで以下が共通

  • loc: 分布の平行移動
  • scale: 倍率
# python
>>> stats.norm.rvs(size=5, loc=100, scale=10)
array([ 87.94461629, 101.62097735, 114.57610849, 109.68581233,
        92.61449913])
# R
rnorm(5, mean=100, sd=10)
# [1]  88.97331 116.73641  87.71554  97.24457  95.40161

以上

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?