Assignment: Your task is to use Rmarkdown to write a short report, readable by a technically literate person. The code you used should not be visible in the final report (unless you have a good reason to show it).
Due: Submit your work via Canvas by the end of the day (midnight) on Thursday, November 18th. Please submit both the Rmd file and the resulting html or pdf file. You can work with other members of class, but I expect each of you to construct and run all of the scripts yourself.
I have a sizeable collection of old coins, some of strange shapes.
(Not really, but imagine.) I have selected 100 of these and flipped each
one some number of times: some more, some less. The resulting data is in
the file coin_flips.txt, with one row per
coin. Each coin has in intrinsic probability,
If a given coin has a probability of Heads drawn from a
Beta-Binomial(
lchoose(n, k) + lbeta(k + alpha, n - k + beta) - lbeta(alpha, beta)
This is the likelihood for a single coin that was flipped
Your report should:
Read in and describe the data, including both numerical and
graphical summaries. The functions strsplit()
and
readLines()
might be helpful.
Find the maximum posterior estimate for the parameters optim()
). (You will need to write a function to compute the
log-likelihood based on the above.)
Make a plot of the Beta distribution with your estimated values
of
Be sure to explain what is being done to the best of your ability!
Note: Here is example code to make a contour plot, so you know what sort of picture I have in mind for (2). You may of course do this any way you want.
# we'll be plotting a hill with the top at (a, b)
<- 1.5
a <- 2.3
b <- function (x, y) { - (x - a)^2 - (y - b)^2 }
f
<- 31
nx <- seq(0, 4, length.out=nx)
xvals <- seq(0, 4, length.out=nx)
yvals <- expand.grid(
xy x = xvals,
y = yvals
)$f <- NA
xyfor (j in 1:nrow(xy)) {
$f[j] <- f(xy$x[j], xy$y[j])
xy
}
<- function(v) { matrix(v, nrow=nx) }
v2m
image(xvals, yvals, v2m(xy$f))
contour(xvals, yvals, v2m(xy$f), add=TRUE)
<- arrayInd(which.max(xy$f), dim(v2m(xy$f)))
max_ij points(xvals[max_ij[1]], yvals[max_ij[2]], pch="*", cex=3)
legend('topright', pch='*', legend='maximum value')