EBCHS is a package for the our new paper: An Empirical Bayes Method for Chi-Squared Data; please see the link: https://amstat.tandfonline.com/doi/full/10.1080/01621459.2020.1777137
You can install the development version from GitHub with:
# install.packages("devtools")
::install_github("dulilun/EBCHS") devtools
This is a basic example which shows you how to solve a common problem:
## basic example code
library(reshape2)
library(ggplot2)
library(EBCHS)
##############################################
set.seed(2020)
= 1000
p = 7
k # the prior distribution for lambda
= 2
alpha = 10
beta # lambda
= rep(0, p)
lambda = 0
pi_0 = floor(p*pi_0)
p_0 = p-p_0
p_1 +1):p] = rgamma(p_1, shape = alpha, rate=1/beta)
lambda[(p_0# Generate a Poisson RV
= sapply(1:p, function(x){rpois(1, lambda[x]/2)})
J = sapply(1:p, function(x){rchisq(1, k+2*J[x])})
X
############################################
= seq(0.01, 0.99, 0.01)
qq_set = EB_CS(X, k, qq=qq_set, method='LS', mixture = FALSE)
out # plot
= out$E_lambda
E = out$V_lambda
V = E+1.645*V^(1/2)
UP = E-1.645*V^(1/2)
LOW
= data.frame(cbind(X, LOW, E, UP))
Dat colnames(Dat)=c('X', 'lower', 'mean', 'upper')
<- melt(Dat, id="X")
df = ggplot(df)+geom_line(aes(x=X, y=value, color=variable))+
pp labs(title="Posterior Inteval")+ylim(c(-5, 80))+xlim(c(0, 100))
pp#> Warning: Removed 22 row(s) containing missing values (geom_path).