Firstly, I programmed this gaussian density as an R function which takes the parameters mean and variance (mean=4,sd=1) and calculates the density on a given realization x. Then, passing the density function that I have coded to a (numerical) maximizer, I want to get a maximum close to the parameters which have been used to generate the sample. (mean=4,sd=1).

The question was:

Generate 1000 realizations following N(4,1) and then apply a numerical maximization procedure to determine a maximum likelihood estimator for the unknown parameters.

This is for homework and I would like to know whether my solution is correct or not, and how I can improve. In the case it's wrong I am not asking for a complete correction but just some clues. Hence, my problem is to apply this maximization procedure.

n <- 5000
x <- rnorm(n, mean =4, sd = 1)

likelihood <- function(mu, sigma)
a = dnorm(x, mu, sigma)
mle(minuslogl =likelihood, start = list(mu = 1, sigma = 1), method = "L-BFGSB",lower = c(-Inf, 0), upper = c(Inf, Inf))


mu=3.9994305, sd=0.9944726


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.