making a grouping variable

4 ビュー (過去 30 日間)
Sarah Yun
Sarah Yun 2019 年 12 月 29 日
回答済み: Star Strider 2019 年 12 月 29 日
Hello,
I want to make group variable so I can do kruskal-wallis test between two columns of unequal size
% Make 2 columns from data
sales_A = Sales{:,2};
sales_B = Sales{:,3};
% Merge columns
x = [sales_A; sales_B];
% Make grouping variable
group = [1 + zeros(size(A)); 2 + zeros(size(B));
% How I make grouping variable here so I can do kruskal-wallis test?
p = kruskalwallis
Thank you.

回答 (1 件)

Star Strider
Star Strider 2019 年 12 月 29 日
Using the illustration in Test for the Same Distribution Across Groups, it would likely be best to create vectors instead of matrices if the group sizes are not equal, for example:
x = [sales_A; sales_B];
group = [ones(size(sales_A)); 2*ones(size(sales_B))];
Since ‘Sales’ appears to be a cell array of column vectors, I am assuming that ‘x’ and ‘group’ will both be column vectors as well. (Change this and the code if my guess is incorrect.)
To use a matrix argument, both columns need to have the same row size, and since they are apparently not the same size, a matrix will not work here. They have to be vectors, creating a new vector.
I cannot test this without ‘Sales’, so I am posting it as UNTESTED CODE.

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by