posterior_pred_check()

118 views
Skip to first unread message

DunovanK

unread,
Sep 18, 2012, 8:56:40 PM9/18/12
to hddm-...@googlegroups.com
Hello all,

In the new How To page there is a section explaining the use of posterior_pred_check().  I have tried implementing this tool:

post_pred_check(model, samples=50, bins=100, stats={'mean': np.mean, 'median': np.median}, evals=None, plot=False, progress_bar=False)

When the script reaches this line the terminal displays "Sampling..." and eventually returns to the prompt without returning the results dictionary.  Any idea why this isn't yielding any output?

Best,

Kyle

Thomas Wiecki

unread,
Sep 19, 2012, 9:04:18 AM9/19/12
to hddm-...@googlegroups.com
That is odd. The same line returns me the expected result.

I don't think this will solve your problem but in hddm there is already some standard statistics for RT data included, so you could call:
hddm.utils.post_pred_check(model, progress_bar=False)

Does it take a little while or does it exit immediately?

Thomas
 

Best,

Kyle

DunovanK

unread,
Sep 19, 2012, 9:37:15 PM9/19/12
to hddm-...@googlegroups.com
Hi Thomas,

Sorry for the delayed response.  That resulted in the same issue.  It remains "Sampling..." for quite a long time and finally returns to the prompt. Here is my full script:  

#!/usr/bin/python

import hddm
from hddm.utils import post_pred_check
from kabuki.analyze import *
import pylab


# Load data from csv file into a NumPy structured array
data = hddm.load_csv('Group_AllPriors_SubEWMA.csv')

# Create a HDDM model multi object
model = hddm.HDDM(data, depends_on={'v':'object', 'z':'condition'}, include=('T'), bias=True, is_group_model=True)

# Create model and start MCMC sampling
model.sample(50000, burn=20000, thin=2)

# Print fitted parameters and other model statistics
model.print_stats()

# Plot posterior distributions and theoretical RT distributions
plot_posterior_nodes(nodes=[model.nodes_db.ix['z(90F)']['node'], model.nodes_db.ix['z(90H)']['node'], model.nodes_db.ix['z(70F)']['node'], model.nodes_db.ix['z(70H)']['node'], model.nodes_db.ix['z(neutral)']['node']], bins=50)

pylab.show()

model.plot_posteriors()

model.plot_posterior_predictive(savefig=True)

hddm.utils.post_pred_check(model, progress_bar=False)

#post_pred_check(model, samples=50, bins=100, stats={'mean': np.mean, 'median': np.median}, evals=None, plot=False, progress_bar=False)


Any other suggestions?
Thank you,
Kyle

Thomas Wiecki

unread,
Sep 20, 2012, 4:59:26 AM9/20/12
to hddm-...@googlegroups.com
Hi Kyle,

You just run that from the command line (e.g. python myscript.py)? In this case it looks like you are ignoring the output value and it gets discarded (this function doesn't plot automatically but just returns). Try adding a print before the statement.

Thomas

DunovanK

unread,
Sep 20, 2012, 2:25:08 PM9/20/12
to hddm-...@googlegroups.com
Hi Thomas,

Yes, I'm just running that script in the terminal.  I included the print and after sampling it returned

<class 'pandas.core.frame.DataFrame'>
MultiIndex: 1800 entries, ('wfpt(highF.face).1', 'std_ub') to ('wfpt(neutral.house).9', 'accuracy')
Data columns:
observed       1772  non-null values
credible       1800  non-null values
quantile       1772  non-null values
SEM            1772  non-null values
mahalanobis    1772  non-null values
mean           1800  non-null values
std            1800  non-null values
2.5q           1800  non-null values
25q            1800  non-null values
50q            1800  non-null values
75q            1800  non-null values
97.5q          1800  non-null values
NaN            1800  non-null values
dtypes: float64(13)

Would you recommend just entering each command in a python terminal instead of running a script?

Kyle

Thomas Wiecki

unread,
Sep 20, 2012, 2:44:43 PM9/20/12
to hddm-...@googlegroups.com
On Thu, Sep 20, 2012 at 2:25 PM, DunovanK <duno...@gmail.com> wrote:
> Hi Thomas,
>
> Yes, I'm just running that script in the terminal. I included the print and
> after sampling it returned
>
> <class 'pandas.core.frame.DataFrame'>
> MultiIndex: 1800 entries, ('wfpt(highF.face).1', 'std_ub') to
> ('wfpt(neutral.house).9', 'accuracy')
> Data columns:
> observed 1772 non-null values
> credible 1800 non-null values
> quantile 1772 non-null values
> SEM 1772 non-null values
> mahalanobis 1772 non-null values
> mean 1800 non-null values
> std 1800 non-null values
> 2.5q 1800 non-null values
> 25q 1800 non-null values
> 50q 1800 non-null values
> 75q 1800 non-null values
> 97.5q 1800 non-null values
> NaN 1800 non-null values
> dtypes: float64(13)
>
> Would you recommend just entering each command in a python terminal instead
> of running a script?

You would still get the same output (although IPython is very useful
in general).

This is the output if a pandas DataFrame (which is what we store the
results in) is too large. You can force it by calling .to_string() on
the dataframe. Or you can only output the variable you are interested
in, e.g. results['SEM']. For hacking on these kind of things I
definitely recommend IPython which has autocomplete and everything.

Thomas

DunovanK

unread,
Sep 20, 2012, 3:16:56 PM9/20/12
to hddm-...@googlegroups.com
Alright Thomas, I will try IPython.  

As always, thank you very much for your help.

Best,

Kyle
Reply all
Reply to author
Forward
0 new messages