diff --git a/.Rbuildignore b/.Rbuildignore
index 31f1dde..bd28d11 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -1,7 +1,6 @@
^.*\.Rproj$
^\.Rhistory$
^\.Rproj\.user$
-^\.travis\.yml$
^docs$
^_pkgdown\.yml$
^README\.Rmd$
@@ -11,3 +10,5 @@
^LICENSE\.md$
^NOTES\.md$
^CRAN-RELEASE$
+^\.github$
+^tools$
diff --git a/.github/.gitignore b/.github/.gitignore
new file mode 100644
index 0000000..2d19fc7
--- /dev/null
+++ b/.github/.gitignore
@@ -0,0 +1 @@
+*.html
diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml
new file mode 100644
index 0000000..73bfb21
--- /dev/null
+++ b/.github/workflows/R-CMD-check.yaml
@@ -0,0 +1,50 @@
+# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
+# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
+on:
+ push:
+ branches: [main, master]
+ pull_request:
+
+name: R-CMD-check.yaml
+
+permissions: read-all
+
+jobs:
+ R-CMD-check:
+ runs-on: ${{ matrix.config.os }}
+
+ name: ${{ matrix.config.os }} (${{ matrix.config.r }})
+
+ strategy:
+ fail-fast: false
+ matrix:
+ config:
+ - {os: macos-latest, r: 'release'}
+ - {os: windows-latest, r: 'release'}
+ - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
+ - {os: ubuntu-latest, r: 'release'}
+ - {os: ubuntu-latest, r: 'oldrel-1'}
+
+ env:
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+ R_KEEP_PKG_SOURCE: yes
+
+ steps:
+ - uses: actions/checkout@v6
+
+ - uses: r-lib/actions/setup-pandoc@v2
+
+ - uses: r-lib/actions/setup-r@v2
+ with:
+ r-version: ${{ matrix.config.r }}
+ http-user-agent: ${{ matrix.config.http-user-agent }}
+
+ - uses: r-lib/actions/setup-r-dependencies@v2
+ with:
+ extra-packages: any::rcmdcheck
+ needs: check
+
+ - uses: r-lib/actions/check-r-package@v2
+ with:
+ upload-snapshots: true
+ build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml
new file mode 100644
index 0000000..16c6c8b
--- /dev/null
+++ b/.github/workflows/pkgdown.yaml
@@ -0,0 +1,47 @@
+# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
+# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
+on:
+ push:
+ branches: [main, master]
+ pull_request:
+ release:
+ types: [published]
+ workflow_dispatch:
+
+name: pkgdown.yaml
+
+permissions: read-all
+
+jobs:
+ pkgdown:
+ runs-on: ubuntu-latest
+ # Only restrict concurrency for non-PR jobs
+ concurrency:
+ group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
+ env:
+ GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/checkout@v6
+
+ - uses: r-lib/actions/setup-pandoc@v2
+
+ - uses: r-lib/actions/setup-r@v2
+
+ - uses: r-lib/actions/setup-r-dependencies@v2
+ with:
+ extra-packages: any::pkgdown, local::.
+ needs: website
+
+ - name: Build site
+ run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
+ shell: Rscript {0}
+
+ - name: Deploy to GitHub pages 🚀
+ if: github.event_name != 'pull_request'
+ uses: JamesIves/github-pages-deploy-action@d92aa235d04922e8f08b40ce78cc5442fcfbfa2f # v4.8.0
+ with:
+ clean: false
+ branch: gh-pages
+ folder: docs
diff --git a/.gitignore b/.gitignore
index 5a1121e..c5a3e76 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
.Rproj.user
.RData
.Rhistory
+*~
+docs/
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 52bc8ae..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-language: r
-
-r:
- - release
- - devel
-cache: packages
-
-sudo: false
-
-notifications:
- email: false
diff --git a/DESCRIPTION b/DESCRIPTION
index a91506a..42d55c6 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: deconvolveR
Title: Empirical Bayes Estimation Strategies
-Version: 1.2-1
+Version: 1.2-2
VignetteBuilder: knitr
Suggests: cowplot, ggplot2, knitr, rmarkdown
Authors@R: c(person("Bradley", "Efron", role=c("aut"),
@@ -23,4 +23,4 @@ LazyData: true
Imports:
splines,
stats
-RoxygenNote: 7.1.0
+Config/roxygen2/version: 8.0.0
diff --git a/NEWS.md b/NEWS.md
index 6780ee9..ff6fb98 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,11 @@
+# deconvolveR 1.2-2
+
+- Fixed documentation markup flagged by CRAN (`checkRd` "Lost braces"
+ NOTE in `deconv.Rd`)
+- Switched CI from Travis to GitHub Actions; pkgdown site is now
+ built and deployed via GitHub Actions
+- Added a package logo and updated badges
+
# deconvolveR 1.2-1
- Fixed URL per CRAN
diff --git a/R/deconv.R b/R/deconv.R
index e928564..2ba3fc3 100644
--- a/R/deconv.R
+++ b/R/deconv.R
@@ -45,9 +45,9 @@
#' where it was referred to as \eqn{R(\alpha)}} \item{cov}{the
#' covariance matrix for the mle} \item{cov.g}{the covariance
#' matrix for the \eqn{g}} \item{stats}{an m by 6 or 7 matrix
-#' containing columns for \eqn{theta}, \eqn{g}, \eqn{\tilde{g}}
+#' containing columns for \eqn{\theta}, \eqn{g}, \eqn{\tilde{g}}
#' which is \eqn{g} with thinning correction applied and named
-#' \code{tg}, std. error of \eqn{g}, \eqn{G} (the cdf of {g}),
+#' \code{tg}, std. error of \eqn{g}, \eqn{G} (the cdf of \eqn{g}),
#' std. error of \eqn{G}, and the bias of \eqn{g}}
#' \item{loglik}{the negative log-likelihood function for the data
#' taking a \eqn{p}-vector argument} \item{statsFunction}{a
@@ -56,7 +56,7 @@
#' @section Details:
#' The data \code{X} is always required with two exceptions. In the Poisson case,
#' \code{y} alone may be specified and \code{X} omitted, in which case the sample space of
-#' the observations $\eqn{X}$ is assumed to be 1, 2, .., \code{length(y)}. The second exception is
+#' the observations \eqn{X} is assumed to be 1, 2, .., \code{length(y)}. The second exception is
#' for experimentation with other exponential families besides the three implemented here:
#' \code{y}, \code{P} and \code{Q} can be specified together.
#'
diff --git a/R/deconvolveR-package.R b/R/deconvolveR-package.R
index 4c73ca0..0377cf1 100644
--- a/R/deconvolveR-package.R
+++ b/R/deconvolveR-package.R
@@ -5,9 +5,6 @@
#' paper reference below and this package includes a vignette
#' containing a number of examples.
#'
-#' @docType package
-#' @name deconvolveR-package
-#'
#' @references Bradley Efron. Empirical Bayes Deconvolution
#' Estimates. Biometrika 103(1), 1-20, ISSN
#' 0006-3444. doi:10.1093/biomet/asv068.
@@ -19,7 +16,7 @@
#' Efron. deconvolveR: A G-Modeling Program for Deconvolution and
#' Empirical Bayes Estimation. doi:10.18637/jss.v094.i11
#'
-NULL
+"_PACKAGE"
#' Shakespeare word counts in the entire canon: 14,376 distinct words
#' appeared exactly once, 4343 words appeared twice etc.
diff --git a/README.md b/README.md
index ecf0fad..784761f 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,13 @@
-Empirical Bayes Deconvolution
-=============================
+# deconvolveR
-[](https://travis-ci.org/bnaras/deconvolveR)
-[](https://cran.r-project.org/package=deconvolveR)
+
+[](https://github.com/bnaras/deconvolveR/actions/workflows/R-CMD-check.yaml)
+[](https://cran.r-project.org/package=deconvolveR)
+[](https://cran.r-project.org/package=deconvolveR)
+[](https://cran.r-project.org/package=deconvolveR)
+
+
+## Empirical Bayes Deconvolution
An unknown prior density $g(\theta)$ has yielded (unobservable)
$\Theta_1, \Theta_2,\ldots,\Theta_N$, and each $\Theta_i$ produces an
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 872639f..7cae618 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -1,7 +1,11 @@
-authors:
+url: https://bnaras.github.io/deconvolveR/
- Balasubramanian Narasimhan:
- href: https://web.stanford.edu/~naras
+template:
+ bootstrap: 5
+ math-rendering: mathjax
+authors:
+ Balasubramanian Narasimhan:
+ href: https://naras.su.domains
Bradley Efron:
- href: http://statweb.stanford.edu/~ckirby/brad/
+ href: https://efron.ckirby.su.domains/
diff --git a/docs/404.html b/docs/404.html
deleted file mode 100644
index d65c6a2..0000000
--- a/docs/404.html
+++ /dev/null
@@ -1,160 +0,0 @@
-
-
-
-
vignettes/deconvolution.Rmd
- deconvolution.RmdWe start with a simulated Poisson example where the \(\Theta_i\) are drawn from a chi-squared density with 10 degrees of freedom and the \(X_i|\Theta_i\) are Poisson with expectation \(\Theta_i:\)
-\[ -\Theta_i \sim \chi^2_{10} \mbox{ and } X_i|\Theta_i \sim \mbox{Poisson}(\Theta_i) -\]
-The \(\Theta_i\) for this setting, with N = 1000 observations can be generated as follows.
Next, the \(X_i|\Theta_i\), for each of nSIM = 1000 simulations can be generated as below.
We take the discrete set \(\mathcal{T}=(1, 2, \ldots, 32)\) as the \(\Theta\)-space and apply the deconv function in the package deconvolveR to estimate \(g(\theta).\)
library(deconvolveR) -tau <- seq(1, 32) -results <- apply(data, 2, - function(x) deconv(tau = tau, X = x, ignoreZero = FALSE, - c0 = 1))
The default setting for deconv uses the Poisson family and a natural cubic spline basis of degree 5 as \(Q.\) The regularization parameter for this example (c0) is set to 1. The ignoreZero parameter indicates that this dataset contains zero counts, i.e., there zeros have not been truncated. (In the Shakespeare example below, the counts are of words seen in the canon, and so there is a natural truncation at zero.)
Some warnings are emitted by the nlm routine used for optimization, but they are mostly inconsequential.
Since deconv works on a sample at a time, the result above is a list of lists from which various statistics can be extracted. Below, we construct a table of values for various values of \(\Theta\).
g <- sapply(results, function(x) x$stats[, "g"]) -mean <- apply(g, 1, mean) -SE.g <- sapply(results, function(x) x$stats[, "SE.g"]) -sd <- apply(SE.g, 1, mean) -Bias.g <- sapply(results, function(x) x$stats[, "Bias.g"]) -bias <- apply(Bias.g, 1, mean) -gTheta <- pchisq(tau, df = 10) - pchisq(c(0, tau[-length(tau)]), df = 10) -gTheta <- gTheta / sum(gTheta) -simData <- data.frame(theta = tau, gTheta = gTheta, - Mean = mean, StdDev = sd, Bias = bias, - CoefVar = sd / mean) -table1 <- transform(simData, - gTheta = 100 * gTheta, - Mean = 100 * Mean, - StdDev = 100 * StdDev, - Bias = 100 * Bias)
The table below summarizes the results for some chosen values of \(\theta .\)
- -| theta | -gTheta | -Mean | -StdDev | -Bias | -CoefVar | -
|---|---|---|---|---|---|
| 5 | -5.6191465 | -5.4416722 | -0.3635378 | --0.1235865 | -0.0668063 | -
| 10 | -9.1646990 | -9.5316279 | -0.4917673 | -0.2588187 | -0.0515932 | -
| 15 | -4.0946148 | -3.3421426 | -0.3119862 | --0.0683187 | -0.0933492 | -
| 20 | -1.1014405 | -0.9810001 | -0.2246999 | --0.1225092 | -0.2290519 | -
| 25 | -0.2255788 | -0.1496337 | -0.0677919 | -0.0602422 | -0.4530522 | -
Although, the coefficient of variation of \(\hat{g}(\theta)\) is still large, the \(g(\theta)\) estimates are reasonable.
-We can compare the empirical standard deviations and biases of \(g(\hat{\alpha})\) with the approximation given by the formulas in the paper.
-library(ggplot2) -library(cowplot) -theme_set(theme_get() + - theme(panel.grid.major = element_line(colour = "gray90", - size = 0.2), - panel.grid.minor = element_line(colour = "gray98", - size = 0.5))) -p1 <- ggplot(data = as.data.frame(results[[1]]$stats)) + - geom_line(mapping = aes(x = theta, y = SE.g), color = "black", linetype = "solid") + - geom_line(mapping = aes(x = simData$theta, y = simData$StdDev), color = "red", linetype = "dashed") + - labs(x = expression(theta), y = "Std. Dev") - -p2 <- ggplot(data = as.data.frame(results[[1]]$stats)) + - geom_line(mapping = aes(x = theta, y = Bias.g), color = "black", linetype = "solid") + - geom_line(mapping = aes(x = simData$theta, y = simData$Bias), color = "red", linetype = "dashed") + - labs(x = expression(theta), y = "Bias") -plot_grid(plotlist = list(p1, p2), ncol = 2)

The approximation is quite good for the standard deviations, but a little too small for the biases.
-Here we are given the word counts for the entire Shakespeare canon in the data set bardWordCount. We assume the \(i\)th distinct word appeared \(X_i \sim Poisson(\Theta_i)\) times in the canon.
## num [1:100] 14376 4343 2292 1463 1043 ...
-We take the support set \(\mathcal{T}\) for \(\Theta\) to be equally spaced on the log-scale and the sample space for \(\mathcal{X}\) to be \((1,2,\ldots,100).\)
- -Using a regularization parameter of c0=2 we can deconvolve the data to get \(\hat{g}.\)
result <- deconv(tau = tau, y = bardWordCount, n = 100, c0=2) -stats <- result$stats
The plot below shows the Empirical Bayes deconvoluation estimates for the Shakespeare word counts.
-ggplot() + - geom_line(mapping = aes(x = lambda, y = stats[, "g"])) + - labs(x = expression(log(theta)), y = expression(g(theta)))

The quantity \(R(\alpha)\) in the paper (Efron, Biometrika 2015) can be extracted from the stats list; in this case for a regularization parameter of c0=2 we can print its value:
print(result$S)
## [1] 0.005534954
-The stats list contains other estimates quantities as well.
As noted in the paper citing this package, about 44 percent of the total mass of \(\hat{g}\) lies below \(\Theta = 1\), which is an underestimate. This can be corrected for by defining \[ -\tilde{g} = c_1\hat{g} / (1 - e^{-\theta_j}), -\] where \(c_1\) is the constant that normalizes \(\tilde{g}\).
-When there is truncation at zero, as is the case here, the deconvolveR package now returns an additional column in stats[, "tg"] which contains this correction for thinning. (The default invocation of deconv assumes zero truncation for the Poisson family, argument ignoreZero = FALSE).
d <- data.frame(lambda = lambda, g = stats[, "g"], tg = stats[, "tg"], SE.g = stats[, "SE.g"]) -indices <- seq(1, length(lambda), 5) -ggplot(data = d) + - geom_line(mapping = aes(x = lambda, y = g)) + - geom_errorbar(data = d[indices, ], - mapping = aes(x = lambda, ymin = g - SE.g, ymax = g + SE.g), - width = .01, color = "blue") + - labs(x = expression(log(theta)), y = expression(g(theta))) + - ylim(0, 0.006) + - geom_line(mapping = aes(x = lambda, y = tg), linetype = "dashed", color = "red")

We can now plot the posterior estimates.
-gPost <- sapply(seq_len(100), function(i) local({tg <- d$tg * result$P[i, ]; tg / sum(tg)})) -plots <- lapply(c(1, 2, 4, 8), function(i) { - ggplot() + - geom_line(mapping = aes(x = tau, y = gPost[, i])) + - labs(x = expression(theta), y = expression(g(theta)), - title = sprintf("x = %d", i)) -}) -plots <- Map(f = function(p, xlim) p + xlim(0, xlim), plots, list(6, 8, 14, 20)) -plot_grid(plotlist = plots, ncol = 2)

As a check, one can perform a parametric bootstrap using \[ -y^{*} \sim Mult_n(N, {\mathbf f}) -\] with the MLE \(\hat{\mathbf f} = {\mathbf f}(\hat{\alpha})\). We use 200 bootstrap replcates to compute the standard errors for \(\hat{g}\) and compare them to the theoretical values in the plot below. The agreement is pretty good.
-set.seed(1783) -B <- 200 -fHat <- as.numeric(result$P %*% d$g) -fHat <- fHat / sum(fHat) -yStar <- rmultinom(n = B, size = sum(bardWordCount), prob = fHat) -gBoot <- apply(yStar, 2, - function(y) deconv(tau = tau, y = y, n = 100, c0 = 2)$stats[, "g"]) -seG <- apply(gBoot, 1, sd) -ggplot(data = d) + - geom_line(mapping = aes(x = lambda, y = SE.g, - color = "Theoretical", linetype = "Theoretical")) + - geom_line(mapping = aes(x = lambda, y = seG, - color = "Bootstrap", linetype = "Bootstrap")) + - scale_color_manual(name = "Legend", - values = c("Bootstrap" = "black", "Theoretical" = "red")) + - scale_linetype_manual(name = "Legend", - values = c("Bootstrap" = "solid", "Theoretical" = "dashed")) + - theme(legend.title = element_blank()) + - labs(x = expression(log(theta)), y = expression(sigma(hat(g))))

Suppose then that a previously unknown Shakespearean corpus of length \(t\times C\) were found, \(C\times 900,000\) the length of the known canon. Assuming a Poisson process model with intensity \(\Theta_i\) for word \(i\), the probability that word \(i\) did not appear in the canon but does appear in the new corpus is \[ -e^{-\Theta_i}\left(1-e^{-\Theta_it}\right); -\] yielding after some work, an estimate for \(R(t)\), the expected number of distinct new words found, divided by \(N\), the observed number of distinct words in the canon: \[ -R(t)=\sum_{j=1}^m\hat{g}_jr_j(t), -\] with \[ -r_j=\frac{e^{-\theta_{(j)}}}{1-e^{-\theta_{(j)}}}\left(1-e^{-\theta_{(j)}t}\right). -\]
-We can compute the \(R(t)\) and plot it as follows.
-gHat <- stats[, "g"] -Rfn <- function(t) { - sum( gHat * (1 - exp(-tau * t)) / (exp(tau) - 1) ) -} -r <- sapply(0:10, Rfn) -ggplot() + - geom_line(mapping = aes(x = 0:10, y = r)) + - labs(x = "time multiple t", y = expression(R(t)))

And the (speculative) doubling time for Shakespeare’s vocabulary is easy to compute too.
- -## [1] 3.653132
-Consider a data set that is generated via the following mechanism.
-\[ -z_i \sim N(\mu_i, 1), \mbox{ $i = 1,2,\ldots, N = 10,000$} -\]
-with
-\[ -\mu_i= - \begin{cases} - 0, & \mbox{with probability .9}\\ - N(-3, 1), & \mbox{with probability .1}\\ - \end{cases} -\]
-set.seed(129023) -N <- 10000 -pi0 <- .90 -data <- local({ - nullCase <- (runif(N) <= pi0) - muAndZ <- t(sapply(nullCase, function(isNull) { - if (isNull) { - mu <- 0 - c(mu, rnorm(1)) - } else { - mu <- rnorm(1, mean = -3) - c(mu, rnorm(1, mean = mu)) - } - })) - data.frame(nullCase = nullCase, mu = muAndZ[, 1], z = muAndZ[, 2]) -})
Below is a histogram of the data (\(z\) values) and that of the \(\Theta\)s.
-p1 <- ggplot(mapping = aes(x = data$z)) + - geom_histogram(mapping = aes(y = ..count.. / sum(..count..) ), - color = "brown", bins = 60, alpha = 0.5) + - labs(x = "z", y = "Density") -p2 <- ggplot(mapping = aes(x = data$mu)) + - geom_histogram(mapping = aes(y = ..count.. / sum(..count..) ), - color = "brown", bins = 60, alpha = 0.5) + - labs(x = expression(theta), y = "Density") -plot_grid(plotlist = list(p1, p2), ncol = 2)

Now we deconvolve this using \(\mathcal{T} = (-6, -5.75,\ldots, 3)\) and a spike at zero and a fifth-degree polynomial.
-tau <- seq(from = -6, to = 3, by = 0.25) -atomIndex <- which(tau == 0) -result <- deconv(tau = tau, X = data$z, deltaAt = 0, family = "Normal", pDegree = 5)
The estimates and the standard errors of the penalized MLE \(\hat{g}\) with c0 = 1 are shown below.
knitr::kable(result$stats)
| theta | -g | -SE.g | -G | -SE.G | -Bias.g | -
|---|---|---|---|---|---|
| -6.00 | -0.0001755 | -0.0001139 | -0.0001755 | -0.0001139 | -0.0002100 | -
| -5.75 | -0.0003137 | -0.0001627 | -0.0004892 | -0.0002764 | -0.0002944 | -
| -5.50 | -0.0005542 | -0.0002188 | -0.0010434 | -0.0004943 | -0.0003817 | -
| -5.25 | -0.0009558 | -0.0002710 | -0.0019991 | -0.0007611 | -0.0004355 | -
| -5.00 | -0.0015902 | -0.0003068 | -0.0035893 | -0.0010496 | -0.0003936 | -
| -4.75 | -0.0025218 | -0.0003396 | -0.0061111 | -0.0013181 | -0.0001835 | -
| -4.50 | -0.0037665 | -0.0004384 | -0.0098775 | -0.0015480 | --0.0002271 | -
| -4.25 | -0.0052352 | -0.0006237 | -0.0151127 | -0.0017954 | --0.0007502 | -
| -4.00 | -0.0067030 | -0.0007782 | -0.0218157 | -0.0021384 | --0.0011392 | -
| -3.75 | -0.0079323 | -0.0008168 | -0.0297481 | -0.0025338 | --0.0011786 | -
| -3.50 | -0.0087575 | -0.0007875 | -0.0385055 | -0.0028572 | --0.0008249 | -
| -3.25 | -0.0091050 | -0.0008190 | -0.0476105 | -0.0030494 | --0.0001984 | -
| -3.00 | -0.0089988 | -0.0009356 | -0.0566093 | -0.0031703 | -0.0004827 | -
| -2.75 | -0.0085341 | -0.0010240 | -0.0651434 | -0.0033244 | -0.0009991 | -
| -2.50 | -0.0078394 | -0.0010049 | -0.0729829 | -0.0035304 | -0.0012035 | -
| -2.25 | -0.0070391 | -0.0009187 | -0.0800220 | -0.0036975 | -0.0010485 | -
| -2.00 | -0.0062096 | -0.0009410 | -0.0862316 | -0.0037737 | -0.0006476 | -
| -1.75 | -0.0053923 | -0.0011197 | -0.0916239 | -0.0038631 | -0.0001722 | -
| -1.50 | -0.0046182 | -0.0013216 | -0.0962421 | -0.0041634 | --0.0002559 | -
| -1.25 | -0.0039083 | -0.0014443 | -0.1001503 | -0.0047866 | --0.0005669 | -
| -1.00 | -0.0032743 | -0.0014544 | -0.1034247 | -0.0056648 | --0.0007344 | -
| -0.75 | -0.0027209 | -0.0013594 | -0.1061456 | -0.0066420 | --0.0007631 | -
| -0.50 | -0.0022468 | -0.0011884 | -0.1083923 | -0.0075782 | --0.0006763 | -
| -0.25 | -0.0018442 | -0.0009889 | -0.1102365 | -0.0083898 | --0.0005154 | -
| 0.00 | -0.8846685 | -0.0103603 | -0.9949050 | -0.0032481 | --0.0007798 | -
| 0.25 | -0.0012121 | -0.0006634 | -0.9961171 | -0.0026657 | --0.0001414 | -
| 0.50 | -0.0009670 | -0.0005580 | -0.9970841 | -0.0021484 | -0.0000199 | -
| 0.75 | -0.0007616 | -0.0004773 | -0.9978457 | -0.0016891 | -0.0001464 | -
| 1.00 | -0.0005909 | -0.0004069 | -0.9984366 | -0.0012899 | -0.0002343 | -
| 1.25 | -0.0004510 | -0.0003385 | -0.9988876 | -0.0009551 | -0.0002847 | -
| 1.50 | -0.0003383 | -0.0002718 | -0.9992259 | -0.0006855 | -0.0003024 | -
| 1.75 | -0.0002500 | -0.0002114 | -0.9994759 | -0.0004756 | -0.0002951 | -
| 2.00 | -0.0001824 | -0.0001602 | -0.9996583 | -0.0003163 | -0.0002713 | -
| 2.25 | -0.0001318 | -0.0001191 | -0.9997901 | -0.0001977 | -0.0002386 | -
| 2.50 | -0.0000945 | -0.0000875 | -0.9998846 | -0.0001104 | -0.0002027 | -
| 2.75 | -0.0000674 | -0.0000639 | -0.9999520 | -0.0000466 | -0.0001677 | -
| 3.00 | -0.0000480 | -0.0000466 | -1.0000000 | -0.0000000 | -0.0001360 | -
Per the above table, the estimated probability of \(\mu = 0\) is 0.885 \(\pm\) 0.01 with a bias of about -0.001.
-We can now plot the \(g\)-estimate removing the atom at 0.
-gData <- as.data.frame(result$stats[-atomIndex, c("theta", "g")]) -gData$g <- gData$g / sum(gData$g) -ggplot(data = gData) + - geom_line(mapping = aes(x = theta, y = g)) + - geom_line(mapping = aes(x = theta, y = dnorm(theta, mean = -3)), - color = "red") + - labs(x = expression(theta), y = expression(g(theta)))

The density approximation is not accurate at all, however, the posterior estimates for the g’s are similar to what one obtains by the Benjamini-Yekutieli procedure as shown below.
-## FCR -q <- 0.05 -R <- max(which(p <= seq_len(N) * q / N)) -discIdx <- orderP[1:R] -disc <- data[discIdx, ] -cat("BY_q procedure discoveries", R, "cases,", sum(disc$nullCase), - "actual nulls among them.\n")
## BY_q procedure discoveries 610 cases, 22 actual nulls among them.
-alphaR <- 1 - R * q / N -zAlpha <- qnorm(alphaR, lower.tail = FALSE) -zMarker <- max(disc$z) -xlim <- c(-7.6, 0.0) -ylim <- c(-10, 0.0) -BY.lo <- c(xlim[1] - zAlpha, xlim[2] - zAlpha) -BY.up <- c(xlim[1] + zAlpha, xlim[2] + zAlpha) -Bayes.lo <- c(0.5 * (xlim[1] - 3) - 1.96 / sqrt(2), 0.5 * (xlim[2] - 3) - 1.96 / sqrt(2)) -Bayes.up <- c(0.5 * (xlim[1] - 3) + 1.96 / sqrt(2), 0.5 * (xlim[2] - 3) + 1.96 / sqrt(2))
d <- data[order(data$mu), ] -muVals <- unique(d$mu) -s <- as.data.frame(result$stats) -indices <- findInterval(muVals, s$theta) + 1 -gMu <- s$g[indices] -st <- seq(min(data$z), -2.0, length.out = 40) -gMuPhi <- sapply(st, function(z) gMu * dnorm(z - muVals)) -g2 <- apply(gMuPhi, 2, function(x) cumsum(x)/sum(x)) -pct <- apply(g2, 2, function(dist) approx(y = muVals, x = dist, xout = c(0.025, 0.975))) -qVals <- sapply(pct, function(item) item$y)
ggplot() + - geom_line(mapping = aes(x = xlim, y = BY.lo), color = "blue") + - geom_line(mapping = aes(x = xlim, y = BY.up), color = "blue") + - geom_line(mapping = aes(x = xlim, y = Bayes.lo), color = "magenta", - linetype = "dashed") + - geom_line(mapping = aes(x = xlim, y = Bayes.up), color = "magenta", - linetype = "dashed") + - geom_point(mapping = aes(x = disc$z, y = disc$mu), color = "red") + - geom_point(mapping = aes(x = disc$z[disc$nullCase], y = disc$mu[disc$nullCase]), - color = "orange") + - geom_line(mapping = aes(x = rep(zMarker, 2), y = c(-10, 1))) + - geom_line(mapping = aes(x = st, y = qVals[1, ]), color = "brown") + - geom_line(mapping = aes(x = st, y = qVals[2, ]), color = "brown") + - labs(x = "Observed z", y = expression(mu)) + - annotate("text", x = -1, y = -4.25, label = "BY.lo") + - annotate("text", x = -1, y = 1.25, label = "BY.up") + - annotate("text", x = -7.5, y = -6.1, label = "Bayes.lo") + - annotate("text", x = -7.5, y = -3.4, label = "Bayes.up") + - annotate("text", x = -2.0, y = -1.75, label = "EB.lo") + - annotate("text", x = -2.0, y = -3.9, label = "EB.up") + - annotate("text", x = zMarker, y = 1.25, label = as.character(round(zMarker, 2)))

In the first normal example, the \(\theta\) distribution had a significant atom at 0 and the rest of the density was smeared around -3. We now investigate what happens when the \(\theta\) distribution is clearly bimodal. Below is a histogram of the the \(\theta\) and alongside a histogram of the data, generated using \(X_i \sim N(\theta_i, 1)\).
-p1 <- ggplot(mapping = aes(x = disjointTheta)) + - geom_histogram(mapping = aes(y = ..count.. / sum(..count..) ), - color = "brown", bins = 60, alpha = 0.5) + - labs(x = expression(theta), y = "Density") -set.seed (2332) -z <- rnorm(n = length(disjointTheta), mean = disjointTheta) -p2 <- ggplot(mapping = aes(x = z)) + - geom_histogram(mapping = aes(y = ..count.. / sum(..count..) ), - color = "brown", bins = 60, alpha = 0.5) + - labs(x = "z", y = "Density") -plot_grid(plotlist = list(p1, p2), ncol = 2)

We deconvolve the data, using various values for the spline degrees of freedom.
-tau <- seq(from = -4, to = 6, by = 0.2) -plots1 <- lapply(2:8, - function(p) { - result <- deconv(tau = tau, X = z, family = "Normal", pDegree = p) - g <- result$stats[, "g"] - ggplot(mapping = aes(x = disjointTheta)) + - geom_histogram(mapping = aes(y = ..count.. / sum(..count..)), - color = "brown", bins = 60, alpha = 0.2) + - geom_line(mapping = aes(x = tau, y = g), color = "blue") + - labs(x = expression(theta), y = "Density", - title = sprintf("DF = %d", p)) - })
Choosing the degrees of freedom to be 7, we now examine the effect of regularization parameter \(c0\).
-plots2 <- lapply(c(0.5, 1, 2, 4, 8, 16, 32), - function(c0) { - result <- deconv(tau = tau, X = z, family = "Normal", pDegree = 6, - c0 = c0) - g <- result$stats[, "g"] - ggplot(mapping = aes(x = disjointTheta)) + - geom_histogram(mapping = aes(y = ..count.. / sum(..count..)), - color = "brown", bins = 60, alpha = 0.2) + - geom_line(mapping = aes(x = tau, y = g), color = "blue") + - labs(x = expression(theta), y = "Density", - title = sprintf("C0 = %.1f", c0)) - }) -plots <- mapply(function(x, y) list(x, y), plots1, plots2) -plot_grid(plotlist = plots, ncol = 2)

The quantity \(S(\alpha)\) is a measure of the strength of the penalty term \(c_0\) and is returned by deconv in the result list as a named item S. Below we vary \(c_0\) and degrees of freedom from 5 to 7 to gauge the effect of the regularization.
c0_values <- c(.5, 1, 2, 4, 8, 16, 32) -stable <- data.frame( - c0 = c0_values, - `DF 5` = sapply(c0_values, function(c0) deconv(tau = tau, X = z, family = "Normal", pDegree = 5, c0 = c0)$S), - `DF 6` = sapply(c0_values, function(c0) deconv(tau = tau, X = z, family = "Normal", pDegree = 6, c0 = c0)$S), - `DF 7` = sapply(c0_values, function(c0) deconv(tau = tau, X = z, family = "Normal", pDegree = 7, c0 = c0)$S) -) -knitr::kable(stable)
| c0 | -DF.5 | -DF.6 | -DF.7 | -
|---|---|---|---|
| 0.5 | -0.0010381 | -0.0013048 | -0.0018553 | -
| 1.0 | -0.0029450 | -0.0034142 | -0.0042665 | -
| 2.0 | -0.0082974 | -0.0090723 | -0.0102037 | -
| 4.0 | -0.0236310 | -0.0248144 | -0.0257369 | -
| 8.0 | -0.0685852 | -0.0708393 | -0.0697542 | -
| 16.0 | -0.1915350 | -0.2039325 | -0.2025109 | -
| 32.0 | -0.4831292 | -0.5385301 | -0.5698289 | -
A DF of 6 or 7 captures the bimodality and a choice of \(c_0 < 4\) would avoid excessive penalization.
-The dataset surg contains data on intestinal surgery on 844 cancer patients. In the study, surgeons removed satellite nodes for later testing. The data consists of pairs \((n_i, X_i)\) where \(n_i\) is the number of satellites removed and \(X_i\) is the number found to be malignant among them.
We assume a binomial model with \(X_i \sim Binomial(n_i, \theta_i)\) with \(\theta_i\) being the probability of any one satellite site being malignant for the \(i\)th patient.
-We take \(\mathcal{T} = (0.01, 0.02,\ldots, 0.09)\), so \(m = 99.\) We take \(Q\) to be the default 5-degree natural spline with columns standardized to mean 0 and sum of squares equal to 1. The penalization parameter is set to 1. The figure below shows the estimated prior density of \(g(\theta)\).
-tau <- seq(from = 0.01, to = 0.99, by = 0.01) -result <- deconv(tau = tau, X = surg, family = "Binomial", c0 = 1) -d <- data.frame(result$stats) -indices <- seq(5, 99, 5) -errorX <- tau[indices] -ggplot() + - geom_line(data = d, mapping = aes(x = tau, y = g)) + - geom_errorbar(data = d[indices, ], - mapping = aes(x = theta, ymin = g - SE.g, ymax = g + SE.g), - width = .01, color = "blue") + - labs(x = expression(theta), y = expression(paste(g(theta), " +/- SE")))

The complete table of estimates and standard errors is also available.
-knitr::kable(d[indices, ], row.names = FALSE)
| theta | -g | -SE.g | -G | -SE.G | -Bias.g | -
|---|---|---|---|---|---|
| 0.05 | -0.0463457 | -0.0015738 | -0.4000686 | -0.0187280 | --0.0001386 | -
| 0.10 | -0.0151816 | -0.0014905 | -0.5227891 | -0.0179368 | -0.0005557 | -
| 0.15 | -0.0063608 | -0.0009530 | -0.5679756 | -0.0177951 | -0.0004028 | -
| 0.20 | -0.0039081 | -0.0006332 | -0.5910638 | -0.0182757 | -0.0002736 | -
| 0.25 | -0.0038724 | -0.0005167 | -0.6098155 | -0.0187490 | -0.0002012 | -
| 0.30 | -0.0053573 | -0.0005917 | -0.6330463 | -0.0188231 | -0.0000993 | -
| 0.35 | -0.0082256 | -0.0010482 | -0.6679794 | -0.0180358 | --0.0001306 | -
| 0.40 | -0.0111402 | -0.0015163 | -0.7184355 | -0.0170109 | --0.0004107 | -
| 0.45 | -0.0111343 | -0.0011809 | -0.7755223 | -0.0167801 | --0.0003743 | -
| 0.50 | -0.0086588 | -0.0009940 | -0.8242825 | -0.0155204 | --0.0000980 | -
| 0.55 | -0.0058962 | -0.0010407 | -0.8590792 | -0.0135817 | -0.0001197 | -
| 0.60 | -0.0039564 | -0.0008251 | -0.8823476 | -0.0125338 | -0.0002037 | -
| 0.65 | -0.0028839 | -0.0005341 | -0.8986379 | -0.0120984 | -0.0002143 | -
| 0.70 | -0.0023398 | -0.0004140 | -0.9112647 | -0.0114461 | -0.0002039 | -
| 0.75 | -0.0021301 | -0.0004763 | -0.9222208 | -0.0103935 | -0.0001911 | -
| 0.80 | -0.0021935 | -0.0005645 | -0.9329514 | -0.0092023 | -0.0001796 | -
| 0.85 | -0.0025512 | -0.0005742 | -0.9448671 | -0.0082261 | -0.0001632 | -
| 0.90 | -0.0032568 | -0.0005083 | -0.9595831 | -0.0072551 | -0.0001253 | -
| 0.95 | -0.0044141 | -0.0007505 | -0.9791329 | -0.0048537 | -0.0000355 | -
The empirical Bayes estimate of the prior distribution puts most of its mass on the small values as can be seem below.
- -## Mass below .20 = 0.59
-
-## Mass above .80 = 0.07
-The posterior distribution of \(\theta_i\) given \((n_i, X_i)\) is computed using Bayes rule as
-\[ -\hat{g} (\theta | X_i = x_i, n_i) = - \frac{g_{\hat{\alpha}} (\theta) {n_i \choose x_i} - \theta^{x_i} (1 - \theta)^{n_i-x_i}} {f_{\hat{\alpha}}(n_i, x_i)} -\]
-where the denominator is given by
-\[ -f_\alpha(n_i, x_i) = \int_0^1{n_i \choose x_i} - \theta^{x_i}(1-\theta)^{n_i-x_i}g_\alpha(\theta)\,d\theta. -\]
-with the mle \(\hat{\alpha}\) in place of \(\alpha\).
-Since \(g(\theta)\) is discrete, the integrals are mere sums as shown below.
-theta <- result$stats[, 'theta'] -gTheta <- result$stats[, 'g'] - -f_alpha <- function(n_k, x_k) { - ## .01 is the delta_theta in the Riemann sum - sum(dbinom(x = x_k, size = n_k, prob = theta) * gTheta) * .01 -} - -g_theta_hat <- function(n_k, x_k) { - gTheta * dbinom(x = x_k, size = n_k, prob = theta) / f_alpha(n_k, x_k) -}
We plot a few posterior distributions.
-g1 <- g_theta_hat(x_k = 7, n_k = 32) -g2 <- g_theta_hat(x_k = 3, n_k = 6) -g3 <- g_theta_hat(x_k = 17, n_k = 18) - -ggplot() + - geom_line(mapping = aes(x = theta, y = g1), col = "magenta") + - ylim(0, 10) + - geom_line(mapping = aes(x = theta, y = g2), col = "red") + - geom_line(mapping = aes(x = theta, y = g3), col = "blue") + - labs(x = expression(theta), y = expression(g(paste(theta, "|(x, n)")))) + - annotate("text", x = 0.15, y = 4.25, label = "x=7, n=32") + - annotate("text", x = 0.425, y = 4.25, label = "x=3, n=6") + - annotate("text", x = 0.85, y = 7.5, label = "x=17, n=18")

The empirical Bayes posterior estimate \(\theta^{EB}\) for patients 34, 40, and 679 in the dataset for example is
- -## Empirical Bayes Estimate: 0.453516
-As a check on the estimates of standard error and bias provided by deconv, we compare the results with what we obtain using a parametric boostrap.
The boostrap is run as follows. For each of 1000 runs, 844 simulated realizations \(\hat{\Theta}^*\) are sampled from density \(\hat{g}.\) Each gave an \(X_i^* \sim Binomial(n_i, \Theta_i^*)\) with \(n_i\) the \(i\)th sample in the original data set. Finally, \(\hat{\alpha}\) was computed using deconv.
set.seed(32776) -B <- 1000 -gHat <- d$g -N <- nrow(surg) - -genBootSample <- function() { - thetaStar <- sample(tau, size = N, replace = TRUE, prob = gHat) - sStar <- sapply(seq_len(N), - function(i) - rbinom(n = 1 , size = surg$n[i], prob = thetaStar[i])) - data.frame(n = surg$n, s = sStar) -} - -bootResults <- lapply(seq_len(B), - function(k) { - surgBoot <- genBootSample() - mat <- deconv(tau = tau, X = surgBoot, family = "Binomial", - c0 = 1)$stats - mat[, c("g", "Bias.g")] - }) - -gBoot <- sapply(bootResults, function(x) x[, 1]) -BiasBoot <- sapply(bootResults, function(x) x[, 2]) - -indices <- c(seq(1, 99, 11), 99) - -table2 <- data.frame(theta = tau, - gTheta = round(gHat * 100, 3), - sdFormula = round(d$SE.g * 100, 3), - sdSimul = round(apply(gBoot, 1, sd) * 100, 3), - BiasFormula = round(d$Bias.g * 100, 3), - BiasSimul = round(apply(BiasBoot, 1, mean) * 100, 3))[ indices, ]
We print out some estimated quantities for comparison.
-knitr::kable(table2, row.names = FALSE)
| theta | -gTheta | -sdFormula | -sdSimul | -BiasFormula | -BiasSimul | -
|---|---|---|---|---|---|
| 0.01 | -12.326 | -0.870 | -0.911 | --0.482 | --0.543 | -
| 0.12 | -1.033 | -0.127 | -0.135 | -0.051 | -0.058 | -
| 0.23 | -0.369 | -0.054 | -0.061 | -0.023 | -0.027 | -
| 0.34 | -0.757 | -0.093 | -0.091 | --0.007 | --0.008 | -
| 0.45 | -1.113 | -0.118 | -0.113 | --0.037 | --0.036 | -
| 0.56 | -0.543 | -0.102 | -0.097 | -0.015 | -0.016 | -
| 0.67 | -0.262 | -0.046 | -0.049 | -0.021 | -0.024 | -
| 0.78 | -0.213 | -0.053 | -0.050 | -0.018 | -0.018 | -
| 0.89 | -0.308 | -0.052 | -0.046 | -0.014 | -0.013 | -
| 0.99 | -0.575 | -0.158 | -0.157 | --0.010 | --0.014 | -
An unknown prior density g(θ) has yielded (unobservable) Θ1, Θ2, …, ΘN, and each Θi produces an observation Xi from an exponential family. deconvolveR is an R package for estimating prior distribution g(θ) from the data using Empirical Bayes deconvolution.
Details and examples may be found in the paper by Narasimhan and Efron, 2020. A vignette with further examples is also provided.
-NEWS.md
- R/deconvolveR-package.R
- bardWordCount.RdShakespeare word counts in the entire canon: 14,376 distinct words -appeared exactly once, 4343 words appeared twice etc.
-data(bardWordCount)- - -
Bradley Efron and Ronald Thisted. Estimating the number of -unseen species: How many words did Shakespeare know? Biometrika, Vol 63(3), -doi:10.1093/biomet/63.3.435.
- -R/deconv.R
- deconv.RdA function to compute Empirical Bayes estimates using deconvolution
-deconv( - tau, - X, - y, - Q, - P, - n = 40, - family = c("Poisson", "Normal", "Binomial"), - ignoreZero = TRUE, - deltaAt = NULL, - c0 = 1, - scale = TRUE, - pDegree = 5, - aStart = 1, - ... -)- -
| tau | -a vector of (implicitly m) discrete support points for -\(\theta\). For the Poisson and normal families, \(\theta\) -is the mean parameter and for the binomial, it is the -probability of success. |
-
|---|---|
| X | -the vector of sample values: a vector of counts for -Poisson, a vector of z-scores for Normal, a 2-d matrix with -rows consisting of pairs, (trial size \(n_i\), number of -successes \(X_i\)) for Binomial. See details below |
-
| y | -the multinomial counts. See details below |
-
| Q | -the Q matrix, implies y and P are supplied as well; see -details below |
-
| P | -the P matrix, implies Q and y are supplied as well; see -details below |
-
| n | -the number of support points for X. Applies only to
-Poisson and Normal. In the former, implies that support of X is
-1 to n or 0 to n-1 depending on the |
-
| family | -the exponential family, one of |
-
| ignoreZero | -if the zero values should be ignored (default =
- |
-
| deltaAt | -the theta value where a delta function is desired
-(default |
-
| c0 | -the regularization parameter (default 1) |
-
| scale | -if the Q matrix should be scaled so that the spline
-basis has mean 0 and columns sum of squares to be one, (default
- |
-
| pDegree | -the degree of the splines to use (default 5). In -notation used in the references below, \(p\) = pDegree + 1 |
-
| aStart | -the starting values for the non-linear optimization, -default is a vector of 1s |
-
| ... | -further args to function |
-
a list of 9 items consisting of
-the maximum - likelihood estimate \(\hat{\alpha}\)
the m by p - matrix Q
the n by m matrix P
the ratio of - artificial to genuine information per the reference below, - where it was referred to as \(R(\alpha)\)
the - covariance matrix for the mle
the covariance - matrix for the \(g\)
an m by 6 or 7 matrix
- containing columns for \(theta\), \(g\), \(\tilde{g}\)
- which is \(g\) with thinning correction applied and named
- tg, std. error of \(g\), \(G\) (the cdf of g),
- std. error of \(G\), and the bias of \(g\)
the negative log-likelihood function for the data - taking a \(p\)-vector argument
a - function to compute the statistics returned above
The data X is always required with two exceptions. In the Poisson case,
-y alone may be specified and X omitted, in which case the sample space of
-the observations $\(X\)$ is assumed to be 1, 2, .., length(y). The second exception is
-for experimentation with other exponential families besides the three implemented here:
-y, P and Q can be specified together.
Note also that in the Poisson case where there is zero truncation,
-the stats matrix has an additional column "tg" which
-accounts for the thinning correction induced by the truncation. See
-vignette for details.
Bradley Efron. Empirical Bayes Deconvolution Estimates. Biometrika 103(1), 1-20, -ISSN 0006-3444. doi:10.1093/biomet/asv068. -http://biomet.oxfordjournals.org/content/103/1/1.full.pdf+html
-Bradley Efron and Trevor Hastie. Computer Age Statistical Inference. -Cambridge University Press. ISBN 978-1-1-7-14989-2. Chapter 21.
- --set.seed(238923) ## for reproducibility -N <- 1000 -theta <- rchisq(N, df = 10) -X <- rpois(n = N, lambda = theta) -tau <- seq(1, 32) -result <- deconv(tau = tau, X = X, ignoreZero = FALSE) -print(result$stats)#> theta g SE.g G SE.G Bias.g -#> [1,] 1 0.0051481615 0.0016525341 0.005148161 1.652534e-03 8.541487e-04 -#> [2,] 2 0.0098958954 0.0023381444 0.015044057 3.986483e-03 1.099087e-03 -#> [3,] 3 0.0185198134 0.0029466370 0.033563870 6.895555e-03 1.102607e-03 -#> [4,] 4 0.0328530174 0.0032249075 0.066416888 9.873512e-03 4.812427e-04 -#> [5,] 5 0.0537835715 0.0036693678 0.120200459 1.224156e-02 -1.090720e-03 -#> [6,] 6 0.0791112606 0.0056206577 0.199311720 1.425433e-02 -3.316963e-03 -#> [7,] 7 0.1017934505 0.0077509950 0.301105170 1.743623e-02 -4.781816e-03 -#> [8,] 8 0.1121459629 0.0073194510 0.413251133 2.110274e-02 -3.712078e-03 -#> [9,] 9 0.1076955317 0.0051046274 0.520946665 2.259374e-02 -5.759912e-04 -#> [10,] 10 0.0934081064 0.0049730965 0.614354771 2.125191e-02 2.609017e-03 -#> [11,] 11 0.0758233573 0.0063169145 0.690178128 1.862765e-02 4.426107e-03 -#> [12,] 12 0.0596913949 0.0066510289 0.749869523 1.672495e-02 4.632921e-03 -#> [13,] 13 0.0472247251 0.0058223171 0.797094249 1.624772e-02 3.649927e-03 -#> [14,] 14 0.0388249870 0.0043740118 0.835919236 1.627164e-02 1.933483e-03 -#> [15,] 15 0.0332241328 0.0031665912 0.869143368 1.566917e-02 -3.121847e-05 -#> [16,] 16 0.0289251034 0.0030459927 0.898068472 1.404924e-02 -1.798007e-03 -#> [17,] 17 0.0250253380 0.0036190550 0.923093810 1.171550e-02 -3.024715e-03 -#> [18,] 18 0.0210171384 0.0039132116 0.944110948 9.419157e-03 -3.448033e-03 -#> [19,] 19 0.0167363462 0.0035333178 0.960847294 7.853539e-03 -2.991447e-03 -#> [20,] 20 0.0123508104 0.0026193414 0.973198105 6.965651e-03 -1.879392e-03 -#> [21,] 21 0.0084417110 0.0017508155 0.981639816 6.220128e-03 -6.879592e-04 -#> [22,] 22 0.0054981488 0.0012927504 0.987137965 5.413467e-03 1.279342e-04 -#> [23,] 23 0.0035175978 0.0010712165 0.990655562 4.617829e-03 5.320583e-04 -#> [24,] 24 0.0022788319 0.0008958692 0.992934394 3.919108e-03 6.645066e-04 -#> [25,] 25 0.0015410174 0.0007350941 0.994475412 3.340415e-03 6.679252e-04 -#> [26,] 26 0.0011212384 0.0006048170 0.995596650 2.858930e-03 6.345106e-04 -#> [27,] 27 0.0008930759 0.0005149033 0.996489726 2.434629e-03 6.091289e-04 -#> [28,] 28 0.0007695787 0.0004644742 0.997259305 2.029782e-03 6.030704e-04 -#> [29,] 29 0.0007062477 0.0004516035 0.997965553 1.611586e-03 6.169472e-04 -#> [30,] 30 0.0006794627 0.0004755882 0.998645015 1.150613e-03 6.487035e-04 -#> [31,] 31 0.0006745962 0.0005341491 0.999319611 6.204563e-04 6.948837e-04 -#> [32,] 32 0.0006803885 0.0006204563 1.000000000 1.706969e-10 7.501296e-04## -## Twin Towers Example -## See Brad Efron: Bayes, Oracle Bayes and Empirical Bayes -## disjointTheta is provided by deconvolveR package -theta <- disjointTheta; N <- length(disjointTheta) -z <- rnorm(n = N, mean = disjointTheta) -tau <- seq(from = -4, to = 5, by = 0.2) -result <- deconv(tau = tau, X = z, family = "Normal", pDegree = 6) -g <- result$stats[, "g"] -if (require("ggplot2")) { - ggplot() + - geom_histogram(mapping = aes(x = disjointTheta, y = ..count.. / sum(..count..) ), - color = "blue", fill = "red", bins = 40, alpha = 0.5) + - geom_histogram(mapping = aes(x = z, y = ..count.. / sum(..count..) ), - color = "brown", bins = 40, alpha = 0.5) + - geom_line(mapping = aes(x = tau, y = g), color = "black") + - labs(x = paste(expression(theta), "and x"), y = paste(expression(g(theta)), " and f(x)")) -}#>-
R/deconvolveR-package.R
- deconvolveR-package.RddeconvolveR is a package for Empirical Bayes Deconvolution
-and Estimation. A friendly introduction is provided in the JSS
-paper reference below and this package includes a vignette
-containing a number of examples.
Bradley Efron. Empirical Bayes Deconvolution - Estimates. Biometrika 103(1), 1-20, ISSN - 0006-3444. doi:10.1093/biomet/asv068. - http://biomet.oxfordjournals.org/content/103/1/1.full.pdf+html
-Bradley Efron and Trevor Hastie. Computer Age - Statistical Inference. Cambridge University Press. ISBN - 978-1-1-7-14989-2. Chapter 21.
-Balasubramanian Narasimhan and Bradley - Efron. deconvolveR: A G-Modeling Program for Deconvolution and - Empirical Bayes Estimation. doi:10.18637/jss.v094.i11
- -R/deconvolveR.R
- deconvolveR.RddeconvolveR is a package for Empirical Bayes Deconvolution
-and Estimation. A friendly introduction is provided in the JSS
-paper reference below and this package includes a vignette
-containing a number of examples.
Bradley Efron. Empirical Bayes Deconvolution - Estimates. Biometrika 103(1), 1-20, ISSN - 0006-3444. doi:10.1093/biomet/asv068. - http://biomet.oxfordjournals.org/content/103/1/1.full.pdf+html
-Bradley Efron and Trevor Hastie. Computer Age - Statistical Inference. Cambridge University Press. ISBN - 978-1-1-7-14989-2. Chapter 21.
-Balasubramanian Narasimhan and Bradley - Efron. deconvolveR: A G-Modeling Program for Deconvolution and - Empirical Bayes Estimation. doi:10.18637/jss.v094.i11
- -R/deconvolveR-package.R
- disjointTheta.RdA set of \(\Theta\) values that have a bimodal distribution for testing
-data(disjointTheta)- - - -
R/deconvolveR-package.R
- surg.RdIntestinal surgery data involving 844 cancer patients. The data consists of -pairs (\(n_i\), \(s_i\)) where \(n_i\) is the number of satellites removed -and \(s_i\) is the number of satellites found to be malignant.
-data(surg)- - -
Gholami, et. al. Number of Lymph Nodes Removed and Survival after -Gastric Cancer Resection: An Analysis from the US Gastric Cancer Collaborative. -J Am Coll Surg. 2015 Aug;221(2):291-9. doi: 10.1016/j.jamcollsurg.2015.04.024.
- -