Mean for certain conditions

1 visualización (últimos 30 días)
Anna
Anna el 7 de Feb. de 2021
Editada: Anna el 10 de Feb. de 2021
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!

Respuesta aceptada

Ive J
Ive J el 7 de Feb. de 2021
Editada: Ive J el 7 de Feb. de 2021
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 comentario
Anna
Anna el 7 de Feb. de 2021
Awesome, thank you!
I totally overlooked the groupsummary function as I was always just looking at how to do it with the mean function.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by