I have a little exercise to solve with Rstudio for my statistics exam. I tryed to translate it in english, so if something isn't clear please ask me for explanations.
"Simulate 100,000 births and use the following probabilities: males 51.3%, females 48.7%, using the sample function.
Check how much the number of males and females obtained differ from the theoretical percentages.
Draw the PMF and the CDF of the probability function of this experiment (on a sample of 50 births).
Calculate mean and variance of the distribution."
I obtained 51356 males and 48644 females, a difference of 56.
But now, How can I draw PMF and CDF of the probability function?
Here I put the code used to simulate the births:
mysample <- data.frame(sample(c("M","F"),100000,replace=T,prob=c(0.513,0.487)))
names(mysample)<-c("Gender")
males <- subset(mysample, Gender=="M")
females <- subset(mysample,Gender=="F")
theoricM <- 100000*0.513
theoricF <- 100000*0.487
realM <- as.integer(nrow(maschi))
realF <- as.integer(nrow(femmine))
#create a data frame to show differences
result <-data.frame(realM,theoricM,realF,theoricF)
names(result)<- c("Males","Theoric Males","Females","Theoric Females")
And results:
Hope someone could help me, I know it's a very easy question for someone experienced with R, but I'm at the very beginning with this language.
So thank you to everyone who will reply.
EDIT:
I tried this code:
x <- 1:50
plot(x,dbinom(x ,size = 50,prob = 0.513),type="l", ylab="PMF", main="Binomial Distribution PMF")
And the result is:
What I think I understand is that, being the prob very close to 1/2, on a set of 50 births the number of males will be very close to 25. Is what plot is showing? And, is this the correct way to do that?