TDT: how to use my own method in pattern_similarity.m?

Hi everyone,

Thank you for your continued support!
I have two quick questions about “pattern_similarity.m”.

  1. How to use my own method? The script says “if you want to use your own method, simply pass a string with the function name (has to be on the path!)”, but I could not achive it. Specifically, I would like to get “1 - pearson r” to use in RSA.

  2. Related to the question 1, I am wondering whether using betas obtained from RSA with 1 - pearson neural RDM is exactly appropriate for performing group-level statistics (i.e., one sample t-test for beta images across participants). Is it better to use other methods (e.g., Fisher’s z transformed correlation) or do some normalizations prior to the group analysis?

I really appreciate your kind support!
Ryuhei

Hi Ryuhei,

Oh, thanks for spotting this! This feature, indeed, wasn’t implemented yet, that was an omission! I’ll upload a new version of the toolbox soon, but please try the following: open pattern_similarity.m and navigate to otherwise, around line 81. Then replace the statement with the following:

try
   ownfunc = @method;
   sim = ownfunc(x,y);
catch
   error('Unknown or incorrectly used method %s for cfg.decoding.software = ''pattern_similarity'' Check field cfg.decoding.train.classification.model_parameters',method)
end

Please let me know if this does the job. The function e.g. one_minus_pearson.m needs to exist, possibly inside you would want to use the following

function dissim = one_minus_pearson(x,y)
    if nargin == 1
         dissim = 1-correlmat(x');
    elseif nargin == 2
         dissim = 1-correlmat(x',y');
    else
         error('No input provided to function')
    end

Regarding your second question, you are absolutely right, of course! But hardly anyone does this. One reason might be that the results will be virtually undistinguishable for absolute correlation values smaller than 0.5, and even up to 0.7, you wouldn’t expect to find a lot of differences. For more extreme values, accurate group-level stats would likely require some correction for bias introduced by Fisher-z, so, ideally a permutation procedure would be applied at that level (e.g. sign-permutation test at the group level). But I would have to think more about this to be really confident. I’d probably stick to no Fisher-z correction unless correlations are really high.

Best,
Martin

Hi Martin,

Thank you for your kind reply!
I have tried to use “one_minus_pearson” function in my matlab, but it did not work.
Could you see if my understanding is correct?

In “pattern_similarity.m”, I am writing like this following your suggestion:


case ‘cov’

   sim = cov2(x',y');    
   
otherwise
           
   % ------ my own method ------
   try
       ownfunc = @method;
       sim = ownfunc(x,y);
   % ---------------------------
   catch
       error('Unknown or incorrectly used method %s for cfg.decoding.software = ''pattern_similarity'' Check field cfg.decoding.train.classification.model_parameters',method)
   end        

end

And then, I am putting “one_minus_pearson.m” file in decoding_software/pattern_similarity/.
However, matlab cannot return one_minus_pearson value and the warning says, “Unknown or incorrectly used method one_minus_pearson for cfg.decoding.software = ‘pattern_similarity’ Check field cfg.decoding.train.classification.model_parameters”. It seems that pattern_similarity.m cannot access one_minus_pearson.m…What do I need to fix in the scripts?

I really appreciate your reply to my second question too! It was so helpful for me to understand why Fisher-z correlation is not very widely used in group-level RSA.

Best,
Ryuhei

Hi Ryuhei,

Hmm. The code I sent is correct, I just checked it and ran it myself. Are you using the function that I provided or a script? (it has to be a function). If this is not the problem, then there might perhaps be something wrong in how you pass the data.

To catch the error, add ME after catch
and then add rethrow(ME) right before the error statement, that should show you what the error is.

Best,
Martin

Hi Martin,

Thank you for replying to my question!
I am using the function that you provided to me as it was. As you guessed, it seems to be due to wrong passing, I’m not one hundred percent sure yet though.

Thanks to your suggestion to use ME, I found that my script accesses “pattern_similarity_fast.m”, instead of “pattern_similarity.m”, so I have added my own method to it as follows:

case 'cov'
    
    sim = covq(x');
    
otherwise
    
    % ------ my own method ------
    try
        ownfunc = @method;
        sim = ownfunc(x);
    % ---------------------------
    catch ME
        rethrow(ME);
        error('Unknown or incorrectly used method %s for cfg.decoding.software = ''pattern_similarity'' Check field cfg.decoding.train.classification.model_parameters',method)
    end

This did not work yet, but when I replace the try content with this, it works!

    try
        sim = one_minus_pearson(x); % directly access one_minus_pearson function

My RSA script is like this:

cfg.decoding.software = 'similarity';
cfg.decoding.method = 'classification';
cfg.decoding.train.classification.model_parameters = 'one_minus_pearson'; % this is 1 - pearson r

cfg.design = make_design_rsa(cfg);

This implies that my “pattern_similarity_fast.m” does not recognize cfg.decoding.train.classification.model_parameters = ‘one_minus_pearson’ referred in my RSA script.

I would be very happy if you could find the reason.
I always appreciate your kind help :slight_smile:

Best,
Ryuhei

Ah, I found the problem:

Use ownfunc = str2func(method);

That should do the job. Sorry, for some reason it worked initially when I tried it manually.

Best,
Martin

I see, it works now!
Thank you for your kind help!
Ryuhei