Hi Marta,
To test whether the distributions of responses from two different patient groups are the same, you can use a chi-squared test for independence. This test will help determine if there is a significant association between the group membership and the responses.
- Organize Your Data: Create a contingency table that summarizes the frequency of each response in each group.
- Perform the Chi-Squared Test: Use the crosstab function to create a contingency table and the chi2gof function to perform the chi-squared test.
% Sample data
% Group A responses
groupA = [1, 2, 2, 3, 4, 5, 3, 2, 1, 5, 4, 3, 3, 2, 1];
% Group B responses
groupB = [2, 3, 3, 4, 5, 5, 4, 3, 3, 2, 1, 5, 4, 3, 2, 1, 1];
% Combine data into a single vector and create a group label vector
responses = [groupA, groupB];
groups = [ones(1, length(groupA)), 2 * ones(1, length(groupB))];
% Create a contingency table
[tbl, chi2stat, pValue] = crosstab(groups, responses);
% Display the contingency table
disp('Contingency Table:');
disp(tbl);
% Perform Chi-Squared Test
% The chi2stat and pValue are already calculated by crosstab
disp(['Chi-Squared Statistic: ', num2str(chi2stat)]);
disp(['p-Value: ', num2str(pValue)]);
% Interpret the result
if pValue < 0.05
disp('There is a significant difference between the groups.');
else
disp('There is no significant difference between the groups.');
end
Make sure your data is correctly formatted and that the responses are categorical as expected by the test. Adjust the sample data to fit your actual dataset.
