LMM

Author

Sam

Ilustration of maximum likelihood estimation

library(tidyverse)

Estimating the Mean

plot(NULL, xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
set.seed(1)
pop <- rnorm(1000, 10, 3)
lines(density(pop), col = "black")

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 5, 1)), col = "red")

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 5, 1)), col = "red")
lines(density(rnorm(1000, 8, 1)), col = "purple")

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 5, 1)), col = "red")
lines(density(rnorm(1000, 8, 1)), col = "purple")
lines(density(rnorm(1000, 10, 1)), col = "green")

Estimating the variance

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 10, 2)), col = "red")

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 10, 2)), col = "red")
lines(density(rnorm(1000, 10, 2.5)), col = "purple")

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 10, 2)), col = "red")
lines(density(rnorm(1000, 10, 2.5)), col = "purple")
lines(density(rnorm(1000, 10, 3)), col = "green")

Final result

plot(density(pop), xlim = c(-3, 23), ylim = c(0, 0.5), ylab = "y label", xlab = "x lablel")
lines(density(rnorm(1000, 10, 3)), col = "green")