Skip to main content

Do likelihood based parameter estimation using maximum likeihood and bayesian methods

Project description

docs/badges/tests-badge.svg docs/badges/coverage-badge.svg

dataprob was designed to allow experimentalists to fit parameters from arbitrary models to experimental data.

  • ease of use: Users write a python function that describes their model, then load in their experimental data as a dataframe. A full analysis can be run with two python commands.

  • dataframe centric: Users use a dataframe to specify parameter bounds, guesses, fixedness, and priors. Observed data can be passed in as a dataframe or numpy vector. All outputs are simple pandas dataframes.

  • consistent experience: Users can run maximum-likelihood, bootstrap resampling, or Bayesian MCMC analyses with an identical interface and nearly identical diagnostic outputs.

  • interpretable: Provides simple diagnostic plots and runs tests assessing fit results, flagging problems with residuals and co-varying parameters.

Simple example

The following code generates noisy linear data and uses dataprob to find the maximum likelihood estimate of its slope and intercept.

import dataprob
import numpy as np

# Generate "experimental" linear data (slope = 5, intercept = 5.7) that has
# random noise on each point.
x_array = np.linspace(0,10,25)
noise = np.random.normal(loc=0,scale=0.5,size=x_array.shape)
y_obs = 5*x_array + 5.7 + noise

# 1. Define a linear model
def linear_model(m=1,b=1,x=[]):
    return m*x + b

# 2. Set up the analysis. 'method' can be "ml", "mcmc", or "bootstrap"
f = dataprob.setup(linear_model,
                   method="ml",
                   non_fit_kwargs={"x":x_array})

# 3. Fit the parameters of linear_model model to y_obs, assuming uncertainty
#    of 0.5 on each observed point.
f.fit(y_obs=y_obs,
      y_std=0.5)

# 4. Access results
print(f.fit_df)
fig = dataprob.plot_summary(f)
fig = dataprob.plot_corner(f)

The f.fit_df dataframe will look something like:

index

name

estimate

std

low_95

high_95

prior_std

m

m

5.009

0.045

4.817

5.202

NaN

b

b

5.644

0.274

4.465

6.822

NaN

The plots will be:

docs/source/_static/simple-example_plot-summary.svg docs/source/_static/simple-example_plot-corner.svg

Installation

We recommend installing dataprob with pip:

pip install dataprob

To install from source and run tests:

git clone https://github.com/harmslab/dataprob.git
cd dataprob
pip install .

# to run test-suite
pytest --runslow

Examples

A good way to learn how to use the library is by working through examples. The following notebooks are included in the dataprob/examples/ directory. They are self-contained demonstrations in which dataprob is used to analyze various classes of experimental data. The links below launch each notebook in Google colab:

Documentation

Full documentation is on readthedocs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dataprob-0.9.0.tar.gz (44.4 kB view details)

Uploaded Source

Built Distribution

dataprob-0.9.0-py2.py3-none-any.whl (56.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dataprob-0.9.0.tar.gz.

File metadata

  • Download URL: dataprob-0.9.0.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for dataprob-0.9.0.tar.gz
Algorithm Hash digest
SHA256 cd0c719bb655ff2c5a9bdedd3dfbbb5a25c58ad68fe3e578be7ba9914b4ad118
MD5 a50f9bd7cddabe84a5e762c0e1cb3d7e
BLAKE2b-256 aceb86f2239be3865db8a5afc545fbcbbb933638fd776a2e90ccdb173de3f069

See more details on using hashes here.

File details

Details for the file dataprob-0.9.0-py2.py3-none-any.whl.

File metadata

  • Download URL: dataprob-0.9.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 56.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for dataprob-0.9.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 329f18495971548679bec2c2070aca096abf28c1d1663668f84c01f2178ca08d
MD5 64538f1aaa1316fd79a07678ef6ea0d0
BLAKE2b-256 d1053194688e4f3bf35b4d4f5d3f94171146e72e86b1a9ee460125c7e9836031

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page