Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I generate a sample of size 1000 consisting of realizations of independent N(4, 1) distributed random variables:

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

I give the density for this sample depending on the parametres (\$\mu\$, \$\sigma\$) \$\in\$ \$\mathbb{R}\$ x \$\mathbb{R}\$+ standing for the mean and standard deviation of the normal density.

generate <- function(mu, sigma,n)
{
 x <- rnorm(n,mu,sigma)
 plot(hist(x),breaks=30)
}

I apply a numerical maximization procedure to determine a maximum likelihood estimator for the unknown parameters:

estimateparameters <- function(mu, sigma,n)
 {
  a = dnorm(x, mu, sigma)
 -sum(log(a))
 mle(likelihood, start = list(mu = 1, sigma=1), method = "L-BFGS-B", lower =c(-Inf, 0),upper = c(Inf, Inf))
  }

What do you think about what I have done?

share|improve this question

migrated from stackoverflow.com Jun 15 at 22:23

This question came from our site for professional and enthusiast programmers.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.