I'm working on this problem.
We consider model data set collected by Gilchrist (1984), in which a series of 33 insect traps were set across sand dunes and the numbers of di↵erent insects caught over a fixed time were recorded. The number of insects of the taxa Staphylinoidea caught in the traps is shown here (data1): 25023134303 21106003011 50120021110 (a) Compute the mean and sample variance for this data. (b) Plot a histogram of the data. (c) Plot a histogram of a Poisson distribution with the same mean as the data. (d) Generate a contour plot of the joint posterior distribution, for your choice of at least three levels. Hint: The LearnBayes function mycontour is straightforward to apply if the log of the posterior data is coded in this way:
Here are my codes to the first three problems. But I have trouble for the last one, create contour plot for joint posterior distribution.
## Test2 Data
require(LearnBayes)
##Problem 1
data1 <- c(2,5,0,2,3,1,3,4,3,0,3,
2,1,1,0,6,0,0,3,0,1,1,
5,0,1,2,0,0,2,1,1,1,0)
#(a) Compute the mean and sample variance for this data.
var(data1)
mean(data1)
#(b) Plot a histogram of the data.
hist(data1)
#(c) Plot a histogram of a Poisson distribution with the same mean as the data (1.636364)
data1_p <- rpois(n = 10e5, lambda = 1.636364)
data1_p_frame <- data.frame(d = data1_p)
library(ggplot2)
hist(data1_p)
ggplot(data1_p_frame, aes(x = data1_p,)) +
geom_histogram(bins = 14, color = "black")
Any suggestions?