Dear Sir, I am a new user of R and I am doing a tast, which is: find the maximum likelihood estimate of the parameter of Gaussian distribution for generated 100 numbers by using >x=rnorm(100, mean=3, sd=1). I tried to use following Maximum Likelihood function>fn<-function(x)(-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*(sum((x-(mean(x))^2)), but it did not work. I am looking for the complete syntax to finish my target task. Thanks for your help. Best regards. Edward Sun Germany
Hello, Use> x=rnorm(100, mean=3, sd=1) > library(MASS) >fitdistr(x, "normal")mean sd 2.93666631 0.99673982 (0.09967398) (0.07048015) Hope this helps, Shrieb
If, however, you are more interested in general methods for maximizing a likelihood function, I suggest you look at "optim", work the examples on the help page, etc. hope this helps. spencer graves DivineSAAM at aol.com wrote:>Hello, > >Use > > > >>x=rnorm(100, mean=3, sd=1) >>library(MASS) >>fitdistr(x, "normal") >> >> > mean sd > 2.93666631 0.99673982 > (0.09967398) (0.07048015) > >Hope this helps, > >Shrieb > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
Or: library(mle) ?mle (which, BTW, uses optim() underneath.) Also, for those not aware of it, fitdistr(x, "normal") just computes mean(x) and (n-1)/n * var(x) and return them. (I can't imagine any reason to do otherwise for normal distribution.) Best, Andy> From: Spencer Graves > > If, however, you are more interested in general methods for > maximizing a likelihood function, I suggest you look at "optim", work > the examples on the help page, etc. > > hope this helps. spencer graves > > DivineSAAM at aol.com wrote: > > >Hello, > > > >Use > > > > > > > >>x=rnorm(100, mean=3, sd=1) > >>library(MASS) > >>fitdistr(x, "normal") > >> > >> > > mean sd > > 2.93666631 0.99673982 > > (0.09967398) (0.07048015) > > > >Hope this helps, > > > >Shrieb > > > >______________________________________________ > >R-help at stat.math.ethz.ch mailing list > >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Hi,> -----Original Message----- > From: DivineSAAM at aol.com [SMTP:DivineSAAM at aol.com] > Sent: Sunday, February 15, 2004 10:24 PM > To: edwardweisun at hotmail.com; r-help at stat.math.ethz.ch > Subject: Re: [R] Maximum likelihood estimation in R > > Hello, > > Use > > > x=rnorm(100, mean=3, sd=1) > > library(MASS) > >fitdistr(x, "normal") > mean sd > 2.93666631 0.99673982 > (0.09967398) (0.07048015) >For me, this example does not work. As it looks like copy+paste, I guess this something platform dependent? At least I have to specify some starting values as shown below. But maybe I did something wrong? Best, Roland (I am using at the moment R 1.8.1 on WinNT) > x=rnorm(100, mean=3, sd=1) > library(MASS) > fitdistr(x, "normal") Error in fitdistr(x, "normal") : 'start' must be a named list > fitdistr(x, "normal", start=list(mean=1, sd=0.4)) mean sd 3.03167815 1.06637851 (0.10663786) (0.07539617) > +++++ This mail has been sent through the MPI for Demographic Research. Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked. If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance.
Hello, Excellent, also the book: Pawitan, Yudi (2001). In all Likelihood: Statistical Modelling and Inference using Likelihood, Clarendon Press, Oxford. Is very good and the associated Web Site is full of MLE using R. Hope this also helps. /oal