# Neuroscience of *L*anguage *L*ab

at New York University

Several software packages are utilized for analyzing MEG data after it has been collected. The MEG Laboratory software MEG160 (Yokogawa Electric Corp., Eagle Technology Corp., Kanazawa Institute of Technology) is used for noise reduction and epoching. Minimum norm estimates are then computed using either BESA 5.1 (MEGIS Software GmbH, Gräfelfing, Germany) or MNE software developed at the Martinos Center for Biomedical Imaging; lab members use the official distribution of MNE as well as a Python distribution. FreeSurfer software, also developed at the Martinos Center, is used to create cortical reconstructions of subjects' structural MRI data, which is sometimes obtained from collaborating labs. These cortical surface reconstructions are used to constrain the minimum-norm estimates computed by MNE and BESA. Further statistical analysis on the minimum-norm solutions is conducted using R software (R Project for Statistical Computing).

## Matlab MEG Scripts

This is a collection of scripts that can be used to import MEG data from MEG160 (.sqd files) into Matlab. To import epoched data, run get_trialsz.m. The zipped collection also includes the *acqparam*, *chanhandle*, and *sqdhandle* classes. It is recommended that the entire collection be downloaded, as many scripts call upon additional scripts and classes found in the folder.

### get_trialsz.m

Imports epoched Meg160 data (from .sqd files) into Matlab. Data can be imported from specified channels, and epochs are defined by events on the specified trigger channels. The length of each epoch to be imported is defined by 'pre' and 'post,' which signify the time in milliseconds pre and post stimulus onset.### all_trigger.m

Called by other scripts.### all_triggerd.m

Called by other scripts.### ave_epoch.m

Averages a 3-d data array (time X sensor X epoch) across all trials.### ave_epochA.m

Averages a 2-d data array (time X epoch) across all trials. rmsA calculates the root-mean-squared of a 2-d data array (time X epoch) across all trials.### baseline.m

For each epoch in the datastack, for each channel in the data, takes the average of the values at that channel in that epoch for the period for pre data slices from the beginning of the epoch and subtracts that value from all the values for that channel for that epoch.### snr_rms.m

Called by other scripts.### sqdread.m

Called by other scripts.

## Correlation analysis scripts

This is a collections of scripts for running correlational analyses on MEG data. The scripts are very general and can either be used to analyze raw sensor data or results of minimum norm estimate analyses in source space. It is recommended that the entire collection be downloaded, as many scripts call upon additional scripts and classes found in the folder.

Download entire collection### ave_peak.m

Averages over all locations. finds positive or negative peak of this average timecourse for each epoch. If sign is 1, find the positive peak. If sign is -1, finds negative peak.### ave_peakA.m

Finds positive or negative peak for each epoch. If sign is 1, find the positive peak. If sign is -1, finds negative peak.### cor_ave_four.m

This function takes the datastack and weight variable, makes a matrix of the correlation coefficients, then returns the sigvalue, which is the smallest of these correlations that is significant. Then plots the correlations with a line separating the significant correlations from the insignificant ones. Also plots the rms of the correlations.### cor_ave_fourA.m

This function takes the RMS of the datastack (or any 2-d data array) and the weight variable, finds the correlation coefficients, then returns the sigvalue, which is the smallest of these correlations that is significant. Then plots the correlations with a line separating the significant correlations from the insignificant ones.### cor_ave_fourA2.m

This function takes the RMS of the datastack (or any 2-d data array) and the weight variable, finds the correlation coefficients, then returns the SigValue, which is the smallest of these correlations that is significant. then plots the correlations with a line separating the significant correlations from the insignificant ones.### cor_ave_fourA3.m

This function takes the RMS of the datastack (or any 2-d data array) and the weight variable, finds the correlation coefficients, then returns the SigValue, which is the smallest of these correlations that is significant. Then plots the correlations with a line separating the significant correlations from the insignificant ones.### cor_ave_fourAA.m

Finds the correlation between two vectors and its p value.### exclude.m

Excludes those values of 'var' that correspond to indices listed in the vector 'list.' For example, if 'list' lists the outliers that were excluded from the data, this function will exclude those same epochs from the variable vector. dim is the dimension for exclusion (assumed to be 1 if not specified). Works for array of up to 3 dimensions.### exclude_by_std.m

This function excludes values of a variable that are more than r standard deviations away from the mean. Makes a new datastack excluding those epochs which correspond to the excluded variable indices. Also makes a list of those indices.### exclude_outliers.m

This function excludes an entire epoch if that epoch contains a value above the max or below -max. Makes a new trigger variable excluding the triggers that correspond to the outliers. Makes a list of the indices of excluded outliers.### exclude_outliers_std.m

This function excludes an entire epoch if that epoch contains a value which is s standard deviations above or below the overall mean of the datastack. Then makes a new trigger variable excluding the triggers that correspond to the outliers and makes a list of the indices of excluded outliers. The count vector is a count of how many values were outside the range in each epoch.### exclude_outliers_std2.m

This function counts how many data points in each epoch are not within s standard deviations of the overall mean of the data - this is the count vector. Then the epochs for which this count is not within c standard deviations of the mean count are excluded. The data and trig are the new datastack and trigger vector without these epochs. The list is a list of the indices of those epochs which were excluded.### export_sqd.m

Adds channels to the data to equal 192 channels; cuts off data from pre-stimulus interval (meg160 will always interpret the data as starting at time = 0); scales the data by the input 'scale,' (scaling by 1000 works well if the data is a matrix of correlation coefficients); then makes a new sqd file from this data.### extr_by_trig_O2.m

Extracts only the data that applies to those trigger values that are specified by the trig vector. Then makes a new trigger vector which only includes those values.### extr_by_trig_O2A.m

Extracts only the data that applies to those trigger values that are specified by the trig vector. Then makes a new trigger vector which only includes those values. This works for 2 dimensional data, such as a cormatrx.### extr_by_trig_var.m

Extracts only the variable data that applies to those trigger values that are specified by the trig vector. This works for 1 dimensional data, such as a stimulus variable.### extr_by_var.m

Excludes the data that corresponds to the '0's of a binary variable. Also makes a list of the indices of the excluded data.### extr_by_varA.m

Divides the data in a 2d matrix (such as an rms array) into 2 separate datastacks, each corresponding to one value of a binary variable. Also divides the variable matrix into 2.### extr_by_varA2.m

Divides the data in a 2d matrix (such as an rms array) into 3 separate datastacks, each corresponding to three variable values. Also divides the variable matrix into 3.### extr_by_varAA.m

Divides the data in a vector into 2 separate ones, each corresponding to one value of a binary variable. Also divides the variable matrix into 2.### mean_amp.m

Finds the mean amplitude of the data with the range t1:t2.### normalize2.m

This function normalizes the data for each sensor for each time over all the epochs into z scores.### normalize_var.m

This function normalizes a vector into z scores.### normalizeA.m

Normalizes for each entry in the dimension dim. (So if dim is the time dimension, normalizes separately for each time point.) Works for 2dimensional data only.### peak.m

Finds maximum peak (not maximum point) within the specified range a:b.### recode_var.m

This function recodes the trigger variable into a dichotomous variable in which the values in the cond vector are coded as '1's and all other values coded as '0's.### rms_datastack.m

Gives the rms over all sensors for each time and epoch.### rmsA.m

Called by other scripts.### sig_value.m

Finds the smallest of the correlations in the cormatrx that is significant at the 0.05 level.### sig_valueA.m

Finds the smallest of the correlations in a vector of correalation coeffs. That is significant at the 0.05 level.### smooth.m

Smooths the rms matrix by taking the mean of each point with the n data points before and the n points after it (in time) to replace the point itself.