code: def lag_correlation(time_series, lag):
      n_subjects = len(time_series)
      n_samples, n_features = time_series[0].shape
      lag_cor = np.zeros((n_subjects, n_features, n_features))
      for subject, serie in enumerate(time_series):
          for i in range(n_features):
              for j in range(n_features):
                  if lag == 0:
                      lag_cor[subject, i, j] = np.corrcoef(
                          serie[:, i], serie[:, j]
                      )[0, 1]
                  else:
                      lag_cor[subject, i, j] = np.corrcoef(
                          serie[lag:, i], serie[:-lag, j]
                      )[0, 1]
      return np.mean(lag_cor, axis=0)
  
imports: from nilearn import datasets
  from nilearn.connectome import ConnectivityMeasure
  from nilearn.maskers import MultiNiftiLabelsMasker
  from nilearn import plotting
  import numpy
  from nilearn.maskers import MultiNiftiMapsMasker
label_desc: Use image node_id 1 for calling a global function with example usage: lag_correlation(time_series, lag) and returns: np