# binomial for US presidential data # Edps 587 # C.J.Anderson # # Taller who won for elections 1932 - 2008 # # See http://en.wikipedia.org/wiki/Heights_of_United_States_Presidents_and_presidential_candidates # Read in data # Plots histogram # Overlay Poisson distribution # # # Plot of # Taller who won for elections 1932 - 2008 # See http://en.wikipedia.org/wiki/Heights_of_United_States_Presidents_and_presidential_candidates # Possible values for probability pi <- seq(0,1,.01) # Observations N <- 19 y <- 15 p <- y/N num <-length(pi) bincoeff <- factorial(N)/(factorial(y)*factorial(N-y)) binprob <- bincoeff * pi**y * (1-pi)**(N-y) plot(pi,binprob, type='l', main="Likelihood Function for Binomial", sub="Note that y=15, N=19, p=.79", xlab=expression(paste("Possible values of the probability ", pi)), ylab="Value of the Likelihood Function" ) lnL <- seq(0,max(binprob),.001) prop <- rep(p,length(lnL)) lines(prop,lnL)