We can achieve the calculation of the mean value and subsequent t-test for each observation in a 3D dataset by iterating through each spatial coordinate in the dataset. For each location, extract the time series data and perform a one-sample t-test against a predefined mean value, which is the average of the high and low composites. The results of these tests are stored in a matrix, allowing us to visualize the spatial distribution of p-values across the dataset using a heatmap.
Below is the sample MATLAB code to achieve the same:
% Initialize the dataset if not already done
% Assume precip is your data matrix of size (141, 71, 38)
% precip = rand(141, 71, 38); % Example initialization
% High and low composite values
high = 1.69;
low = -1.29;
% Mean value calculation
mean_value = (high - low) / 2;
% Initialize result matrix for storing t-test results
t_test_results = zeros(141, 71);
% Iterate over each spatial location
for i = 1:141
for j = 1:71
% Extract the time series for each location
data_series = squeeze(precip(i, j, :));
% Perform a one-sample t-test against the mean value
[~, p] = ttest(data_series, mean_value);
% Store the p-value or test result
t_test_results(i, j) = p;
end
end
% Display the t-test results
% use imagesc or a similar function to display the map
imagesc(t_test_results);
colorbar;
title('P-value Map from T-test');
xlabel('Longitude Index');
ylabel('Latitude Index');
Please find attached the documentation of functions used for reference:
I hope this helps in resolving the issue.