Skip to content

Commit

Permalink
Merge pull request #854 from Shotgunosine/add1stlevelinterceptonlyerror
Browse files Browse the repository at this point in the history
ENH: Make intercept-only first level models throw a NotImplementedError
  • Loading branch information
effigies authored May 10, 2022
2 parents 993362b + da44817 commit 341d8d0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bids/modeling/statsmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ def __init__(self, level, name, transformations=None, model=None,
group_by.append(self.level)
self.group_by = group_by

# Check for intercept only run level model and throw an error
try:
if (self.level == 'run') and (self.model['x'] == [1]):
raise NotImplementedError("Run level intercept only models are not currently supported."
"If this is a feature you need, please leave a comment at"
"https://github.com/bids-standard/pybids/issues/852.")
except KeyError:
# We talked about X being required, I don't know if we want to throw an error over that requirement here
# though.
pass

def __repr__(self):
return f"<{self.__class__.__name__}[{self.level}] {self.name}>"

Expand Down
8 changes: 8 additions & 0 deletions bids/modeling/tests/test_statsmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,11 @@ def test_expand_wildcards():
assert expand_wildcards(
["non_steady_state*"], ["non_steady_state00", "non_steady_state01"]
) == ["non_steady_state00", "non_steady_state01"]


def test_interceptonly_runlevel_error():
layout_path = join(get_test_data_path(), "ds005")
layout = BIDSLayout(layout_path)
json_file = join(layout_path, "models", "ds-005_type-interceptonlyrunlevel_model.json")
with pytest.raises(NotImplementedError):
graph = BIDSStatsModelsGraph(layout, json_file)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"Name": "ds005_mixedgamblestask",
"Description": "An intercept only run level model to test that an error is correctly thrown.",
"BIDSModelVersion": "1.0.0",
"Input": {
"task": [
"mixedgamblestask"
]
},
"Nodes": [
{
"Level": "Run",
"Name": "Run",
"GroupBy": [
"run",
"subject"
],
"Transformations": {
"Transformer": "pybids-transforms-v1",
"Instructions": [
{
"Name": "Factor",
"Input": "trial_type"
}
]
},
"Model": {
"Type": "glm",
"X": [
1
],
"HRF": {
"Variables": [
"trial_type.parametric gain"
],
"Model": "DoubleGamma",
"Parameters": {
"PeakDelay": 3,
"PeakDispersion": 6,
"UndershootDelay": 10,
"UndershootDispersion": 12,
"PeakUndershootRatio": 0.2
}
}
},
"Contrasts": [
{
"Name": "run_parametric gain",
"ConditionList": [
"trial_type.parametric gain"
],
"Weights": [
1.0
],
"Test": "t"
}
]
}
]
}

0 comments on commit 341d8d0

Please sign in to comment.