How to calculate mean of standard deviation (mean deviation) in a table

6 views (last 30 days)
With the table below how do I find the players mean_score and standard deviation.
what I tried. now quite sure how to handle the mean deviations.
Average standard deviation = √ (s12 + s22 + … + sk2) / k. ref here
summary = groupsummary(table,{'player'},{'mean'},{'mean_score','mean_rate'})
DATA
week = [1 2 1 2 1 2]';
player = [1 1 2 2 3 3]';
mean_score = [3.4 5.2 4.5 5.5 2.8 3.8]';
std_score = [2.1 2.4 2.8 2.3 2.2 2.3]'; %standard deviation
mean_rate = [5.4 8.2 4.5 15.5 22.8 12.8]';
std_rate = [0.1 0.16 0.14 0.12 0.3 0.16]'; % standard deviation
T = table(week,player,mean_score,std_score,std_rate);

Answers (2)

Image Analyst
Image Analyst on 17 May 2023
You forgot to attach your data, so we can't try anything with your actual data.
DON'T use "table" as the name of your table because table is a built in function!
Did you try
meanStd = mean(summary.std_score)
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
  4 Comments
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi on 17 May 2023
The code I added now should help in creating table T. In the end it should have 3 rows one for each player. Thank you.
Image Analyst
Image Analyst on 17 May 2023
Is there something wrong with my suggested solution?
week = [1 2 1 2 1 2]';
player = [1 1 2 2 3 3]';
mean_score = [3.4 5.2 4.5 5.5 2.8 3.8]';
std_score = [2.1 2.4 2.8 2.3 2.2 2.3]';
std_rate = [0.1 0.16 0.14 0.12 0.3 0.16]';
T = table(week,player,mean_score,std_score,std_rate)
T = 6×5 table
week player mean_score std_score std_rate ____ ______ __________ _________ ________ 1 1 3.4 2.1 0.1 2 1 5.2 2.4 0.16 1 2 4.5 2.8 0.14 2 2 5.5 2.3 0.12 1 3 2.8 2.2 0.3 2 3 3.8 2.3 0.16
meanStd = mean(T.std_score)
meanStd = 2.3500

Sign in to comment.


Star Strider
Star Strider on 17 May 2023
The 'mean_rate' variable does not exist in ‘T’.
Giving groupsummary the correct variable names (or at least variable names that exist) works —
week = [1 2 1 2 1 2]';
player = [1 1 2 2 3 3]';
mean_score = [3.4 5.2 4.5 5.5 2.8 3.8]';
std_score = [2.1 2.4 2.8 2.3 2.2 2.3]';
std_rate = [0.1 0.16 0.14 0.12 0.3 0.16]';
T = table(week,player,mean_score,std_score,std_rate)
T = 6×5 table
week player mean_score std_score std_rate ____ ______ __________ _________ ________ 1 1 3.4 2.1 0.1 2 1 5.2 2.4 0.16 1 2 4.5 2.8 0.14 2 2 5.5 2.3 0.12 1 3 2.8 2.2 0.3 2 3 3.8 2.3 0.16
summary = groupsummary(T,{'player'},{'mean'},{'mean_score','std_score','std_rate'})
summary = 3×5 table
player GroupCount mean_mean_score mean_std_score mean_std_rate ______ __________ _______________ ______________ _____________ 1 2 4.3 2.25 0.13 2 2 5 2.55 0.13 3 2 3.3 2.25 0.23
.
  4 Comments
Star Strider
Star Strider on 23 May 2023
That doesn’t lend itself to groupsummary, and the means of the standard deviations is not the same as rms, so a different approach is necessary.
Try this —
week = [1 2 1 2 1 2]';
player = [1 1 2 2 3 3]';
mean_score = [3.4 5.2 4.5 5.5 2.8 3.8]';
std_score = [2.1 2.4 2.8 2.3 2.2 2.3]';
std_rate = [0.1 0.16 0.14 0.12 0.3 0.16]';
T = table(week,player,mean_score,std_score,std_rate)
T = 6×5 table
week player mean_score std_score std_rate ____ ______ __________ _________ ________ 1 1 3.4 2.1 0.1 2 1 5.2 2.4 0.16 1 2 4.5 2.8 0.14 2 2 5.5 2.3 0.12 1 3 2.8 2.2 0.3 2 3 3.8 2.3 0.16
mean3 = accumarray(T{:,2}, (1:size(T,1)).', [], @(x)mean(T{x,3})); % Mean Of Mean Values
mean45c = accumarray(T{:,2}, (1:size(T,1)).', [], @(x){sqrt(sum(T{x,[4 5]}.^2))/numel(x)}); % MEan Of Standard Deviations
mean45 = cell2mat(mean45c);
VN = T.Properties.VariableNames;
Player_Means_Table = table(unique(T{:,2},'stable'),mean3,mean45(:,1),mean45(:,2), 'VariableNames',VN(2:end))
Player_Means_Table = 3×4 table
player mean_score std_score std_rate ______ __________ _________ ________ 1 4.3 1.5945 0.09434 2 5 1.8118 0.092195 3 3.3 1.5914 0.17
Those results appear to be correct (I checked some manually), if their calculations (as I understand them) are correct.
.
Star Strider
Star Strider on 23 May 2023
@Image Analyst — I don’t believe this is the same as rms.
As I understand it (although the expression posted is a bit ambiguous, and would benefit from appropriately-placed parenthesees) —
square root of the mean of the squares,
while
mean of the square root of the summed variaces
Anyway, that’s how I coded it.

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!