Code Monkey home page Code Monkey logo

bunny's Introduction

Bunny

About

Bunny is a monte carlo power analysis (MCPA) package for python. Bunny takes a theory of how you think humans will behave (called a Participant) and the analysis you plan to apply to your data (called a DataTest) and helps you understand your experiment by simulating the process of collecting and analyzing your data thousands of times. Bunny can help you determine your experiment's power, the sample size you need, or simply to understand how different tests affect your study.

Bunny is simple. Here is a complete working example showing how to calculate the power for a two-alternative forced choice task:

from Bunny import *
ChildModel = Participant(Behaviors.BernoulliAgent(0.8))
MyTest = DataTest(Tests.BinomialTest())
MyExperiment = Experiment(ChildModel, MyTest)
Hop(MyExperiment)

Usage

Bunny's main objects are Experiments, a combination of a formal theory of how you think participants will behave and a statistical procedure you plan to use on your data. If you use Bunny's libraries, you can build an Experiment in as little as three lines of code. Implementing your own is also simple. Once you have an experiment, Bunny can ...

Calculate its power, given the sample size

Inspect(Experiment)

Help you visualize the experiment's power

Imagine(Experiment)

Find the sample size you need given a power

Experiment.SetPower(0.95)
Hop(Experiment)

Or explore the relationship between sample size and power

Explore(Experiment)

Get started

To get started visit the wiki or look at the examples.

Installation

To install download the source code and on a terminal run

python setup.py install
pip uninstall Bunny

License

Bunny is available through an MIT license.

bunny's People

Contributors

julianje avatar maxsiegel avatar

Stargazers

andy guess avatar Mel Day avatar Brian McMahan avatar Avery Pinko avatar TJ Mahr avatar Michael Frank avatar

Watchers

James Cloos avatar  avatar

bunny's Issues

Experiment.Replicate() check

Experiment.Replicate() should ensure it can actually run the simulation. Otherwise, the error gets repeated N times.

More sample-size searchers

Add sample size searchers through binary search that return a single sample size with the power the user sets

Add meta-analysis

Transfer meta-analysis hierarchical stuff to Bunny. Preferably as a new class. This will be the core part of Bunny.chomp()

TTest did something weird when connecting with empirical distribution

Test = Bunny.DataTest(Bunny.TestLibrary.TTest())

Experiment = Bunny.Experiment([Effort,NoEffort],Test,"Baby effort experiment")

Bunny.Explore(Experiment)
/Users/julianjara-ettinger/anaconda/lib/python2.7/site-packages/numpy/core/_methods.py:83: RuntimeWarning: Degrees of freedom <= 0 for slice
warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning)
/Users/julianjara-ettinger/anaconda/lib/python2.7/site-packages/numpy/core/_methods.py:117: RuntimeWarning: invalid value encountered in double_scalars
ret = ret.dtype.type(ret / rcount)
/Users/julianjara-ettinger/anaconda/lib/python2.7/site-packages/scipy/stats/stats.py:3107: RuntimeWarning: invalid value encountered in absolute
prob = distributions.t.sf(np.abs(t), df) * 2 # use np.abs to get upper tail
Exploring sample sizes ...
No limit specified. Testing samples between 15 and 35 ...
Estimating time ....
Traceback (most recent call last):
File "", line 1, in
File "Bunny/BunnyFunctions.py", line 14, in Explore
res = ExploreSampleSize(Exp)
File "Bunny/BunnyFunctions.py", line 148, in ExploreSampleSize
Power.append(Exp.GetPower(samples))
File "Bunny/Experiment.py", line 55, in GetPower
return sum(results)*1.0/len(results)
TypeError: unsupported operand type(s) for +: 'int' and 'list'

Improve validation

Have validation test run simulating the data and testing it and catch any errors it gets

Bunny.Hop bug when ensuring a null signal wont' give a false positive

Bunny.Hop uses binary search, which assumes that the power function p:SampleSize->[0,1] is increasing.

If you use a null model, the goal is to find a sample size where your test will only detect something less than (1-power)% of the time. So Hop won't work:

Bunny.Hop(Experiment,limit=100,power=0.05)
Power: 0.05
Limit: 100
Replications per proposal: 10000
Searching for your sample size...
Simulating with 50 participants per condition... Power=0.0577
Simulating with 25 participants per condition... Power=0.0631
Simulating with 13 participants per condition... Power=0.0812
Simulating with 7 participants per condition... Power=0.1178
Simulating with 4 participants per condition... Power=0.1809
Simulating with 2 participants per condition... Power=0.4001
Simulating with 1 participants per condition... Power=0.9058
[1, 0.9]

DataTest modify

If a datatest only works on one condition, it should run in parallel across all conditions of a behavior model.

Can't use openssl with anaconda

Openssl has problems finding the certificate in some anaconda installations:

WARNING: can't open config file: /opt/anaconda1anaconda2anaconda3/ssl/openssl.cnf

This is a known issue (ContinuumIO/anaconda-issues#137) and not a Bunny problem, but I need to find some other way of pre-registering.

BinomialWithControl failed

BehaviorTestModel = Participant(ParticipantLibrary.BinomialAgent(0.75))
BehaviorControlModel = Participant(ParticipantLibrary.BinomialAgent(0.5))

The lest library comes with a test that does this:

Test = DataTest(TestLibrary.BinomialWithControl("OT"))

You will see a message letting you know that Bunny is assuming that the first condition is test and the second one is control.

MyExperiment = Experiment([BehaviorTestModel, BehaviorControlModel], Test, "2-AFC task")

Bunny.Save() bug

Bunny.Save(Experiment,"Test")
Traceback (most recent call last):
File "", line 1, in
File "Bunny/BunnyFunctions.py", line 93, in Save
pickle.dump(Exp,open(Filename, "wb"))
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 419, in save_reduce
save(state)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 663, in _batch_setitems
save(v)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 600, in save_list
self._batch_appends(iter(obj))
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 615, in _batch_appends
save(x)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 419, in save_reduce
save(state)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 663, in _batch_setitems
save(v)
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/julianjara-ettinger/anaconda/lib/python2.7/pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <function F at 0x1056c9050>: it's not found as Bunny.ParticipantLibrary.F

BinomialWithControl failed


AttributeError Traceback (most recent call last)
in ()
----> 1 Hop(MyExperiment)

/Users/julianjara-ettinger/anaconda/lib/python2.7/site-packages/Bunny-0.1.3-py2.7.egg/Bunny/BunnyFunctions.pyc in Hop(Exp, limit, power, samples, Verbose)
92 sys.stdout.flush()
93 Exp.SetSampleSize(current)
---> 94 p = Exp.GetPower(samples)
95 if Verbose:
96 sys.stdout.write("Power=" + str(p) + "\n")

/Users/julianjara-ettinger/anaconda/lib/python2.7/site-packages/Bunny-0.1.3-py2.7.egg/Bunny/Experiment.pyc in GetPower(self, samples)
119 >> MyExperiment.UpdatePower()
120 """
--> 121 results = self.ExtractDecision(self.Replicate(samples))
122 return sum(results) * 1.0 / len(results)
123

/Users/julianjara-ettinger/anaconda/lib/python2.7/site-packages/Bunny-0.1.3-py2.7.egg/Bunny/Experiment.pyc in ExtractDecision(self, Data)
136 power (bool): Indicator about whether simulation fulfilled DataTest's final criteria.
137 """
--> 138 return [Data[i].aggregatedecision for i in range(len(Data))]
139
140 def Replicate(self, N=1000):

AttributeError: 'NoneType' object has no attribute 'aggregatedecision'

Analyze experiment object

Add Bunny.Inpsect(Experiment) as a supporting function to print an experiment's summary and power (to be used for preregistration)

Bigger changes for next version

What if bunny stat and participant libraries included a potential intuitive description of the test. The preregistration method could then also describe the model with words, also useful for writing methods sections explaining the power analysis.

I'm starting to add way too much staff to stay tests. They should really be create an object of simulationsummary or something! Then they could also have a list of critical statistics of something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.