plotly Package

We install the plotly R package

devtools::install_github("ropensci/plotly")

and load it

library(plotly)

Simulate Normal Data

We simulate a random sample of 1000 Normal\((\mu=0, \sigma=5)\) IID random variables.

n <- 1000
x <- rnorm(n, mean=0, sd=5)

MLE

We compute the MLE’s \((\widehat{\mu}_{\text{MLE}}, \widehat{\sigma}_{\text{MLE}})\) for \((\mu, \sigma)\):

xbar <- sum(x)/n
sigma_hat <- sqrt((1/n)*sum((x-xbar)^2))
c(xbar, sigma_hat)
## [1] 0.1587176 4.8559057

Log-Likelihood Function

The log-likelihood function can be computed, as described in the Lec12 notes, with the following function:

f <- function(x, mu, sigma){
  sum(dnorm(x, mean=mu, sd=sigma, log = TRUE))
}

We plot the log-likelihood function for \((\mu, \sigma)\) given \(\vec{x}\), saving the values in log_lkhd (code hidden).

plot_ly(z = log_lkhd, type = "surface", x=sigma, y=mu)

Interpretation

The MLE \((\widehat{\mu}_{\text{MLE}}, \widehat{\sigma}_{\text{MLE}})\) are the parameter values that best explain/fit the observed data x.