Skip to main content

Streamlines the fitting of common Bayesian item response theory models using Stan

Project description

edstan for Python

A python module that simplifies the fitting of common Bayesian item response theory models using Stan. It is compatible with and extends the functionality of pystan.

Features

  • Streamlined interface to common Bayesian item response models using Stan
  • Models include: Rasch, two-parameter logistic, (generalized) rating scale, and (generalized) partial credit
  • Posterior summaries tailored to item response models

Installation

edstan depends on the successful installation of pystan, so please see the pystan installation guide. Note that compatibility with Windows OS may be limited.

edstan may subsequently be installed with pip:

pip install edstan

Quickstart

Here is an example of running a model using data from a response matrix:

from edstan import EdStanModel
import numpy as np
import pandas as pd

# Simulate a "wide format" data frame of item responses for
# 5 items and 100 persons. Responses are scored 0 or 1.
rng = np.random.default_rng(seed=42)
data = pd.DataFrame(rng.binomial(1, p=.5, size=(100, 5)))
data.columns = [f"Question {i}" for i in range(5)]
data.index = [f"Respondent {i}" for i in range(100)]

# Instantiate the model, selecting the Rasch model
model = EdStanModel("rasch")

# Sample from the model by MCMC
fit = model.sample_from_wide(data)

# View a posterior summary of the item (and person distribution)
# parameters
print(fit.item_summary())

# View a posterior summary of the person parameters
print(fit.person_summary())

Alternatively, this is an example of using long format data:

from edstan import EdStanModel
import numpy as np
import pandas as pd

# Simulate a "long format" data frame of item responses for
# 5 items and 100 persons. Responses are scored 0, 1, or 2.
rng = np.random.default_rng(seed=42)
data = pd.DataFrame(
  {
     "person": [f"Person {j}" for j in range(100) for i in range(5)],
     "item": [f"Item {i}" for j in range(100) for i in range(5)],
     "response": rng.binomial(2, p=.5, size=5*100),
  }
)

# Instantiate the model, choosing the generalized partial
# credit model
model = EdStanModel("gpcm")

# Sample from the model by MCMC
fit = model.sample_from_long(
  ii=data['item'],
  jj=data['person'],
  y=data['response'],
)

# View a posterior summary of the item (and person distribution)
# parameters
print(fit.item_summary())

# View a posterior summary of the person parameters
print(fit.person_summary())

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

edstan-0.2.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edstan-0.2.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file edstan-0.2.0.tar.gz.

File metadata

  • Download URL: edstan-0.2.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for edstan-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b148a38c325cf593570f357cbafd7a4409e129a51f121b02b3efc9e830e5505d
MD5 af1f24585a80da09b33f01e7ccb6aa8e
BLAKE2b-256 19dd3c4a053662cf9c2ffd900b4ac62a689a973951883d9bbf48cddad2705544

See more details on using hashes here.

File details

Details for the file edstan-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: edstan-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for edstan-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 711ff7d95627285e4ace345db78c34f3b721a9e92c1cb6d31b3bf23e63c184e8
MD5 1f43ce252ff428ca4ca9e4ba5c203f7f
BLAKE2b-256 9fc09bf10ab22f26112709e3aad61706f2a02fb8cb09c10e9d72d55ef969c13f

See more details on using hashes here.

Supported by

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