# Group Analysis: Visual/Motor Activation

This tutorial covers group analysis via batch scripting and various AFNI functions: sswarper2 (for converting data to standard space), afniproc.py (for individual subject preprocessing), and gen\_group\_command.py (for group-level statistics with 3dttest++ or 3dMEMA).

## Workflow Overview

<figure><img src="/files/8pPMUBMvqmK7yLjTZ9eu" alt="Flow chart depicting the first and second level analysis steps. First Level: MRI data is collected and then downloaded and organized using xnat2bids. Task/timing data is collected and converted to BIDS tsv files, then converted to AFNI 1D files. fMRI data is then warped to standard space using sswarper2. All MRI data and stimulus timing files are input into afniproc.py for preprocessing. Second Level: The output from afniproc is passed to 3dMEMA for statistical analysis. Then, group masks and average smoothness are calculated. Finally, 3dClustSim and 3dClusterize are used to create estimate maps."><figcaption></figcaption></figure>

The basic flow of this pipeline is as follows:

**First-Level Analysis:**

1. Download data from XNAT and automatically convert it to BIDS format using xnat2bids
2. Convert psychopy timing files to be used by AFNI
3. Prepare fMRI data for preprocessing by warping to standard space (using sswarper2)
4. Use afni\_proc.py to create a preprocessing stream and run the general linear model per subject

**Second-Level Analysis:**

1. Use gen\_group\_command.py to build and run your statistical tests
2. Compute a group intersection mask
3. Calculate the average smoothness across participants
4. Use 3dClustSim to simulate noise and determines what cluster sizes are needed to control false positives
5. Use 3dClusterize to apply the thresholds to your group-level statistical maps from 3dMEMA. It outputs final significant clusters and effect estimate maps


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ccv.brown.edu/bnc-user-manual/analysis-pipelines/task-based-fmri-analysis-using-afni/group-analysis-visual-motor-activation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
