MATLAB Answers

how to transform t_value to p_value ?

14 views (last 30 days)
jinwoo lee
jinwoo lee on 3 Feb 2021
Answered: Hiro on 3 Feb 2021
Hi, all
I would like to know how to calculate p_value through calculated t_value.
Referring to the above formula, I calculated t_value and since it is a calculation for 118 channels, the dimension of t_value is 118x 118.
Now, I need to calculate p_value based on t_value.
% corr_RH = [112 x 118 x 118] bp_RH = [ 112 x 250 x 118] ( trials, time , ch)
for rh_idx = 1: l
corr_RH(rh_idx,:,:) = corrcoef(squeeze(bp_RH(rh_idx,:,:)));
end
for rf_idx = 1:r
corr_RF(rf_idx,:,:) = corrcoef(squeeze(bp_RF(rf_idx,:,:)));
end
% mean corrleation coefficient
mean_corr_RH = squeeze(mean(corr_RH, 1));
mean_corr_RF = squeeze(mean(corr_RF, 1));
% find t-statistic
% S_p : pooled standard deviation case_2
% freedom = l + r - 2
% paper equation (6) ref.
freedom = l + r - 2;
for rh_idx = 1: l
s_temp_rh(rh_idx, :,:) = (squeeze(corr_RH(rh_idx,:,:)) - mean_corr_RH).^2;
end
for rf_idx = 1: l
s_temp_rf(rf_idx, :,:) = (squeeze(corr_RF(rf_idx,:,:)) - mean_corr_RH).^2;
end
% attenion ()
s_rh = sum(s_temp_rh,1) ./ (l-1) ;
s_rf = sum(s_temp_rf,1) ./ (r-1) ;
s_p = sqrt( ((l-1).*squeeze(s_rh) + (r-1).*squeeze(s_rf)) ./ freedom );
t_value = ( mean_corr_RH - mean_corr_RF ) ./ s_p * sqrt( 1/l + 1/r );
% t_value --> p_value transform
% P_thr = 0.05
P_thr = 0.05;
I have calculated up to t_value, but then how do I calculate p_value?
I have also used the ttest2 command, but something is weird, so I am writing the code myself.

Answers (1)

Hiro
Hiro on 3 Feb 2021
I did not walk through your script though, I would use t-distribution curve directly.
tcdf function is what you are looking for.
Without using proper functions, you'd result in writing code for integral computation, which is not that straightfoward....

Community Treasure Hunt

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

Start Hunting!

Translated by