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. tf_example_path() gives the path of each
example, and tf_example_names() lists them. Running the
checklist on the theory 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.
weak <- tf_read(tf_example_path("weak-theory.theory.yaml"))
report <- tf_check(weak)
report$aggregate_score[1] 2.2
report$aggregate_range[1] 1.1 3.9
report$gate[1] "blocked"
open_items <- Filter(function(item) item$status != "pass", report$items)
data.frame(
item = vapply(open_items, function(item) item$id, character(1)),
status = vapply(open_items, function(item) item$status, character(1)),
if_failed = vapply(open_items, function(item) item$severity_if_fail, character(1))
) item status if_failed
1 falsifiability fail blocker
2 precision warn warning
3 risk_severity warn warning
4 parsimony n/a warning
5 non_redundancy warn warning
6 construct_clarity warn warning
7 scope warn warning
8 logical_why warn warning
9 causal_testability warn warning
10 diagnosticity warn warning
11 formalisation warn warning
12 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
view of tf_diagram() 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.
Reading and validating a theory
The rest of this vignette reads a theory of modality switching in grounded conceptual processing. Five constructs are linked by four causal propositions. Sensorimotor experience with a concept drives the activation of a modality-specific perceptual system, and that activation both raises the cost of switching modality between consecutive trials and eases conceptual access, which familiarity with the word form eases as well.
theory <- tf_read(tf_example_path("modality-switching.theory.yaml"))tf_validate() returns TRUE invisibly when
the theory is valid and otherwise stops with a message that lists every
problem. With the default full = FALSE, it checks the
structure: the required fields, the allowed values of each enumerated
field, that every top-level field is one the schema defines and that
each collection is a list. full = TRUE adds the referential
checks, that ids are unique and that every reference between constructs,
propositions, predictions, alternatives, assumptions, evidence and test
outcomes names a declared id, and then checks the type of every other
field, the form of each claim and whether the bounds of each prediction
fit its type. The calls below wrap it in isTRUE() to show
the result.
isTRUE(tf_validate(theory))[1] TRUE
isTRUE(tf_validate(theory, full = TRUE))[1] TRUE
A prediction that cites a proposition the theory never declares
passes the structural check, since every required field is present, and
only the full pass reports it. The message counts entries from 0, so
prediction[0] is the first prediction.
broken <- theory
broken$predictions[[1]]$derives_from <- list("p_missing")
isTRUE(tf_validate(broken))[1] TRUE
tf_validate(broken, full = TRUE)Error:
! invalid theory object: prediction[0] derives_from 'p_missing' is not a known proposition
Identifying a theory by its content
tf_content_hash() returns the SHA-256 digest of the
theory’s content written in a canonical form. Two files that hold the
same theory have the same hash, whatever their layout, comments, key
order or format, and any change to a value changes it. The
preregistration and the dossier both print it, so a reader can check
that the theory file in hand is the one a document describes. The Python
package’s content_hash() gives the same digest.
tf_content_hash(theory)[1] "sha256:c8109f9b8b7ca5df9c28ea0b42d799a4e9e608cad9cb0641e6030f9cd7bbb630"
A theory can record its own hash under
version$content_hash, which the hash leaves out of the
content it digests. The full validation then compares the recorded hash
with the content, so an edit made after the hash was recorded is
reported.
recorded <- theory
recorded$version$content_hash <- tf_content_hash(recorded)
isTRUE(tf_validate(recorded, full = TRUE))[1] TRUE
recorded$constructs[[1]]$definition <- paste(
recorded$constructs[[1]]$definition, "Edited after registration."
)
tf_validate(recorded, full = TRUE)Error:
! invalid theory object: version content_hash does not match the theory's content
The checklist
tf_check() scores the theory against the checklist the
package ships, version 3.1, whose twelve items each test one criterion
drawn from the methodology literature. Each item has the status
"pass", "warn", "fail" or
"n/a", the last for an item with nothing to assess, such as
the parsimony of a theory that adds no assumption to answer an anomaly.
An "n/a" item has a NULL score.
report <- tf_check(theory)
report$checklist_version[1] "3.1"
report$aggregate_score[1] 87.1
report$aggregate_range[1] 83.5 89.2
report$coverage[1] 0.92
report$gate[1] "pass"
data.frame(
item = vapply(report$items, function(item) item$id, character(1)),
status = vapply(report$items, function(item) item$status, character(1)),
score = vapply(report$items, function(item) {
if (is.null(item$score)) NA_real_ else item$score
}, numeric(1))
) item status score
1 falsifiability pass 1.000
2 precision pass 0.500
3 risk_severity pass 0.613
4 parsimony n/a NA
5 non_redundancy pass 1.000
6 construct_clarity pass 1.000
7 scope pass 1.000
8 logical_why pass 1.000
9 causal_testability pass 1.000
10 diagnosticity pass 0.500
11 formalisation pass 1.000
12 derivation_chain pass 1.000
The checklist score, aggregate_score, is the weighted
mean of the applicable items’ scores, on a scale of 0 to 100, and the
coverage is the share of the checklist’s weight that applied. The
weights are a convention, so aggregate_range gives the
lowest and the highest score over the checklist’s weights, equal weights
and each applicable item’s weight halved and then doubled with the
others unchanged. The range is the extremes of these weightings and not
an interval for the score, and the choices made in coding the file and
the constants of the claim-form rubric lie outside it. A score whose
range is wide depends on the convention more than one whose range is
narrow. The score is compensatory, since a high score on one item
offsets a low score on another. The gate is not. It is
"blocked" when an item marked as a blocker fails,
"pass" otherwise, and "advisory" for a theory
whose maturity is draft. The derivation chain warns,
without blocking the gate, when a prediction’s or a phenomenon’s claim
names a construct on a feedback loop or downstream of one, which
tf_check() leaves unread by default, and
tf_check(theory, cycles = "sigma") reads such claims by
sigma-separation. The article Methodological
foundations sets out each item, its supporting literature and how
its score is computed.
tf_report() returns the same result as a string, in JSON
by default or as an HTML fragment for a web page with
format = "html".
Building a theory
A theory’s maturity field records its stage as
building, developing or testing,
or as draft, which makes the checklist’s gate advisory.
tf_theory() starts an empty theory, and the builders
tf_add_construct(), tf_add_proposition(),
tf_add_prediction(), tf_add_phenomenon(),
tf_add_alternative(), tf_add_assumption(),
tf_add_evidence(), tf_add_test_outcome() and
tf_set_formal_model() add to it. Each returns a modified
copy and records a step in the theory’s provenance log, so the steps
compose with the native pipe and the original object stays as it
was.
built <- tf_theory("panic-demo", "A demonstration theory of panic") |>
tf_add_construct("c_arousal", "Physiological arousal",
"Bodily activation in response to a stressor.",
measurement = "heart rate variability",
boundary_conditions = "awake adults") |>
tf_add_construct("c_threat", "Perceived threat",
"Appraised danger of bodily sensations.",
measurement = "self-report appraisal scale",
boundary_conditions = "awake adults") |>
tf_add_proposition("p1", "c_arousal", "c_threat", "increases",
mechanism = "Activation raises the salience of threat cues.") |>
tf_add_prediction("h1", "Arousal raises threat appraisal.", "directional",
derives_from = "p1",
claim = list(kind = "effect", x = "c_arousal",
y = "c_threat", sign = "positive"))
isTRUE(tf_validate(built, full = TRUE))[1] TRUE
step action detail
1 1 tf_theory panic-demo
2 2 tf_add_construct c_arousal
3 3 tf_add_construct c_threat
4 4 tf_add_proposition p1
5 5 tf_add_prediction h1
The type of a prediction names the form of its claim. An
existence prediction asserts that an effect or relation
exists, without a direction, and a directional one asserts
a sign or an order. An interval prediction asserts that a
quantity lies in a stated range, and a point prediction
asserts one value, with the tolerance that measurement requires.
bounds states the region, and the full validation checks
that it fits the type, so an existence prediction takes none. A
claim states the prediction in a form the causal reading
can check against the propositions, as the article Developing
and testing a theory shows.
How a theory is encoded decides what the package derives from it. A
moderates proposition states that its from
modifies the effect of other causes on its to, and the
causal graph reads it as an edge without a sign from the moderator to
the outcome. The relation it modifies keeps its sign, but every effect
of the moderator on that outcome is left open, including a main effect
the theory also states, even when that main effect is encoded as a
signed proposition of its own, since an edge has a sign only when every
proposition that states it gives it one. A theory whose main effect
matters can record the interaction in the functional_form
of the proposition it modifies, or in a prediction’s statement, at the
cost of a graph that does not show it. Whether a relation that a
proposition states is also entered as a prediction is the encoder’s
choice too, and it changes the hypotheses that the preregistration
lists.
tf_add_alternative() registers a rival account, which
can state propositions of its own over the theory’s constructs. A
prediction that names the rival in diagnostic_vs declares
that it discriminates between the two, and the checklist checks that
declaration against the rival’s propositions.
built <- built |>
tf_add_alternative(
"alt_reverse", "Threat drives arousal",
propositions = list(list(id = "r1", from = "c_threat", to = "c_arousal",
relation = "increases"))
)
length(built$alternatives[[1]]$propositions)[1] 1
tf_write() saves a theory as JSON when the path ends in
.json and as YAML otherwise. The file reads back as the
same theory, with the same content hash, in R and in Python.
path <- tempfile(fileext = ".json")
tf_write(built, path)
identical(tf_content_hash(tf_read(path)), tf_content_hash(built))[1] TRUE
Starting from a DAGitty diagram
Many causal theories are first drawn as a diagram in DAGitty (Textor et al., 2016).
tf_read_dagitty() reads its model code and returns a theory
with one construct for each variable and one proposition for each edge.
An arrow becomes causes, or increases or
decreases when relation says so, and
<-> becomes associates. The theory has
the maturity draft, and it is not valid until every
construct has a definition, which a diagram cannot supply.
FAIR theory specifies a theory as a findable, accessible, interoperable and reusable digital object in a public archive (Van Lissa et al., 2026). Its worked example of self-determination theory, in the theorytools package (Van Lissa, 2025), keeps the diagram in a DAGitty file and the construct definitions in a CSV table beside it. The example below imports the modality-switching graph in that form. The two files are written out as text so that the code runs as shown, and in practice each would be read from its file.
dagitty_file <- "dag {
sensorimotor_experience -> modality_activation
modality_activation -> switch_cost
modality_activation -> conceptual_access
lexical_familiarity -> conceptual_access
}"
definitions <- read.csv(text = "Concept,Synonym,Definition,Operationalization
Sensorimotor experience,,Perceptual and motor engagement with the referent of a concept.,Perceptual strength ratings
Modality activation,,Recruitment of one modality's perceptual system while a word is understood.,Interference from a concurrent load
Switch cost,,The extra time taken when consecutive trials address different modalities.,Switch-minus-repeat response time
Conceptual access,,The speed with which the meaning of a word becomes available.,Semantic categorisation latency",
stringsAsFactors = FALSE)
imported <- tf_read_dagitty(
dagitty_file,
id = "modality-switching-fair",
title = "Modality switching in grounded conceptual processing",
relation = "increases"
)
key <- gsub(" ", "_", tolower(trimws(definitions$Concept)))
for (i in seq_along(imported$constructs)) {
row <- match(imported$constructs[[i]]$id, key)
if (!is.na(row)) {
imported$constructs[[i]]$label <- trimws(definitions$Concept[row])
imported$constructs[[i]]$definition <- trimws(definitions$Definition[row])
}
}
ids <- vapply(imported$constructs, function(c) c$id, character(1))
defined <- vapply(imported$constructs, function(c) nzchar(c$definition), logical(1))
ids[!defined][1] "lexical_familiarity"
The table names its concepts in words, and the diagram in
identifiers, so each concept is matched to a construct by its name
lower-cased with spaces replaced by underscores. One construct, lexical
familiarity, has no row in the table and is listed above. The
operationalisation column is left out, because it describes measures in
prose, whereas a construct’s measurement lists indicator
names that the lavaan syntax uses as columns of the data. The merge
edits the theory’s fields directly, so the provenance log records the
import and not the definitions.
With the missing definition added, the theory validates in full. Its
gate is advisory, since its maturity is draft, and the
checklist reports what the diagram could not supply: a prediction that
forbids some result, measures, scope conditions and mechanisms.
imported$constructs[[match("lexical_familiarity", ids)]]$definition <-
"How well established the form of a word is for a reader."
isTRUE(tf_validate(imported, full = TRUE))[1] TRUE
imported_report <- tf_check(imported)
imported_report$gate[1] "advisory"
Filter(function(item) item$status != "pass", imported_report$items) |>
vapply(function(item) paste(item$id, item$status), character(1)) [1] "falsifiability fail" "precision warn" "risk_severity warn"
[4] "parsimony n/a" "construct_clarity warn" "scope warn"
[7] "logical_why warn" "diagnosticity warn" "formalisation warn"
[10] "derivation_chain n/a"
The graph alone already commits the imported theory to the
conditional independencies and the untestable causal directions that the
article Developing
and testing a theory derives for the full modality-switching theory,
since the two share a graph. The causal_dag view of
tf_diagram() writes a theory back in DAGitty’s syntax,
keeping its directed edges, its associations and any variable marked as
latent.
Screening constructs for redundancy
tf_redundancy_check() compares the definitions of every
pair of constructs by the words they share, through the Jaccard
similarity and the overlap coefficient, and returns the pairs sorted by
descending similarity. A pair is flagged "review" when its
definitions are near duplicates or one is contained in the other, which
suggests that two names cover one construct. It also flags two
constructs that carry one label, and a pair in which every measure
listed for one construct is also listed for the other, since data from
those measures cannot tell the two apart. The reason column
names the grounds of each flag. The comparison of definitions is
lexical, so a definition reworded into other words passes it.
head(tf_redundancy_check(theory), 3) a b similarity overlap flag reason
1 c_modality_activation c_switch_cost 0.150 0.273 ok
2 c_conceptual_access c_lexical_familiarity 0.053 0.111 ok
3 c_modality_activation c_conceptual_access 0.053 0.111 ok
tf_embedding_redundancy() compares the definitions by
the cosine similarity of vectors from an embedder that the caller
supplies, such as a language model. Here, a toy bag-of-words embedder
stands in for one.
vocab <- c("bodily", "activation", "appraised", "danger", "salience")
embedder <- function(definition) {
words <- strsplit(tolower(definition), "[^a-z]+")[[1]]
vapply(vocab, function(w) sum(words == w), numeric(1))
}
tf_embedding_redundancy(built, embedder) a b cosine flag
1 c_arousal c_threat 0.408248 ok
Drawing the theory
tf_diagram() returns one of ten views of the theory. The
graph views are Graphviz DOT, which any Graphviz tool renders. The
nomological network draws each proposition as an edge labelled with its
id and relation.
cat(tf_diagram(theory, type = "nomological_net"))digraph nomological_net {
graph [rankdir=LR, bgcolor="transparent", fontname="Helvetica", fontsize=11, pad="0.2", nodesep="0.3", ranksep="0.45"];
node [fontname="Helvetica", fontsize=11, shape=box, style="rounded,filled", color="#33567A", fillcolor="#F2F6F9", fontcolor="#12283A", penwidth=1.1, margin="0.16,0.1"];
edge [fontname="Helvetica", fontsize=10, color="#7B909F", fontcolor="#0F6E6E", arrowsize=0.7];
"c_sensorimotor_experience" [label="Sensorimotor\nexperience with a\nconcept", fillcolor="#E4F1F1", color="#1E7B7B"];
"c_modality_activation" [label="Modality-specific\nperceptual\nactivation", fillcolor="#E4F1F1", color="#1E7B7B"];
"c_switch_cost" [label="Cost of switching\nmodality between\nconsecutive trials", fillcolor="#E4F1F1", color="#1E7B7B"];
"c_conceptual_access" [label="Ease of conceptual\naccess", fillcolor="#E4F1F1", color="#1E7B7B"];
"c_lexical_familiarity" [label="Lexical\nfamiliarity with\nthe word form", fillcolor="#E4F1F1", color="#1E7B7B"];
"c_sensorimotor_experience" -> "c_modality_activation" [label="p1: increases"];
"c_modality_activation" -> "c_switch_cost" [label="p2: increases"];
"c_modality_activation" -> "c_conceptual_access" [label="p3: increases"];
"c_lexical_familiarity" -> "c_conceptual_access" [label="p4: increases"];
}
tf_render_diagram() returns the DOT as a DiagrammeR
widget for the viewer and for R Markdown, or as an SVG string with
as = "svg". The packages it uses are optional and listed in
Suggests. The figure below is drawn from the DOT above.
cat(
'<div class="tf-figure tf-diagram">',
tf_render_diagram(theory, "nomological_net", as = "svg"),
'</div>',
sep = ""
)The causal_dag view writes the directed relations and
the associations in DAGitty’s syntax, for dagitty.net and the dagitty package, and
tf_render_diagram() does not draw it.
cat(tf_diagram(theory, type = "causal_dag"))dag {
c_sensorimotor_experience -> c_modality_activation
c_modality_activation -> c_switch_cost
c_modality_activation -> c_conceptual_access
c_lexical_familiarity -> c_conceptual_access
}
Next steps
The article Developing and testing a theory appraises an amendment and derives what a theory’s causal graph commits it to, from its implied independencies to the results that would tell it from a rival, and then preregisters it, grades its tests and assembles the dossier. Mapping the literature maps a corpus of publications against a theory, and Browser apps describes the two apps that run the packages without an installation.
Two languages, one specification
A Python package of the same name implements the same specification,
with the same function names without the tf_ prefix, apart
from new_theory() for tf_theory(). The
deterministic functions, from validation and the checklist to the causal
reading, the preregistration and the dossier, are checked against shared
expected outputs, so the two languages give the same results. The
helpers that depend on a network service, an embedder or a renderer
(tf_fetch_corpus(), tf_osf_push(),
tf_embedding_redundancy() and
tf_render_diagram()) can differ between them.