Sampling 100 four-child families to estimate the probability that a four-child family has three girls

2 views (last 30 days)
So I am able to create the familys and count how many familys have 3 daughters but I cant figure out how I would estimate the probability so that I could make a line plot
S = 2; % 1=boy 2=girl
R = 1; % coin fliped once
N = 4; % flip 4 coins at once
T = 100; % repeat 100 times
Out = randi([1 S],[R N T]);
formatSpec = "%x";
for i = 1:T
for j = 1:N
a = num2str(Out(:,j,i),formatSpec);
fam(i,j) = a;
end
end
match1 = ('1222'); %row you want
eq1 = sum(all(bsxfun(@eq,fam,match1),2)); %engine
match2 = ('2122'); %row you want
eq2 = sum(all(bsxfun(@eq,fam,match2),2)); %engine
match3 = ('2212'); %row you want
eq3 = sum(all(bsxfun(@eq,fam,match3),2)); %engine
match4 = ('2221'); %row you want
eq4 = sum(all(bsxfun(@eq,fam,match4),2)); %engine
f = [eq1 eq2 eq3 eq4];
fd = sum(f);

Accepted Answer

Image Analyst
Image Analyst on 14 Feb 2021
Scrap almost all that and do this:
S = 1; % 0=boy 1=girl
R = 1000000; % a million families with 4 children
N = 4; % flip 4 coins at once
Out = randi([0, S], [R, N]);
numGirls = sum(Out, 2);
fd = mean(numGirls == 3) / N
fd =
0.06245675

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!