calculate proportion correct for each condition of each session, excluding trials where gaze offset is an outlier in matlab

To calculate the proportion correct for each condition of each session, excluding trials where gaze offset is an outlier in MATLAB, you can follow these steps:

  1. Load and preprocess your data: Start by loading your data into MATLAB and pre-process it according to your specific requirements. Ensure that you have separate variables for conditions, sessions, and gaze offset measurements.

  2. Identify outliers: Use an outlier detection method to identify trials where gaze offset is an outlier. There are multiple ways to do this, such as using z-scores or the interquartile range (IQR). For example, you can consider trials where the gaze offset is more than 3 standard deviations away from the mean as outliers.

  3. Exclude outlier trials: Remove the outlier trials from your data set by filtering out rows that correspond to these trials. This can typically be done using logical indexing.

  4. Compute the proportion correct: Group your data by conditions and sessions. Calculate the proportion correct for each condition and session by counting the number of correct trials and dividing it by the total number of trials.

Here's an example code snippet illustrating these steps:

main.m
% Step 1: Load and preprocess data
load('yourdata.mat'); % replace with your data file
conditions = yourdata.conditions; % replace with your actual variable names
sessions = yourdata.sessions;
gazeOffset = yourdata.gazeOffset;

% Step 2: Identify outliers
zscore_gazeOffset = zscore(gazeOffset);
outliers = abs(zscore_gazeOffset) > 3;

% Step 3: Exclude outlier trials
conditions(outliers) = [];
sessions(outliers) = [];
gazeOffset(outliers) = [];

% Step 4: Compute proportion correct
uniqueConditions = unique(conditions);
uniqueSessions = unique(sessions);
proportionCorrect = zeros(length(uniqueConditions), length(uniqueSessions));

for i = 1:length(uniqueConditions)
    for j = 1:length(uniqueSessions)
        idx = (conditions == uniqueConditions(i)) & (sessions == uniqueSessions(j));
        correctTrials = sum(idx); % replace with your actual correct trial variable name
        totalTrials = sum(idx); % replace with your total trial variable name
        proportionCorrect(i, j) = correctTrials / totalTrials;
    end
end

% The 'proportionCorrect' matrix now contains the proportion correct for each condition of each session, excluding trials with gaze offset outliers.
1187 chars
31 lines

Please replace 'yourdata.mat', 'yourdata.conditions', 'yourdata.sessions', 'yourdata.gazeOffset', and the calculation of 'correctTrials' and 'totalTrials' variables with your actual variable names in your data file.

This code assumes that conditions and sessions are categorical variables, and that you want to calculate the proportion correct separately for each unique combination of conditions and sessions. Adjust the code accordingly if your case is different.

Remember to modify the outlier detection criteria to suit your specific needs and data characteristics.

gistlibby LogSnag