# Edps 590BAY # Fall 2019 # C.J.Anderson # # Impact on Binomial of # (a) var x mean # (b) n with fixed p # (c) p or theta with fixed n # # Impact on Beta of # (d) a=b # (e) right skewed ab # # # Plot variance x mean of binomial distribution # par(mfrow=c(1,1)) p <- seq(from=0, to=1, length.out=1000) mu <- 20*p var <- 20*p*(1-p) plot(mu,var,type='l',main="Binomial n=20: variance x mean", xlim=c(0,20),xlab="Mean", ylab="Variance") # # Some example of binomial distributions # par(mfrow=c(2,2)) # (b) y10 <- seq(from=0, to=10) y20 <- seq(from=0, to=20) y50 <- seq(from=0, to=50) y100 <- seq(from=0, to=100) bin10 <- dbinom(y10,10,.5) bin20 <- dbinom(y20,20,.5) bin50 <- dbinom(y50,50,.5) bin100 <- dbinom(y100,100,.5) plot(y10,bin10, type='h', main="n=10, p=.5") plot(y20,bin20, type='h',main="n=20, p=.5") plot(y50,bin50, type='h', main="n=50, p=.5") plot(y100,bin100, type='h',main="n=100, p=.5") # (c) bin.1 <- dbinom(y20,20,.1) bin.3 <- dbinom(y20,20,.3) bin.7 <- dbinom(y20,20,.7) bin.95 <- dbinom(y20,20,.95) plot(y20,bin.1, type='h', main="n=20, p=.1") plot(y20,bin.3, type='h',main="n=20, p=.3") plot(y20,bin.7, type='h', main="n=20, p=.7") plot(y20,bin.95, type='h',main="n=20, p=.95") ################################################ # For beta and less typing, use function # ################################################ beta.plot <- function(a,b){ y <- seq(from=0, to=1, length.out=1000) beta.ab <- dbeta(y,a,b) plot(y,beta.ab,type='l',main=paste("Beta(",a,",",b,")"),lwd=2, ylab="Density", xlim=c(0,1)) } # # Examples of beta distribution # #(d) par(mfrow=c(2,2)) beta.plot(0.1,0.1) beta.plot(1,1) beta.plot(2,2) beta.plot(5,5) # (e) par(mfrow=c(2,2)) beta.plot(0.1,1) beta.plot(1,2) beta.plot(2,3) beta.plot(3,4) # (f) par(mfrow=c(2,2)) beta.plot(1,0.1) beta.plot(2,1) beta.plot(3,2) beta.plot(4,3) # (g) --- not in lecture notes par(mfrow=c(2,2)) beta.plot(.1,.1) beta.plot(.8,.8) beta.plot(.7,3) beta.plot(3,.7)