R Language: Plotting the Likelihood

0

Plotting the likelihood can be a useful way to visualize the optimization problem and to see how peaked or flat the likelihood function is. For example, the following code shows how to plot the negative log-likelihood when mu is fixed to 1:

# Fix mu to be equal to 1

nLL <- make.NegLogLik(normals, c(1, FALSE))


# Evaluate nLL() at every point in x

x <- seq(1.7, 1.9, len = 100)

y <- sapply(x, nLL)


# Plot the negative log-likelihood

plot(x, exp(-(y - min(y))), type = "l")

The plot shows that the negative log-likelihood is very peaked around the true value of sigma, which is 1.8. This means that the optimization algorithm should be able to converge quickly to the optimal solution.

The following code shows how to plot the negative log-likelihood when sigma is fixed to 2:

# Fix sigma to be equal to 2

nLL <- make.NegLogLik(normals, c(FALSE, 2))


# Evaluate nLL() at every point in x

x <- seq(0.5, 1.5, len = 100)

y <- sapply(x, nLL)


# Plot the negative log-likelihood

plot(x, exp(-(y - min(y))), type = "l")

The plot shows that the negative log-likelihood is much flatter when sigma is fixed to 2. This means that the optimization algorithm may take longer to converge to the optimal solution.

Plotting the likelihood can be a useful way to visualize the optimization problem and to see how peaked or flat the likelihood function is. This can help you to choose the right optimization algorithm and to set the right parameters for the algorithm.

Post a Comment

0Comments
Post a Comment (0)