Hi everyone,

I’m completely new to nilearn, and I have been attempting to create a quick function that pulls within-network connectivity from ROI’s I’ve specified. I just wanted to make sure I understand what I’m doing and was hoping for some feedback. Thanks so much in advance!

```
# extract data from specified labels (label_file):
masker = NiftiLabelsMasker(labels_img = label_file, standardize = 'zscore_sample', \
verbose = 1, memory = "nilearn_cache", memory_level = 2)
# fit the timeseries for the subject (subject_file), specify regressors (regressor_file)
time_series = masker.fit_transform(subject_file, confounds=regressor_file)
# create correlation matrix, AKA, each ROI's correlation to all the other ROI's in the network
from nilearn.connectome import ConnectivityMeasure
correlation_measure = ConnectivityMeasure(kind='correlation')
correlation_matrix = correlation_measure.fit_transform([time_series])[0]
np.fill_diagonal(correlation_matrix, 0)
# compute mean correlation strength between all regions in the same network
means = []
for row in correlation_matrix:
correlation_mean = np.mean(row)
means.append(correlation_mean)
within_network_connectivity = np.mean(means)
```

Please let me know if this seems right! I am following the documentation and a couple of method sections from papers who use nilearn. I would appreciate all the feedback you can give. Thank you

- Matt