poldracklab / fitlins

Fit Linear Models to BIDS Datasets
https://fitlins.readthedocs.io
Apache License 2.0
76 stars 32 forks source link

BSM: run level model for 1 run per subject #346

Closed adelavega closed 2 years ago

adelavega commented 2 years ago

Previously we had decided to use a 3 level model (run, subject, dataset), even when there was only 1 run per subject. This had the advantage of keeping outputs & models the same across datasets (i.e. all datasets would have run level models, not some run level and some starting w/ subject level).

However, now the groupby directive in v1 models fails if there is no run information, and you try to group by run:

e.g.:

{
  "Name": "featviz_merlin_any_faces_edited",
  "Input": {
    "Task": "MerlinMovie",
    "Subject": [
      "25",
      "20",
      "21",
      "22",
      "23",
      "24",
      "26",
      "27",
      "28",
      "29",
      "30",
      "31",
      "32",
      "33",
      "34",
      "35",
      "36",
      "19"
    ]
  },
  "Description": "dummy contrasts of a cleaned any_faces feature and speech feature from merlin",
  "BIDSModelVersion": 1,
  "Nodes": [
    {
      "Level": "run",
      "Model": {
        "X": [ "any_faces_edited", "speech_edited", 1 ]
      },
      "Contrasts": [
        {
          "Name": "speech_edited",
          "Type": "t",
          "Weights": [ 1 ],
          "ConditionList": [ "speech_edited" ],
          "Test": "t"
        },
        {
          "Name": "any_faces_edited",
          "Type": "t",
          "Weights": [ 1 ],
          "ConditionList": [ "any_faces_edited" ],
          "Test": "t"
        }
      ],
      "Name": "run",
      "GroupBy": [ "run", "subject" ],
      "Transformations": {
        "Transformer": "pybids-transforms-v1",
        "Instructions": [
          {
            "Name": "Convolve",
            "Input": [ "any_faces_edited", "speech_edited" ]
          }
        ]
      }
    },
    {
      "Level": "subject",
      "DummyContrasts": {
        "Test": "t"
      },
      "Name": "subject",
      "GroupBy": [ "subject", "contrast" ],
      "Model": {
        "X": [ 1 ],
        "Type": "Meta"
      }
    },
    {
      "Level": "dataset",
      "DummyContrasts": {
        "Test": "t"
      },
      "Name": "dataset",
      "GroupBy": [ "contrast", "group" ],
      "Model": {
        "X": [ 1 ]
      }
    }
  ]
}

Any idea what the proposed solution should be? The most obvious thing would be to suggest a 2 level model (and modify my conversion script accordingly), but I don't like how the model will change depending on the dataset.

effigies commented 2 years ago

I agree that we should handle this smoothly. Looks like PyBIDS needs to accept missing grouping variables, at least for run and session which can reasonably be absent while still having a clear meaning.

effigies commented 2 years ago

https://github.com/bids-standard/pybids/pull/822

effigies commented 2 years ago

Should be fixed in latest release.