Skip to main content

Authoring generalized linear mixed effects models from conceptual models

Project description

rTisanePy

Authoring generalized linear mixed effects models from conceptual models. Based on rTisane.

rTisanePy lets you:

  • Declare variables and specify causal and relational assumptions
  • Query for a statistical model from a conceptual model
  • Automatically identify confounders (following Cinelli, Forney & Pearl, 2022)
  • Infer random effects from nesting and repeated measures
  • Select candidate family/link functions based on DV type

Installation

pip install rtisanepy

For development:

pip install -e ".[dev]"

Requires Python 3.10+ and networkx.

Quick Start

from rtisanepy import (
    Unit, continuous, categories,
    causes, equals, increases,
    ConceptualModel,
)

# Declare variables
student = Unit("student", cardinality=100)
classroom = Unit("classroom", cardinality=10)
student = Unit("student", cardinality=100, nests_within=classroom)

tutoring = categories(unit=student, name="Tutoring", cardinality=2)
ses = categories(unit=student, name="SES", order=["lower", "middle", "upper"])
test_score = continuous(unit=student, name="TestScore")

# Build a conceptual model
cm = (
    ConceptualModel()
    .assume(causes(ses, test_score))
    .assume(causes(ses, tutoring))
    .hypothesize(causes(tutoring, test_score,
                        when=equals(tutoring, "in-person"),
                        then=increases(test_score)))
)

# Query for a statistical model
model = cm.query(iv=tutoring, dv=test_score)

print(model.formula())       # TestScore ~ Tutoring + SES + (1 | classroom)
print(model.family)           # Inverse Gaussian
print(model.main_effects)     # ['Tutoring', 'SES']
print(model.random_effects)   # [RandomIntercept(group=classroom)]

# Override family/link
model2 = model.with_family("Gaussian", link="identity")

API Overview

Variables

Constructor Description
Unit(name, cardinality, nests_within=None) Entity (participant, subject)
Participant(name, cardinality, nests_within=None) Alias for Unit
Time(name, order=None, cardinality=0) Time variable
continuous(unit, name, number_of_instances=1) Continuous measure
counts(unit, name, number_of_instances=1) Count measure
categories(unit, name, *, cardinality=None, order=None) Categorical measure (ordered if order given)

Relationships

Function Description
causes(cause, effect, *, when=None, then=None) Directed causal relationship
relates(lhs, rhs, *, when=None, then=None) Undirected (ambiguous) relationship
nests(base, group) Nesting relationship between units

Comparisons (for when/then annotations)

Function Description
equals(variable, value) Variable equals a value
not_equals(variable, value) Variable does not equal a value
increases(variable) Variable increases
decreases(variable) Variable decreases

ConceptualModel

cm = ConceptualModel()
cm.assume(relationship)        # Add assumed relationship (returns self)
cm.hypothesize(relationship)   # Add hypothesized relationship (returns self)
cm.interacts(*vars, dv=dv)     # Add interaction annotation (returns self)
cm.query(iv=iv, dv=dv)         # Infer a StatisticalModel

At least one hypothesized relationship connecting iv and dv is required to query.

StatisticalModel

Attribute / Method Description
.formula() R-style formula string
.main_effects List of main effect variable names
.interaction_effects List of interaction terms
.random_effects List of RandomIntercept / RandomSlope
.family Selected family function
.link Selected link function
.family_candidates All candidate family/link pairs
.summary() Machine-readable dict
.with_family(family, link=None) Copy with overridden family/link

Running Tests

python -m pytest tests/ -v

Citation

If you use rTisanePy in your research, please cite:

@software{rtisanepy,
  author = {Eunice Jun},
  title = {rTisanePy: A Python Tool for Authoring Statistical Models from Conceptual Models},
  url = {https://github.com/emjun/rTisanePy},
  year = {2026}
}

References

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

rtisanepy-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

rtisanepy-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file rtisanepy-0.1.0.tar.gz.

File metadata

  • Download URL: rtisanepy-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for rtisanepy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df8d193fe2dc04f91acc89d64ef84bbe7d588b8c472af582c6e72068b3b7d7b1
MD5 b54f9b493b64c5af5a97388a9eb91b48
BLAKE2b-256 3b904b559e515933adab8764346af6a5f8ce0f6bb406f0e2c0fe8fb75e54b968

See more details on using hashes here.

File details

Details for the file rtisanepy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rtisanepy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for rtisanepy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a90f92348f6b98df65d37bb931cb480138df51e10656d082195a15f3c81274e9
MD5 9350d28ef2df38fc6f9f71de71f78b89
BLAKE2b-256 9d86e83fe831a45b24c9bd51c7644de1e24a79bd51add68d39a2fd798029f9ff

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