Fitting a logistic function using a script to data individually and then analysing it together

7 次查看(过去 30 天)
Hi there,
For background, this analysis related to an experiment in which 12 participants done a auditory temporal bisection task in which they were represented auditory stimuli lasting from 300-700ms and had to judge if this stimuli was closer in duration to the long stimuli (lasting 700ms) or to the short one (lasting 300ms). I have the data from each participant in 12 separate mat files. I am meant to first fit a logistic function to ach datafile separately with this script:
function [bp,wf,plongs]=tb_script(filename)
%% RUN THE FUNCTION
% tb_script(filename) (e.g. 'ts_12.mat')
%% add path for toolbox (you need to change this!)
addpath /Users/anacc/Desktop/MATLAB/palamedes1_10_9/Palamedes
%% INPUTS
file=load('ts_1.mat');
data=file.data;
%% DATA PREPARATION
% identify the stimulus levels
stimlevels=unique(data(:,1));
% compute p(long) for each interval and number of trials
plong=zeros(1,size(stimlevels,1));
for i = 1:size(stimlevels,1)
temp=data(data(:,1)==stimlevels(i),:);
plong(1,i)=size(temp(temp(:,2)==2,:),1) / size(temp,1);
trials(1,i)=size(temp,1);
end
% compute the number of "long" responses at each interval
numpos=plong.*trials;
% compute the number of trials at each interval
outofnum=[ones(1,size(stimlevels,2)).*trials];
%% PSYCHOMETRIC FUNCTION FIT
% psychometric function type
PF=@PAL_Logistic;
% number of bootstraps
boot=1000;
% which parameters are free (1=free, 0=fixed)
paramsfree=[1 1 0 0];
% search grid for different parameters
searchgrid.alpha = [.300:005:.700];
searchgrid.beta = .01:.02:2;
searchgrid.gamma = 0;
searchgrid.lambda =0.1;
% fit psychometric function & compute values
paramsvalues = PAL_PFML_Fit(stimlevels',numpos,outofnum,searchgrid,paramsfree,PF);
% bisection point
fit75 = PAL_Logistic(paramsvalues, .75, 'Inverse');
fit25 = PAL_Logistic(paramsvalues, .25, 'Inverse');
bp = PAL_Logistic(paramsvalues, .5, 'Inverse');
wf=((fit75-fit25)/2)/bp;
% compute pdev
[dev pdev devsim converged] = PAL_PFML_GoodnessOfFit(stimlevels',numpos,outofnum,paramsvalues,paramsfree,boot,PF,'searchGrid',searchgrid);%'lapseLimits',[0 .3]);
%% PLOT
% p(long)
proplongdata=numpos./outofnum;
% psychometric function
stimlevelsfine=[min(stimlevels):(max(stimlevels)-min(stimlevels))./1000:max(stimlevels)];
fit=PF(paramsvalues,stimlevelsfine);
% plot plong
plot(stimlevels,proplongdata,'k.','markersize',20);
set(gca,'fontsize',12,'TickDir','out');
axis([.250 .750 0 1]);
xlabel('Stimulus duration (ms)')
ylabel('p(long)')
pbaspect([1 1 1])
box off
hold on
% plot logistic function
plot(stimlevelsfine,fit,'b-','linewidth',0.5);
hold off
%% PRINT
% present information in command window
% print values
bp=bp
wf=wf
pdev=pdev
plongs=proplongdata
----
I have gathered that I need to alter this bit:
%% INPUTS
file=load('ts_1.mat');
data=file.data;
according to the name of the datafile I want to analyse. So far, I have been doing 'ts_1.mat', then 'ts_2.mat' until number 12 (12 participants). However, this is the bit where I am stuck at. So, I am meant to run the script for each datafile separately and then save all the information which comes up in the command window. After that, I am meant to compare the 2 groups of participants (6 of them fit one group as they have Tourette’s syndrome and the other 6 fit the other group which does not have the condition) on the two dependent variables (that those with the condition will have an underestimation bias; and that they will also be prone to poorer temporal decision). I also know that the participants with Tourettes are 2, 3, 5, 7, 11, 12. Now, how am I meant to save the command window info in a way in which I can then analyse there two groups against one another on the 2 variables? Am I meant to save it independently, group it according to the group they belong to (create 2 data 'sets'), create just one data set? I thought that maybe I am meant to concatonate the data together, but now I am not sure anymore. And how exactly can I save it?
As you can see from this picture, this is the info that comes up in the command window for the datafile ts_1.mat after I ran the script.

回答(1 个)

ANKIT MAURYA
ANKIT MAURYA 2022-5-7
Hi Ana,
I am working on temporal bisection task for my experiment. Now, i have to write analysis code in Matlab. Luckily I found your this post. Many of the things are clear to me by understanding your logic. I want to understand few of the things.
I will be proceeding for analysis in the same way -- first individual and then will concatenate all the data files. I also have two conditions, but my designing in within group and not beween group.
Can you kindly explain me the portion of the code written below ---------------
plong=zeros(1,size(stimlevels,1));
for i = 1:size(stimlevels,1)
temp=data(data(:,1)==stimlevels(i),:);
plong(1,i)=size(temp(temp(:,2)==2,:),1) / size(temp,1);
trials(1,i)=size(temp,1);
% What is stimlevels? Is it the comparison durations between 300 -700 ms?
%%% What is 1 after stimlevels in second line?
Please explain me this portion of code line by line. I am not able to get this. Also , can you share the mat file of function you wrote for temporal bisection task with me. My mail id is -- ankit.m@hs.iitr.ac.in . I would highly appreaciate your effort for this. Thanks in advance.

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by