Mean for certain conditions

1 次查看(过去 30 天)
Anna
Anna 2021-2-7
编辑: Anna 2021-2-10
Hello,
I hope I can express my problem right, if not please ask about further details.
I am quite the beginner so I already have problems 'translating' the following basics into matlab language:
I have a table with data of a rating experiment and I need to get the mean values of certain items.
For each ID (all the '2' lines are one subject) I need a mean for the four ratings of the four phases of each snack and item. For example, I want the mean of the ratings of phases 1-4 for the item 'wanting' for the snack 'Gummibärchen', and that for each subject. ANd that for all items and snacks.
The plan after that is to visualise those differnces in heatmaps or plots but I am not sure how my desired output should look like (e.g. list or table or?). If you have tips regarding this, that would be great, too.
I have included a table with the data of 2 test IDs for testing, if that helps.
(Because the table is quite long, this screenshot only shows the beginnign of the table but as you can see the first 8 lines are all the 'Gummibärchen' ratings for phase 1 with the 8 rating-items. After that follows the same for 'Crackers', etc. Then, after the 6 snacks it switches back to 'Gummibärchen' and starts phase 2...)
Thank you for your help!

采纳的回答

Ive J
Ive J 2021-2-7
编辑:Ive J 2021-2-7
t = readtable('extracted_table.xlsx');
y = groupsummary(t, {'ID', 'Item', 'Snack'}, @mean, 'Rating'); % mean of Rating for each ID, Item and Snack combination
head(y)
ID Item Snack GroupCount fun1_Rating
__ ______________ _________________ __________ ___________
2 {'Bitternis' } {'Brezeln' } 4 1.5367
2 {'Bitternis' } {'Cracker' } 4 0.44025
2 {'Bitternis' } {'Gummibaerchen'} 4 3.4337
2 {'Bitternis' } {'Kekse' } 4 0.28776
2 {'Bitternis' } {'Nic Nacs' } 4 1.8572
2 {'Bitternis' } {'Rosinen' } 4 5.322
2 {'Intensität'} {'Brezeln' } 4 52.593
2 {'Intensität'} {'Cracker' } 4 32.14
You can visualize it also with scatter3
scatter3(categorical(y.Item), categorical(y.Snack), y.fun1_Rating, 50, y.ID, 'filled')
c = colorbar(gca);
c.Ticks = unique(y.ID);
c.TickLabels = string(unique(y.ID)); % show IDs on the colorbar
  1 个评论
Anna
Anna 2021-2-7
Awesome, thank you!
I totally overlooked the groupsummary function as I was always just looking at how to do it with the mean function.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by