Skip to content

Commit

Permalink
Add plot of theta against L
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaakshat committed Nov 3, 2021
1 parent 678d558 commit 886b457
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ch08.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Visualizing the likelihood function

# R: Visualize the likelooh function
# R: Visualize the likelood function
library(pracma)
library(plot3D)

Expand All @@ -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()



#############

0 comments on commit 886b457

Please sign in to comment.