フィルターのクリア

Error in paired t-test between corresponding elements.

3 ビュー (過去 30 日間)
Haya Ali
Haya Ali 2024 年 3 月 25 日
コメント済み: Haya Ali 2024 年 3 月 26 日
I am trying to perform paired t-test between corresponding elements of group1 and group2. It should provide non-NaN p-values for each corresponding pair but it is providing NAN values. Please help to resolve the error. Below is my code.
% Define the data for two groups
group1 = [10, 15, 20, 25, 30];
group2 = [12, 18, 22, 28, 32];
% Initialize array to store p-values
p_values = zeros(size(group1));
% Check if the sizes of the two groups are the same
if numel(group1) ~= numel(group2)
error('The sizes of the two groups must be the same.');
end
% Perform paired t-test for each pair of corresponding elements
for i = 1:numel(group1)
fprintf('Performing t-test for Node %d...\n', i);
% Perform paired t-test for the current pair
[~, p_values(i)] = ttest(group1(i), group2(i));
end
% Display the p-values for each corresponding pair
for i = 1:numel(group1)
fprintf('Node %d: p-value = %f\n', i, p_values(i));
end
  1 件のコメント
VBBV
VBBV 2024 年 3 月 26 日
The input data for samples need to be vectors when using ttest or ttest2 functions to evaluate the p-values

サインインしてコメントする。

採用された回答

VBBV
VBBV 2024 年 3 月 25 日
編集済み: VBBV 2024 年 3 月 25 日
% Define the data for two groups
group1 = [10, 15, 20, 25, 30];
group2 = [12, 18, 22, 28, 32];
% Initialize array to store p-values
p_values = zeros(size(group1));
% Check if the sizes of the two groups are the same
if numel(group1) ~= numel(group2)
error('The sizes of the two groups must be the same.');
end
% Perform paired t-test for each pair of corresponding elements
for i = 1:numel(group1)
fprintf('Performing t-test for Node %d...\n', i);
% Perform paired t-test for the current pair
[~, p_values(i)] = ttest(group1, group2(i)); % use a vector for paired comparison test
end
Performing t-test for Node 1... Performing t-test for Node 2... Performing t-test for Node 3... Performing t-test for Node 4... Performing t-test for Node 5...
% Display the p-values for each corresponding pair
for i = 1:numel(group1)
fprintf('Node %d: p-value = %f\n', i, p_values(i));
end
Node 1: p-value = 0.086418 Node 2: p-value = 0.601832 Node 3: p-value = 0.601832 Node 4: p-value = 0.086418 Node 5: p-value = 0.027426
p_values
p_values = 1x5
0.0864 0.6018 0.6018 0.0864 0.0274
  4 件のコメント
VBBV
VBBV 2024 年 3 月 26 日
Hi @Haya Ali, for two sample t-test, check the ttest2 function instead of regular ttest
Haya Ali
Haya Ali 2024 年 3 月 26 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by