Calculating probability using the CDF function of Beta distribution.
4 views (last 30 days)
Show older comments
hi,
i need help some help please :(
i have a csv file with some election data (attached it in the post)
and this is the question form my homework:
Using the Beta distribution for each state, you can calculate the probability that the Democrats/Republicans will win the upcom ing elections in each state. Calculate it using the CDF function of each Beta distribution. How and why should you use it to get the probability of the election results in each state?
now i did calculate the beta distribution for each state using this code:
a = data.Democrat + 1; % number of people that voted democrat in the poll
b = data.Republican + 1; % number of people that voted Republican in the poll
% calculating beta distribution for each state_ii :
beta_dist = cell(size(data,1),1); proportion_democrate = zeros;
for ii=1:51
beta_dist{ii} = makedist('beta','a',a(ii),'b',b(ii));
proportion_democrate(ii) = mean(beta_dist{ii});
end
but i dont know how to continue :(
thanks in advance
4 Comments
the cyclist
on 15 Jun 2023
Sorry, I didn't see that you had replied to my comment.
I did get a notification about the answer below, which looks helpful (although perhaps too late to help for your assignment).
Answers (1)
Rohit
on 15 Jun 2023
Hi,
I understand that you want to calculate probability of Democrats/Republicans winning the elections using CDF function of each Beta distribution.
The CDF of a probability distribution gives the probability that a random variable takes a value less than or equal to a certain value. In the case of the beta distribution, the CDF gives the probability that the true proportion of Democrats (or Republicans) in a given state is less than or equal to 0.5, based on the poll data. This is directly related to the probability that the Democrats (or Republicans) will win the upcoming elections in that state, since whoever gets more than 50% of the votes is the winner.
The code you have written is correct and you can follow that by using CDF to get probability as shown below:
% calculate beta distribution for each state
a = data.Democrat + 1;
b = data.Republican + 1;
beta_dist = cell(size(data,1),1);
proportion_democrat = zeros(size(data,1),1);
for ii=1:size(data,1)
beta_dist{ii} = makedist('beta','a',a(ii),'b',b(ii));
end
% calculate probability of Democrats winning each state
prob_Dem = zeros(size(data,1),1);
for ii=1:size(data,1)
prob_Dem(ii) = 1 - cdf(beta_dist{ii},0.5);
end
% calculate probability of Republicans winning each state
prob_Rep = 1 - prob_Dem;
You can learn more about CDF from this documentation link: https://in.mathworks.com/help/stats/prob.normaldistribution.cdf.html
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!