Correlation between data a certain number of days apart

조회 수: 2 (최근 30일)
Chika Ugwuodo
Chika Ugwuodo 2021년 4월 11일
편집: Pavan Sahith 2024년 4월 18일
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.

답변 (1개)

Pavan Sahith
Pavan Sahith 2024년 4월 17일
편집: Pavan Sahith 2024년 4월 18일
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.

카테고리

Help CenterFile Exchange에서 Biological and Health Sciences에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by