Anna
Anna

Reputation: 1

Matlab resampling hypothesis test correlation - Why Do the P-Value and Confidence Interval for My Correlation Test Give Different Results?

I want to test wether there is a correlation between the (average) exam and deliverable marks obtained by each student, so I tried to do it using resampling testing.


%% 
% Hypotheses:
% H0​: There is no correlation between exam and deliverable marks (ρ=0).
% H1​: There is a significant correlation between exam and deliverable marks (ρ≠0).

%% 
% Calculate the observed correlation between exam and deliverable marks
observed_corr = corr(marks_exams_perStudent, marks_deliverables_perStudent);

% Bootstrap resampling for correlation coefficients
nResamples = 10000;  % Number of bootstrap resamples
bootstrap_corrs = zeros(nResamples, 1);

for i = 1:nResamples
    % Resample with replacement

    resample_indices = randi(size(marks_exams_perStudent, 1), size(marks_exams_perStudent, 1), 1);
    resample_exam = marks_exams_perStudent(resample_indices);
    resample_deliverable = marks_deliverables_perStudent(resample_indices);
    
    % Compute correlation for the resampled data
    bootstrap_corrs(i) = corr(resample_exam, resample_deliverable);
end

% Calculate the 95% Confidence Interval for the bootstrap correlations
sorted_bootstrap_corrs = sort(bootstrap_corrs);
lower_bound = sorted_bootstrap_corrs(floor(0.025 * length(sorted_bootstrap_corrs)) + 1);
upper_bound = sorted_bootstrap_corrs(floor(0.975 * length(sorted_bootstrap_corrs)));

% Display the confidence interval
disp(['The 95% Confidence Interval for the correlation coefficient is: [' num2str(lower_bound) ', ' num2str(upper_bound) ']']);


% Calculate the p-value for the observed correlation
bootstrap_abs_corrs = abs(bootstrap_corrs);  % Take absolute values of bootstrap correlations
observed_abs_corr = abs(observed_corr);      % Absolute value of observed correlation

% Calculate the p-value (two-tailed)
p_value = mean(bootstrap_abs_corrs >= observed_abs_corr);

disp(['p-value for the hypothesis test: ', num2str(p_value)]);


I get the following results:

The 95% Confidence Interval for the correlation coefficient is: [0.090306, 0.50174] p-value for the hypothesis test: 0.5187

So going by CI Im able to reject the hypothesis while by p-value Im not. What am I doing wrong?

Upvotes: 0

Views: 16

Answers (0)

Related Questions