# Instructions for use #
This component contains the analysis and plotting scripts for Experiment 2a. The scripts are organized into three folders (AnalysisScripts, AnalysisScripts_EyePos, and AnalysisScripts_Supp). Under the heading for each folder there are brief descriptions of what each script does (roughly listed in the order you'd want to run them).
## AnalysisScripts ##
This folder contains all the scripts to run the main analyses reported in the paper.
**SubList.mat:** a .mat file that contains the list of subjects with usable data.
**compileBehavior:** compiles relevant variables from raw behavior files (one file for each block of the task) into a single file for each participant. Note: the compiled behavior files are already available in the 'Compiled Data' component.
**compileBehavior_Subs11_19:** compile behavior function for Sub 11 and Sub 19. Reads in renamed files to deal with things that happened during data collection. I have included the renamed files in the 'Compiled Data' component.
Sub 11: Stopped recording EEG at end of Block 7 when subject took a break. Forgot to start recording again, so did not record EEG data for blocks 8-11. Had participant do an extra block of the task, so they completed 16 blocks in total (12 blocks with EEG data). The eye tracker wasn’t working for this subject, so I only had to patch together and align the EEG and behavior data. I renamed the behavior files: 8-11 were deleted (because no EEG data), 12 became 8, 13, became 9 etc. 11b-1 (the extra block) became 12. There is a script in the preprocessing folders (in the Compiled Data component) that I used to patch together the EEG files called “ConcatenateSub11”
Sub 19: Sub 19: recorded two extra blocks at the end of the session (17 blocks total). I renamed the files for blocks 1-15 from 19_JJF_16_1_BlockNum.mat to 19_JJF_16_1_renamed_BlockNum. The extra blocks (which were saved as 119_JJF_16_1.mat and 119_JJF_16_2.mat), where renamed 19_JJF_16_1_renamed_16.mat and 19_JJF_16_1_renamed_17.mat.
######Details here
**fitSwapModel:** fit Bays swap model to response errors using MemToolbox (http://visionlab.github.io/MemToolbox/).
**summarizeParamEsts:** summarize the parameter estimates (for all subjects) obtained using fitSwapModel in a single matrix.
**SpatialEM:** runs the spatial encoding model on alpha-band (8-12 Hz) activity.
**SpatialEM_Permute:** runs the relevant spatial encoding model routine 1000 times, each time with the location bin labels permuted within each train/test set. The output of these scripts is the basis for the permutation tests that we report in the paper.
**calculateSlopes_Alpha:** calculate CTF slope metric for both the unpermuted (output of SpatialEM) and permuted (output of SpatialEM_Permute) data.
**PermTest_T_Alpha:** used the output of the calculateSlopes script to run the permutation test using the CTF slope metric.
**PermTest_NT_Alpha:** same thing for the non-target CTFs.
**bootstrapSlopes:** bootstrap standard error bars across time.
**resamplingTest_TvsNT:** does the resampling test to test for differences in CTF slope between the target- and non-target-CTF. Uses output from bootstrapSlopes.
**baselinedEOG:** baseline the EOG data.
### Plotting functions ###
**plotHEOGBias:** plot the average baselined HEOG as a function of position bin. Uses output from baselinedEOG.m
**plotSlopes:** plot the time-resolved slope of target- and non-target-CTFs (Fig 3a').
### Sub-functions called by other scripts ###
**eegfilt:** EEGLAB’s filtering function (http://sccn.ucsd.edu/eeglab/; Delorme & Makeig, 2004). Called by the SpatialEM scripts for filtering data.
**shadedErrorBar:** used for generating shaded error bars (retrieved from: https://www.mathworks.com/matlabcentral/fileexchange/49382-pict--particle-image-characterization-tool/content/PICT/shadedErrorBar/shadedErrorBar.m)
## AnalysisScripts_EyePos ##
This folder contains the scripts used to analyzed the eye tracking data reported in Figure S4 in the Supplemental Information.
**EyeTrackSubList:** a .mat file that contains the list of subjects with usable eye tracking data.
**EyeTrack_processData:** read in eye tracking data, mark trials with bad eye tracking data (i.e., eye tracker lost the pupil), drift correct the data, save to a file.
**EyeTrack_AveByBin:** average eye data for each position bin.
**plot_SuppEyeFig:** plot data as in Figure S4 in Supplemental Information.
## AnalysisScripts_Supp ##
**SubList.mat:** a .mat file that contains the list of subjects with usable data.
**SpatialEM_TrnT_TstNT:** runs the spatial encoding model on alpha-band (8-12 Hz) activity but trains on the target position and tests on the non-target position.
**SpatialEM_TrnT_TstNT_Permute:** runs the relevant spatial encoding model routine 1000 times (again training on the target position and testing on the non-target position), each time with the location bin labels permuted within each train/test set. The output of these scripts is the basis for the permutation tests.
**calculateSlopes_TrnT_TstNT:** calculate CTF slope metric for both the unpermuted (output of SpatialEM_TrnT_TstNT) and permuted (output of SpatialEM_TrnT_TstNT_Permute) data.
**bootstrapSlopes_TrnT_TstNT:** bootstrapping for standard error bars.
**PermTest_Alpha_TrnT_TstNT:** does permutation testing to see where CTF selectivity is above chance.
**plotSlopes_FigS2:** plot CTF slope across time (Figure S2).
**eegfilt** and **shadedErrorBar** are as described above.