# learning the use of dbinom set.panel(1,1) xbin100 <- seq(0,100,1) print("examples of binomial distribution") print("N=100,p=.5") print(xbin100) print(dbinom(xbin100,100,.5)) readline() plot(30,.2, xlim=c(0,100), ylim=c(0,.2), type="n", col=1) lines(xbin100, dbinom(xbin100, 100, 0.5), type="h", col=2) readline() lines(xbin100, dbinom(xbin100,100,0.1), type="h", col=3) print("N=100,p=.1") readline() lines(xbin100, dbinom(xbin100,100,0.3), type="h", col=1) print("N=100,p=.3") readline() #### likelihood # N=100 trials; observed 30 'successes' print("suppose we observed 30 out of 100 draws") set.panel(1,1) plot(30,.2, xlim=c(0,100), ylim=c(0,.2), type="h", col=1) readline() lines(xbin100, dbinom(xbin100, 100, 0.5), type="h", col=2) print("N=100,p=.5") readline() lines(xbin100, dbinom(xbin100,100,0.1), type="h", col=3) print("N=100,p=.1") readline() lines(xbin100, dbinom(xbin100,100,0.3), type="h", col=1) print("N=100,p=.3")