2

我使用以下方法估计了一个模型pystan

import pystan

stan_model = pystan.StanModel('stan_codes/stan_code_1.stan')
samples = stan_model.sampling(data = sdata, iter = 10, chains = 1, seed = 42)
model_results = {'mdata' : model_data, 'sdata': sdata, 'samples' : samples, 'model': stan_model}

后来我想将“东西”从格式中提取samples出来dataframe。我在用

mdata, sdata, samples, model = [x for x in model_results.values()]
samples.extract().to_dataframe()

但我收到一个错误:

 AttributeError: 'collections.OrderedDict' object has no attribute 'to_dataframe'

根据文档samples.extract()应该有一个属性to_dataframe(),对吧?我在这里做错了吗?我在用pystan version 2.18.0.0

4

1 回答 1

1

您是否尝试过直接从 fit 对象提取到 DataFrame

就像是 ...

stan_model = pystan.StanModel('stan_codes/stan_code_1.stan')
samples = stan_model.sampling(data = sdata, iter = 10, chains = 1, seed = 42)
chains = samples.to_dataframe('parameter name')
于 2018-10-12T23:16:39.787 回答