Loop to calculate multiple P values

I have a csv file with heartrate data throughout a day. Currently i have a function which will run a ttest on 2 groups of 60 datapoints which is split about a set point in the day (noon in this case). I want to create some kind of loop which will keep moving the split point in the dataset on and calculate a new p-value each time. I basically want to be able to plot and track the p-values throughout the day to determine when it falls below a certain threshold. Any ideas about how i could go bout doing this?
data = readtable('2021-02-07.csv');
noonindex = find(data.noonTime==1);
A = data.HeartRate(noonindex-60:noonindex);
B = data.HeartRate(noonindex+1:noonindex+61);
[h, p, ci] = ttest2(A,B)

8 comentarios

Scott MacKenzie
Scott MacKenzie el 22 de Abr. de 2021
Is that a typo in the 3rd line? Should that be noonIndex-60? The table includes a column named noonTime and another named HeartRate. Are the values in the noonTime column just 0s and 1s? Are there other columns for different times of the day? More details, please.
Ross Thompson
Ross Thompson el 22 de Abr. de 2021
Yes sorry just corrected that. And yes the noontime column is just 0s and 1s. So there’s only the one 1
Ross Thompson
Ross Thompson el 22 de Abr. de 2021
And the table has 3 columns. DataTime, heart rate and noontime
Ross Thompson
Ross Thompson el 22 de Abr. de 2021
But I’d imagine it would be better just to index the datapoint instead of the noontime to pivot about
Scott MacKenzie
Scott MacKenzie el 22 de Abr. de 2021
So, there's a column called DataTime. What do the data in that column look like? Examples? What is height(data)? It seems to me you'll need to build your code to iterate through the values in the DataTime column.
Ross Thompson
Ross Thompson el 23 de Abr. de 2021
Timestamp Heart rate
2021-02-27 12:00:00 80.03
2021-02-27 12:02:00 80.04
2021-02-27 12:04:00 80.04
2021-02-27 12:06:00 80.05
2021-02-27 12:08:00 80.06
2021-02-27 12:10:00 80.06
2021-02-27 12:12:00 80.07
Heres a sample of what the data looks like
Ross Thompson
Ross Thompson el 23 de Abr. de 2021
And then theres the noontime column but i dont think thats relevent
Scott MacKenzie
Scott MacKenzie el 23 de Abr. de 2021
Editada: Scott MacKenzie el 23 de Abr. de 2021
OK, it seems there's an entry ever 2 minutes. Why don't you just iterate down the table and insert the code shown in the original question, except using i as the split point:
n = height(data);
for i=n+60:n-61
A = data.HeartRate(i-60:i);
B = data.HeartRate(i+1:i+61);
[h, p, ci] = ttest2(A,B)
end
If you want to start at i=1 and end at i=n, then there's a bit more work to do:
n = height(data);
for i=1:n-1
lowerIdx = max(1, i-60);
upperIdx = min(n, i+60)
A = data.HeartRate(lowerIdx:i);
B = data.HeartRate(i+1:upperIdx);
[h, p, ci] = ttest2(A,B)
% display results, or whatever you want to do at each iteration
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Abr. de 2021

Editada:

el 23 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by