贝叶斯统计与简单的数据集,1模型

时间:2017-08-02 02:02:04

标签: python bayesian pymc3

我对python和贝叶斯统计数据很新。 Web上的大多数介绍示例都通过switchpoints或多个参数进行工作。对于我的数据,我只想绘制95%HPD并确定平均值。我想将频率与贝叶斯统计数据与简单数据和简单模型进行比较。

我想我的问题是,我是否正确建模了?

在histrogram中绘制数据

import pandas as pd
import pymc3 as pm

data = np.array([0.170717, 0.174359, 0.172085, 0.171650, 0.171511, 0.175207,
                         0.174769, 0.174633, 0.174814, 0.174655, 0.199607,     0.198277,
                         0.199973, 0.142929, 0.143697, 0.143240, 0.143503, 0.144641,
                         0.143488, 0.145386, 0.143688, 0.144603, 0.144529, 0.191608,
                         0.192063, 0.192355, 0.193154, 0.156040, 0.158525, 0.155890,
                         0.156021, 0.155429, 0.157540, 0.156556, 0.158478, 0.161370,
                         0.161220, 0.167436, 0.161289, 0.162017, 0.167989, 0.170717,
                         0.174359, 0.172085, 0.171650, 0.171511, 0.175207])

df = pd.DataFrame(data)
df.plot(kind='hist')
plt.title("Histogram")
plt.xlabel("Value")
[histogram][1]

## Modeling the prior as Normal Distribution

with pm.Model():
    mu = pm.Normal('mu', 0, 1) #prior 
    sigma = .01

    returns = pm.Normal('returns', mu=mu, sd=sigma, observed=data) #likelihood 

    step = pm.NUTS()
    trace = pm.sample(10000, step, tune=500)
## Plotting trace
pm.traceplot(trace)
pm.summary(trace)

pm.plots.plot_posterior(trace)
[posterior][3]


  [1]: https://i.stack.imgur.com/ZTgfy.png
  [3]: https://i.stack.imgur.com/LEKem.png

0 个答案:

没有答案