I see that you're working with data on gene biomarkers and corresponding COVID infection data. You're aiming to analyze the correlation between the gene biomarker data for a given day and the COVID infection data 4 days later.
To achieve this in MATLAB, you have converted your date data to ‘datenum’, for further steps to check the correlation of your data, you can follow the similar approach:
- I assumed that your data will be in the below format, I generated some sample data of gene biomarker and COVID information.
startDate = datenum('2020-01-01');
endDate = datenum('2020-06-30');
allDates = (startDate:endDate)';
geneData = [allDates, geneValues];
covidData = [allDates, covidValues];
- Then I prepared the data of gene biomarker and COVID infection, based on the 4-day lag, ensuring that the dates match correctly for a meaningful correlation analysis.
geneDates = geneData(:, 1);
geneValues = geneData(:, 2);
covidDates = covidData(:, 1) - 4;
covidValues = covidData(:, 2);
[commonDates, geneIdx, covidIdx] = intersect(geneDates, covidDates);
matchedGeneValues = geneValues(geneIdx);
matchedCovidValues = covidValues(covidIdx);
- Using “corrcoef”, I calculated the Pearson correlation coefficient between the aligned gene biomarker and COVID infection data sets.
[R, P] = corrcoef(matchedGeneValues, matchedCovidValues);
disp(['Correlation coefficient: ', num2str(R(1,2))]);
disp(['P-value: ', num2str(P(1,2))]);
- The correlation coefficient '(R(1,2))' quantifies the strength and direction of the linear relationship, while the p-value '(P(1,2))' assesses its statistical significance.
If your data is not normally distributed or you are more interested in the rank order of your data rather than linear relationships, you might consider using ‘Spearman's rho’ or ‘Kendall's tau’ for correlation. These can be computed using the “corr” function by specifying the method.
[Rho, Pval] = corr(matchedGeneValues, matchedCovidValues, 'Type', 'Spearman');
[Tau, Pval] = corr(matchedGeneValues, matchedCovidValues, 'Type', 'Kendall');
To know more about the “corrcoef”, “corr”, you can refer to the following MathWorks documentation:
I hope this will help you calculating the desired correlation.