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

조회 수: 8 (최근 30일)
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi 2023년 5월 17일
댓글: Star Strider 2023년 5월 23일
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);

답변 (2개)

Image Analyst
Image Analyst 2023년 5월 17일
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
Frederick Awuah-Gyasi
Frederick Awuah-Gyasi 2023년 5월 17일
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 2023년 5월 17일
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

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2023년 5월 17일
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
Star Strider
Star Strider 2023년 5월 23일
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 2023년 5월 23일
@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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by