% Filename: TaySachs.m
% M-file for determing P(A|not B) where
%   A = offspring is a carrier
%   B = offspring does have TaySachs
% given that both parents are carriers

% Set how many times to run the experiment
N = 1000;

% Set variables to sum up the probabilities of events
A = 0;      % probability of Aa or aA
B = 0;      % probability of aa

% Run set of N experiments N times
for i = 1:N
   % Set counters
   a = 0;   % heterozygous counter
   b = 0;   % homozygous recessive counter
   
   % Run experiment N times
   for j = 1:N
       % Get child's genotype if both parents are carriers
       child = OneChild(1,1);
       
       % Increase appropriate counter
       if child == 1
           a = a + 1;
       elseif child == 3
           b = b + 1;
       else
           % do nothing
       end
   end
   
   % Add the probabilities for this set of N experiments
   % to the running sum
   A = A + a/N;
   B = B + b/N;
end

% Estimated Probability of Event A
PA = A/N;

% Estimated Probability of Event NOT B
PB = 1 - B/N;

% Print out results
fprintf('P(carrier|no disease)=%6.4f\n',PA/PB)