proportion of gender having health issue

I have a table that has Gender vector (1=Boy, 2=Girl) and Healtissue (based on score). I would like to know the proportion of girls only have a health issue if their score more than 17?

2 Commenti

Look at findgroups, groupsummary with the Subject "Split-Apply-Combine" workflow under splitapply
Many examples...
Thank you

Accedi per commentare.

 Risposta accettata

Assume t is your table and you have a column for gender, a column with HealthScore (true or false), and a column for their score (continously-valued number). Then try
% Find rows with girls who have a score more than 17.
rows1 = (t.Gender == 2) & (t.Score > 17)
% Now find girls with a score more than 17 who ALSO have a health issue (may not be 100% - may only be part of them).
rows2 = (t.Gender == 2) & (t.Score > 17) & t.HealthIssue % Assuming this is a logical column.
proportion = rows2 / rows1

5 Commenti

Thanks for your help
I have created the following
score=sdq;% obtaining scores from sdq vector
Gender= (sex == 1);% To get male student only
count=0;
for K=1:length(score)
O=1:length(Gender);
MentalHealthProblem = score > 17 & Gender ; % count male whos score >17
count=count+1;
end
Uh, okay. But you said you wanted girls. And it was not clear how the health problem was defined. I thought it was independently determined, like some percentage of those with scores above 17 would have a problem. But it looks like you're saying that if the score is more than 17, they definitely, 100% have a health problem. If that's it, then that's fine. Anyway, this code doesn't look good. Your count will always equal length(score) so what's the point? Plus MentalHealthProblem will always be a logical vector, assuming sdq was a vector, not a scalar, which seems reasonable since you're doing a loop for every element of it. Do you even need a for loop if you simply want
MentalHealthProblem = sum(score > 17 & Gender); % Count males whose score > 17
Great that give good out put
now if you want to compare the result of boys who are under the smae condition with the girls who have same problem how can I do that?
I'd do
maleRows = (sex == 1); % To get male students only.
femaleRows = (sex == 2); % To get female students only.
I rewrite based on your suggestion and I think it looks bettern now. However I have problem in creating figure showing the result
score=sdq;
BoyGender= (sex == 1);
GirlGender=(sex==2);
BoysMentalHealthProblem = sum(score > 17 & BoyGender)
GirlsMentalHealthProblem = sum(score > 17 & GirlGender)

Accedi per commentare.

Più risposte (1)

Some other things to explore...
hScore=randi(100,100,1)/4; % An artificial dataset...
sex=(rand(size(hScore))>0.5)+1; % 50:50 roughly
tMH=table(sex,hScore,'VariableNames',{'Gender','HealthIssue'}); % make a table
tMH.Gender=categorical(tMH.Gender,[1,2],{'Boy','Girl'}); % turn into categorical instead
tMH.AtRisk=categorical(tMH.HealthIssue>17); % compute the risk factor
heatmap(tMH,'Sex','AtRisk') % one way to look at results...
Results will vary for a random sample, but for the particular dataset generated here:
>> groupsummary(tMH,'Gender')
ans =
2×2 table
Gender GroupCount
______ __________
Boy 51
Girl 49
>> groupsummary(tMH,'AtRisk')
ans =
2×2 table
AtRisk GroupCount
______ __________
false 68
true 32
>> groupsummary(tMH,{'Gender','AtRisk'})
ans =
4×3 table
Gender AtRisk GroupCount
______ ______ __________
Boy false 37
Boy true 14
Girl false 31
Girl true 18
>>
You can compute percentages from the GroupCounts depending upon whether want by Gender or overall...the above produces

Community Treasure Hunt

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

Start Hunting!

Translated by