# p-value example fill.under.curve <- function( x1 , x2 , mean=0 , sd=3 , density=30 ) { xseq <- seq(from=x2,to=x1,by=(x1-x2)/10) x <- c( x1 , x2 , xseq ) y <- c( 0 , 0 , dnorm( xseq , mean=mean , sd=sd ) ) polygon( x , y , density=density ) } curve( dnorm( x , mean=0 , sd=3 ) , from=-14 , to=14 , xlab="estimate" , ylab="density" ) lines( c( 0,0 ) , c( 0 , dnorm(0,0,3) ) , lty=2 ) fill.under.curve( 5 , 14 ) # beta estimate example curve( dnorm( x , mean=5 , sd=2 ) , from=-14 , to=14 , xlab="estimate" , ylab="likelihood" ) curve( dnorm( x , mean=0 , sd=3 ) , from=-14 , to=14 , xlab="estimate" , ylab="likelihood" ,add=TRUE ) lines( c( 0,0 ) , c( 0 , dnorm(0,0,3) ) , lty=2 ) fill.under.curve( 5 , 14 ) fill.under.curve( 0 , -5 , mean=5 , sd=2 ) lines( c( 5,5 ) , c( 0 , dnorm(5,5,2) ) , lty=2 ) x <- rnorm(30) y <- 1 + 1/2*x + rnorm(30) m <- lm( y ~ x ) # coin example barplot( dbinom(0:10,size=10,prob=0.5) , names.arg=0:10 , xlab="heads observed" , ylab="likelihood | prob=0.5" , col=c(0,0,0,2,0,0,0,0,0,0,0) ) barplot( dbinom(0:10,size=10,prob=0.5) , names.arg=0:10 , xlab="heads observed" , ylab="likelihood | prob=0.5" , col=c(1,1,1,2,0,0,0,0,0,0,0) ) cols <- rep(0,21) cols[7] <- 2 cols[1:6] <- 1 barplot( dbinom(0:20,size=20,prob=0.5) , names.arg=0:20 , xlab="heads observed" , ylab="likelihood | prob=0.5" , col=cols ) cols <- rep(0,41) cols[14] <- 2 cols[1:13] <- 1 barplot( dbinom(0:40,size=40,prob=0.5) , names.arg=0:40 , xlab="heads observed" , ylab="likelihood | prob=0.5" , col=cols )