# world cup soccer 1994 # Edps 587 # C.J.Anderson # # Read in data # Plots histogram # Overlay Poisson distribution # # create data n.goals <- seq(from=0,to=7) counts <- c(20,29,16,3,1,0,1,0) mu <- weighted.mean(n.goals,counts) # Quick look at data barplot(counts, main="Goals Scored in 1st Round of 1994 World Cup", xlab="Number of Goals Scored", names.arg = c("0","1","2","3","4","5","6,","7+"), col="cyan" ) # To overlay predicted Poisson mu <- weighted.mean(n.goals,counts) d.poisson <- dpois(n.goals,mu) pred.goals <- d.poisson*sum(counts) # Data and predicted: version 1 plot(n.goals,counts, type="h", main="Goals Scored in 1st Round of 1994 World Cup", xlab="Number of Goals Scored", col="cyan" ) lines(n.goals,pred.goals,type="p") text(6,28,"mu=1.143") text(6,26.5,"total=70") # Data and predicted: version 2 barplot(counts, main="Goals Scored in 1st Round of 1994 World Cup", xlab="Number of Goals Scored", names.arg = c("0","1","2","3","4","5","6,","7+"), col="cyan" ) n.goals0 <- c(0.75, 1.9, 3.15, 4.25, 5.5, 6.75, 8.0 , 9.25) # to center points of number lines(n.goals0,pred.goals,type="b") text(8.25,28,"mu=1.143") text(8.25,26.5,"total=70")