I wanted to apply the chi-squared function with the return of the p-value, but matlab's chi2cdf function only returns zero.
Show older comments
% Example data matrix (2000 rows and 9 columns)
data_matrix = randi([0, 10], 2000, 9); % Replace this with your actual data
% Example empirical frequency (a vector with 9 elements)
empirical_frequency = [10, 20, 30, 40, 50, 60, 70, 80, 90]; % Replace this with your actual empirical frequency
% Initialize vectors to store results
chi_squared_results = zeros(2000, 1);
p_values = zeros(2000, 1);
for i = 1:2000
% Select the data for row i
row_i = data_matrix(i, :);
% Calculate the chi-squared statistic manually
chi_squared = sum((row_i - empirical_frequency).^2 ./ empirical_frequency);
% Determine the degrees of freedom (df)
df = length(row_i) - 1;
% Calculate the p-value using the chi-squared distribution
p = 1 - chi2cdf(chi_squared, df);
% Store the results in vectors
chi_squared_results(i) = chi_squared;
p_values(i) = p;
end
unique(p_values)
The problem is that chicdf return 0.
1 Comment
PEDRO ALEXANDRE Fernandes
on 2 Nov 2023
Accepted Answer
More Answers (0)
Categories
Find more on Hypothesis Tests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
