# Supplement for Lovric and Dave: One-Sided Jeffreys-Lindley Behavior # Uses base R only. Run in a writable working directory with: source("JL_Paradox_OneSided_Supplement.R") # Numerical integration is done in the standardized coordinate u = sqrt(n)*theta. # Boundary theta0 = 0 and sampling SD sigma = 1 throughout. bf_slab <- function(n, p, prior = c("exponential", "half-normal", "uniform")) { prior <- match.arg(prior) z <- qnorm(1-p) density <- switch(prior, "exponential" = function(t) dexp(t, rate=1), "half-normal" = function(t) 2*dnorm(t), "uniform" = function(t) dunif(t, min=0, max=2)) upper <- if (prior == "uniform") 2*sqrt(n) else Inf f <- function(u) exp(z*u-u*u/2)*density(u/sqrt(n))/sqrt(n) integrate(f, lower=0, upper=upper, rel.tol=1e-10, subdivisions=1000L)$value } point_posterior <- function(n,p,prior) 1/(1+bf_slab(n,p,prior)) # With prior theta ~ N(0,1), posterior theta|xbar ~ N(n*xbar/(n+1),1/(n+1)). continuous_tail <- function(n,p) pnorm(-qnorm(1-p)*sqrt(n/(n+1))) # With prior 0.5 delta_0 + 0.5 N(0,1) the Bayes factor vs the atom is: bf_normal <- function(n,p) { z <- qnorm(1-p) 1/sqrt(n+1)*exp(n*z*z/(2*(n+1))) } atom_inclusive <- function(n,p) { z <- qnorm(1-p) b <- bf_normal(n,p) (1 + b*continuous_tail(n,p))/(1+b) } ns <- c(100,500,1000,5000,10000,50000,100000) table1 <- data.frame(n=ns, p=rep(.05,length(ns)), exponential=sapply(ns,point_posterior,p=.05,prior="exponential"), half_normal=sapply(ns,point_posterior,p=.05,prior="half-normal"), uniform_0_2=sapply(ns,point_posterior,p=.05,prior="uniform"), continuous_N01=sapply(ns,continuous_tail,p=.05), atom_half_N01=sapply(ns,atom_inclusive,p=.05)) print(round(table1,5),row.names=FALSE) write.csv(table1,"JL_Table1_values.csv",row.names=FALSE) ns2 <- c(100,1000,10000,100000) ps <- c(.10,.05,.01) table2 <- data.frame(n=ns2) for (p in ps) table2[[paste0("point_",p)]] <- sapply(ns2,point_posterior,p=p,prior="exponential") for (p in ps) table2[[paste0("tail_",p)]] <- sapply(ns2,continuous_tail,p=p) print(round(table2,5),row.names=FALSE) write.csv(table2,"JL_Table2_values.csv",row.names=FALSE) # Figure 2: match the figure in the revised manuscript. # Point-model posterior, continuous-prior left-tail probability, # and the fixed one-sided p = 0.05 horizontal reference line. # The boundary-atom posterior is still calculated for Table 1 above, # but is not plotted in Figure 2. png("JL_Figure2_reproduced.png",width=1400,height=850,res=160) plot(ns,table1$exponential,log="x",type="b",pch=19,lwd=2, xlab="Sample size n (log scale)",ylab="Posterior probability",ylim=c(0,1), main="Fixed one-sided p = 0.05: different Bayesian targets") lines(ns,table1$continuous_N01,lty=2,lwd=2) abline(h=0.05,lty=3,lwd=1) legend("right",legend=c("Point-model posterior (exponential slab)", "Continuous-prior tail", "One-sided p = 0.05"), lty=c(1,2,3),lwd=c(2,2,1),pch=c(19,NA,NA),bty="n") dev.off() # Figure 3: exact rejection probability of the right-sided z-test. mu <- seq(280,320,length.out=600) mu0 <- 300; sigma <- 15; n3 <- 25; alpha <- .05 power <- 1-pnorm(qnorm(1-alpha)-(mu-mu0)*sqrt(n3)/sigma) png("JL_Figure3_reproduced.png",width=1400,height=850,res=160) plot(mu,power,type="l",lwd=2,xlab="True mean mu",ylab="Rejection probability", main="One-sided z-test rejection probability") abline(v=mu0,lty=2);abline(h=alpha,lty=3) dev.off()