theoryforge (Python)¶
Theories in the behavioural sciences often define their constructs too loosely to measure, state claims that no result could contradict and survive a failed test by adding an assumption that protects them. theoryforge holds a theory as a structured file of constructs, propositions, predictions, rival accounts and test outcomes, and computes what that file commits the theory to. It checks how completely the file states what a checklist of criteria drawn from the methodology literature asks for, derives the independencies and signed effects its causal graph implies, grades how risky each prediction is and how severely it has been tested, and appraises, by fixed rules that borrow Lakatos's terms, whether an amendment adds content or only shields the theory from an anomaly.
A worked result¶
The package includes a deliberately underspecified theory of motivation. Reading it and running the checklist gives its checklist score, the range of scores that equal weights or one weight halved or doubled would give, its gate and the items it does not pass.
import theoryforge as tf
weak = tf.read(tf.example_path("weak-theory.theory.yaml"))
report = weak.check()
print(report["aggregate_score"], report["aggregate_range"], report["gate"])
for item in report["items"]:
if item["status"] != "pass":
print(f'{item["id"]:<19} {item["status"]:<5} {item["severity_if_fail"]}')
2.2 [1.1, 3.9] blocked
falsifiability fail blocker
precision warn warning
risk_severity warn warning
parsimony n/a warning
non_redundancy warn warning
construct_clarity warn warning
scope warn warning
logical_why warn warning
causal_testability warn warning
diagnosticity warn warning
formalisation warn warning
derivation_chain fail blocker
The gate is blocked because two items that the checklist treats as blockers failed. The theory's one prediction, 'Motivated people exist', is typed as an existence claim, and the falsifiability item reads that label: no prediction is typed point, interval or directional. The prediction also cites no proposition from which it would follow. To unblock the gate, the author would state a prediction that rules out some result, such as a direction or a bounded range of an effect, type it accordingly and derive it from a proposition. The warnings name the remaining work. Motivation and Drive are defined in nearly the same words and would have to be merged or defined apart. Neither construct has a measure or a stated scope, and the one proposition is an association without a mechanism. The development roadmap draws the same list as an ordered worklist.
The checklist score describes how completely the file states what checklist 3.1 asks for. Most items read whether a field is filled in or how a prediction is labelled, and stated claims are checked against the causal graph. Test outcomes are read only by the parsimony item, the weights are conventions, and no study has established what difference between two scores is meaningful. The score does not show that the theory is true or well reasoned.
The checklist score is a mean of the item scores under conventional weights. The gate reports whether either blocking item failed: at least one prediction is typed point, interval or directional, and every prediction cites declared propositions whose graph entails any claim it states, with no stated phenomenon contradicted. The labels are the author's and are not checked against the statements. A passing gate does not show that the theory is true or well reasoned. A claim that names a construct on a feedback loop or downstream of one is left unread by default and not checked, and the derivation chain then warns without blocking the gate. Methodological foundations gives the rationale and the computation behind each item.
From building to testing¶
A theory's maturity field records its stage as building, developing or testing, or
as draft, which makes the checklist's gate advisory. At the building stage, the
builder methods assemble the theory and log each step. read_dagitty() starts a draft from
a causal diagram drawn in DAGitty. Validation checks the file against the schema and every
cross-reference, and the content hash identifies its content exactly.
At the developing stage, appraise_amendment() compares a revision with its prior version
and classifies it as progressive, degenerating or neutral, by fixed rules that borrow
Lakatos's terms. The verdict holds only if what the two files declare is true, and since the
appraisal reads no dates, the prior must be the version before the new predictions were
stated.
At the testing stage, the causal graph of the propositions is read for the conditional independencies it implies, the signs of the effects it entails, the directions no test of conditional independence can settle and the results that would tell it from a rival. The package then grades each prediction before and after the data, writes the theory and hypotheses sections of a preregistration and assembles a dossier for a reviewer.
Get started covers reading, validating and scoring a theory, and Workflow modes follows the three stages with a worked example of each function. The literature layer maps a corpus of publications and finds the themes that the theory and its rivals share words with.
Install¶
pip install theoryforge
A first look¶
The examples ship with the package, so these lines run straight after installation.
import theoryforge as tf
t = tf.read(tf.example_path("modality-switching.theory.yaml"))
t.validate(full=True) # the schema, every cross-reference and the recorded hash
t.check() # the checklist: checklist score, range, gate and items
t.implications() # the conditional independencies the causal graph implies
t.entailments() # whether the graph entails each claim the theory states
t.discriminate("alt_grounding_by_interaction") # where data could tell it from a rival
t.dossier() # the dossier for a reviewer, as Markdown
Browser apps¶
Two browser apps run the package in a web page, with a theory editor that needs no YAML. The Python app runs this package through Pyodide, and nothing leaves the browser.
Two languages, one specification¶
This is the Python twin of the R package of
the same name. Both implement one
specification, and
their deterministic functions, from validation and the checklist to the causal reading, the
preregistration and the dossier, are checked against shared expected outputs. The helpers
that depend on a network service, a user-supplied embedder or a renderer
(fetch_corpus(), osf_push(), embedding_redundancy() and render_diagram()) can give
different results in the two languages. The API reference lists the differences in
naming.
Author¶
theoryforge is written and maintained by Pablo Bernabeu and released under the MIT licence. If theoryforge contributes to published work, please cite it. Its citation gives the concept DOI https://doi.org/10.5281/zenodo.21229964, which resolves to the latest release archived on Zenodo.