# NOT RUN {
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)
##
## 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)"))
}
# }
Run the code above in your browser using DataLab