diff --git a/ch08.r b/ch08.r index c966b9f..42fa871 100644 --- a/ch08.r +++ b/ch08.r @@ -3,7 +3,7 @@ ## Visualizing the likelihood function -# R: Visualize the likelooh function +# R: Visualize the likelood function library(pracma) library(plot3D) @@ -27,4 +27,26 @@ L = S_grid * log(theta_grid) + (N-S_grid) * log(1-theta_grid) L = t(L) image(S, theta, L, col=rainbow(256), ylim=c(0.9, 0.1)) +## Visualizing the likelihood function + +# R code +library(pracma) + +N = 50 +S = 1:N +theta = seq(0.1, 0.9, (0.1+0.9)/100) +mesh = meshgrid(S, theta) +S_grid = mesh$X +theta_grid = mesh$Y +L = S_grid * log(theta_grid) + (N-S_grid) * log(1-theta_grid) +L_df = data.frame(L) +colnames(L_df) = S + +plot(theta, L_df$"12", type="n") +lines(theta, L_df$"12", lwd=6) +title(expression(paste("L(", theta, " | S = 12)"))) +grid() + + + #############