Effacer les filtres
Effacer les filtres

Correlation between data a certain number of days apart

6 vues (au cours des 30 derniers jours)
Chika Ugwuodo
Chika Ugwuodo le 11 Avr 2021
Modifié(e) : Pavan Sahith le 18 Avr 2024
I have a gene biomaker data and corresponding Covid infection data. I want to check for correlation between gene biomarker data for a given day and Covid infection data 4 days later. Is there a way to automatically code this.
I have converted my date data to datenum but got stuck while trying to write the code.

Réponses (1)

Pavan Sahith
Pavan Sahith le 17 Avr 2024
Modifié(e) : Pavan Sahith le 18 Avr 2024
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.
% Sample data
startDate = datenum('2020-01-01');
endDate = datenum('2020-06-30');
allDates = (startDate:endDate)';
% Create the datasets
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; % Shift COVID data 4 days earlier
covidValues = covidData(:, 2);
% Find matching dates in both datasets
[commonDates, geneIdx, covidIdx] = intersect(geneDates, covidDates);
% Extract values for matching dates
matchedGeneValues = geneValues(geneIdx);
matchedCovidValues = covidValues(covidIdx);
  • Using “corrcoef”, I calculated the Pearson correlation coefficient between the aligned gene biomarker and COVID infection data sets.
% Calculate correlation
[R, P] = corrcoef(matchedGeneValues, matchedCovidValues);
% Display the correlation coefficient and p-value
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.


En savoir plus sur Biological and Health Sciences dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by