I need help using the corrcoef function to calculate PRx (pressure reactivity index)
Hi everyone! I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP (mean arterial blood pressure) data. PRx is known as "pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP) and intracranial pressure (ICP)". I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.
This is the script to display the PRx data that was given to me:
%PRx_display
% Load PRx data from MAT file
load(‘PRx,data_part1of1’);
PRx_values = measurement_data;
disp(‘PRx Values:’);
disp(PRx_values);
% Plot PRx values
figure;
plot(PRx_values);
xlabel(‘Time’);
ylabel(‘PRx Value’);
title(‘PRx’);
grid on;
% Calculate average PRx
average_PRx = mean(PRx_values);
% Display average PRx
fprintf(‘Average PRx: %.4f\n’, average_PRx);
This is the script I am trying to calculate PRx with:
%PRx_calc
% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;
load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;
% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);
% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);
% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error(‘ICP_time_vector and ICP_data have different lengths’);
end
if length(ABP_time_vector) ~= length(ABP_data)
error(‘ABP_time_vector and ABP_data have different lengths’);
end
% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, ‘linear’, ‘extrap’);
end
% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector
% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points
% Preallocate PRx array
PRx = NaN(floor((n – windowSize) / stepSize) + 1, 1);
% Compute moving correlation coefficient
for i = 1:stepSize:(n – windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize – 1, 2);
windowABP = ABP(i:i + windowSize – 1, 2);
% Calculate correlation coefficient for the current window
R = corrcoef(windowICP, windowABP);
% Store PRx (correlation coefficient of ICP and ABP)
PRx(floor(i / stepSize) + 1) = R(1, 2);
end
% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, ‘omitnan’) / sum(~isnan(PRx));
% Display average PRx in the command window
fprintf(‘Average PRx: %.4f\n’, averagePRx);
% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title(‘PRx vs Time’);
xlabel(‘Time (minutes)’);
ylabel(‘PRx Values’);
I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit. I am looking for help with the way I am using the corrcoef function and general debugging help.
Here are the first 20 values of each type of data: First 20 values of
ICP: 10 10 10 10 11 11 11 11 10 11 10 11 11 11 11 11 10 11 11 11
First 20 values of
ABP: 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89
First 20 calculated
PRx values: NaN NaN NaN NaN NaN NaN -0.0838 -0.2111 -0.0586 0.1704 0.4276 0.3193 0.3417 0.4128 0.5488 0.4790 0.5207 0.6822 0.7107 0.5235
Average PRx: 0.3209
The PRx_calc script, which produces the above values, should produce the given PRx values(below).
First 20 PRx Values: 0.6150 0.5996 0.6010 0.6276 0.7499 0.4495 0.4488 0.4492 0.5078 0.7263 0.7290 0.7343 0.7490 0.7561 0.6997 0.4609 0.2567 0.5935 0.7317 0.6666
Average PRx: 0.5247
Please let me know if there is anything else I should add, more data points, graphs, etc. Thank you!Hi everyone! I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP (mean arterial blood pressure) data. PRx is known as "pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP) and intracranial pressure (ICP)". I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.
This is the script to display the PRx data that was given to me:
%PRx_display
% Load PRx data from MAT file
load(‘PRx,data_part1of1’);
PRx_values = measurement_data;
disp(‘PRx Values:’);
disp(PRx_values);
% Plot PRx values
figure;
plot(PRx_values);
xlabel(‘Time’);
ylabel(‘PRx Value’);
title(‘PRx’);
grid on;
% Calculate average PRx
average_PRx = mean(PRx_values);
% Display average PRx
fprintf(‘Average PRx: %.4f\n’, average_PRx);
This is the script I am trying to calculate PRx with:
%PRx_calc
% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;
load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;
% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);
% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);
% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error(‘ICP_time_vector and ICP_data have different lengths’);
end
if length(ABP_time_vector) ~= length(ABP_data)
error(‘ABP_time_vector and ABP_data have different lengths’);
end
% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, ‘linear’, ‘extrap’);
end
% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector
% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points
% Preallocate PRx array
PRx = NaN(floor((n – windowSize) / stepSize) + 1, 1);
% Compute moving correlation coefficient
for i = 1:stepSize:(n – windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize – 1, 2);
windowABP = ABP(i:i + windowSize – 1, 2);
% Calculate correlation coefficient for the current window
R = corrcoef(windowICP, windowABP);
% Store PRx (correlation coefficient of ICP and ABP)
PRx(floor(i / stepSize) + 1) = R(1, 2);
end
% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, ‘omitnan’) / sum(~isnan(PRx));
% Display average PRx in the command window
fprintf(‘Average PRx: %.4f\n’, averagePRx);
% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title(‘PRx vs Time’);
xlabel(‘Time (minutes)’);
ylabel(‘PRx Values’);
I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit. I am looking for help with the way I am using the corrcoef function and general debugging help.
Here are the first 20 values of each type of data: First 20 values of
ICP: 10 10 10 10 11 11 11 11 10 11 10 11 11 11 11 11 10 11 11 11
First 20 values of
ABP: 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89
First 20 calculated
PRx values: NaN NaN NaN NaN NaN NaN -0.0838 -0.2111 -0.0586 0.1704 0.4276 0.3193 0.3417 0.4128 0.5488 0.4790 0.5207 0.6822 0.7107 0.5235
Average PRx: 0.3209
The PRx_calc script, which produces the above values, should produce the given PRx values(below).
First 20 PRx Values: 0.6150 0.5996 0.6010 0.6276 0.7499 0.4495 0.4488 0.4492 0.5078 0.7263 0.7290 0.7343 0.7490 0.7561 0.6997 0.4609 0.2567 0.5935 0.7317 0.6666
Average PRx: 0.5247
Please let me know if there is anything else I should add, more data points, graphs, etc. Thank you! Hi everyone! I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP (mean arterial blood pressure) data. PRx is known as "pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP) and intracranial pressure (ICP)". I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.
This is the script to display the PRx data that was given to me:
%PRx_display
% Load PRx data from MAT file
load(‘PRx,data_part1of1’);
PRx_values = measurement_data;
disp(‘PRx Values:’);
disp(PRx_values);
% Plot PRx values
figure;
plot(PRx_values);
xlabel(‘Time’);
ylabel(‘PRx Value’);
title(‘PRx’);
grid on;
% Calculate average PRx
average_PRx = mean(PRx_values);
% Display average PRx
fprintf(‘Average PRx: %.4f\n’, average_PRx);
This is the script I am trying to calculate PRx with:
%PRx_calc
% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;
load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;
% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);
% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);
% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error(‘ICP_time_vector and ICP_data have different lengths’);
end
if length(ABP_time_vector) ~= length(ABP_data)
error(‘ABP_time_vector and ABP_data have different lengths’);
end
% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, ‘linear’, ‘extrap’);
end
% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector
% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points
% Preallocate PRx array
PRx = NaN(floor((n – windowSize) / stepSize) + 1, 1);
% Compute moving correlation coefficient
for i = 1:stepSize:(n – windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize – 1, 2);
windowABP = ABP(i:i + windowSize – 1, 2);
% Calculate correlation coefficient for the current window
R = corrcoef(windowICP, windowABP);
% Store PRx (correlation coefficient of ICP and ABP)
PRx(floor(i / stepSize) + 1) = R(1, 2);
end
% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, ‘omitnan’) / sum(~isnan(PRx));
% Display average PRx in the command window
fprintf(‘Average PRx: %.4f\n’, averagePRx);
% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title(‘PRx vs Time’);
xlabel(‘Time (minutes)’);
ylabel(‘PRx Values’);
I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit. I am looking for help with the way I am using the corrcoef function and general debugging help.
Here are the first 20 values of each type of data: First 20 values of
ICP: 10 10 10 10 11 11 11 11 10 11 10 11 11 11 11 11 10 11 11 11
First 20 values of
ABP: 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89
First 20 calculated
PRx values: NaN NaN NaN NaN NaN NaN -0.0838 -0.2111 -0.0586 0.1704 0.4276 0.3193 0.3417 0.4128 0.5488 0.4790 0.5207 0.6822 0.7107 0.5235
Average PRx: 0.3209
The PRx_calc script, which produces the above values, should produce the given PRx values(below).
First 20 PRx Values: 0.6150 0.5996 0.6010 0.6276 0.7499 0.4495 0.4488 0.4492 0.5078 0.7263 0.7290 0.7343 0.7490 0.7561 0.6997 0.4609 0.2567 0.5935 0.7317 0.6666
Average PRx: 0.5247
Please let me know if there is anything else I should add, more data points, graphs, etc. Thank you! corrcoef MATLAB Answers — New Questions