Dear Sir/Madam, I am using R version 1.8.1. I am doing following tast: First generate 100 Gaussion(3,1) numbers, then write the likelihood function to estimate the parameters of Gaussian distribution by direct maximizing the likelihood function. My likelihood function is:>fn<-function(x) >(-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*(sum((x-(mean(x))^2))After I input above function, the '' >'' turned to be '' + ''. and it did not work. I am looking for the help to solve this tast by writting a likelihood function. Thanks a lot. Best regards. edward sun
Dear Sir/Madam, I am using R version 1.8.1. I am doing following tast: First generate 100 Gaussion(3,1) numbers, then write the likelihood function to estimate the parameters of Gaussian distribution by direct maximizing the likelihood function. My likelihood function is:>fn<-function(x) >(-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*(sum((x-(mean(x))^2))After I input above function, the '' >'' turned to be '' + ''. and it did not work. I am looking for the help to solve this tast by writting a likelihood function. Thanks a lot. Best regards. edward sun p.s>x=rnorm(100, mean=3, sd=1)library(MASS) fitdistr(x, "normal") and>fitdistr(x, "normal", list(mean=0, sd=1))do not work.
I fear you have a problem with your parentheses. The '>' sign turns to a '+' when the line is incomplete. See the R-FAQ for information. This evaluates but I'm not sure if it's what you want.... fn < -function(x){ (-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*(sum((x-(mea n(x))^2))) } fn(1:10) HTH, Andy
A likelihood function is the pdf or pmf as a function of parameters given the data. The function you wrote is purely a function of the data, not parameters. You need to write the function as a likelihood before you can get the MLE. Andy> From: Edward Sun > > Dear Sir/Madam, > > I am using R version 1.8.1. I am doing following tast: > > First generate 100 Gaussion(3,1) numbers, then write the > likelihood function > to estimate the parameters of Gaussian distribution by direct > maximizing the > likelihood function. > > My likelihood function is: > >fn<-function(x) > >(-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*( > sum((x-(mean(x))^2)) > > After I input above function, the '' >'' turned to be '' + > ''. and it did > not work. > > I am looking for the help to solve this tast by writting a likelihood > function. > > Thanks a lot. > > Best regards. > edward sun------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Is this a homework problem? The "+" means the statement is not syntactically complete. Perhaps you have more "(" than ")"? Also, have you read "the posting guide! http://www.R-project.org/posting-guide.html"? Many people answer their own questions just following that guide. spencer graves Edward Sun wrote:> Dear Sir/Madam, > > I am using R version 1.8.1. I am doing following tast: > > First generate 100 Gaussion(3,1) numbers, then write the likelihood > function to estimate the parameters of Gaussian distribution by direct > maximizing the likelihood function. > > My likelihood function is: > >> fn<-function(x) >> (-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*(sum((x-(mean(x))^2)) >> > > > After I input above function, the '' >'' turned to be '' + ''. and it > did not work. > > I am looking for the help to solve this tast by writting a likelihood > function. > > Thanks a lot. > > Best regards. > edward sun > > ______________________________________________ > 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
Hi, when I write the likelihood function as>fn<-function(x) -50*log(2*pi)-100*log(sigma)-(1/2*(sum((x-mu)/sigma)^2))then what should I do since it shows that Error in log(sigma) : Object "sigma" not found. Thanks edward> > > From: Edward Sun > > > > Dear Sir/Madam, > > > > I am using R version 1.8.1. I am doing following tast: > > > > First generate 100 Gaussion(3,1) numbers, then write the > > likelihood function > > to estimate the parameters of Gaussian distribution by direct > > maximizing the > > likelihood function. > > > > My likelihood function is: > > >fn<-function(x) > > >(-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*( > > sum((x-(mean(x))^2)) > > > > After I input above function, the '' >'' turned to be '' + > > ''. and it did > > not work. > > > > I am looking for the help to solve this tast by writting a likelihood > > function. > > > > Thanks a lot. > > > > Best regards. > > edward sun > > >------------------------------------------------------------------------------ >Notice: This e-mail message, together with any attachments, contains >information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New >Jersey, USA 08889), and/or its affiliates (which may be known outside the >United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan as >Banyu) that may be confidential, proprietary copyrighted and/or legally >privileged. It is intended solely for the use of the individual or entity >named on this message. If you are not the intended recipient, and have >received this message in error, please notify us immediately by reply >e-mail >and then delete it from your system. >------------------------------------------------------------------------------
Do: library(mle) ?mle and read the documentation and the example. That should get you on the right track. Andy> From: Edward Sun > > Hi, > when I write the likelihood function as > > >fn<-function(x) > -50*log(2*pi)-100*log(sigma)-(1/2*(sum((x-mu)/sigma)^2)) > > then what should I do since it shows that Error in log(sigma) > : Object > "sigma" not found. > > Thanks > edward > > > > > > > > > From: Edward Sun > > > > > > Dear Sir/Madam, > > > > > > I am using R version 1.8.1. I am doing following tast: > > > > > > First generate 100 Gaussion(3,1) numbers, then write the > > > likelihood function > > > to estimate the parameters of Gaussian distribution by direct > > > maximizing the > > > likelihood function. > > > > > > My likelihood function is: > > > >fn<-function(x) > > > >(-50*log((sd(x))^2))-50*log(sqrt(2*pi))-(1/2*((mean(x))^2))*( > > > sum((x-(mean(x))^2)) > > > > > > After I input above function, the '' >'' turned to be '' + > > > ''. and it did > > > not work. > > > > > > I am looking for the help to solve this tast by writting > a likelihood > > > function. > > > > > > Thanks a lot. > > > > > > Best regards. > > > edward sun > > > > > >------------------------------------------------------------- > ----------------- > >Notice: This e-mail message, together with any attachments, contains > >information of Merck & Co., Inc. (One Merck Drive, > Whitehouse Station, New > >Jersey, USA 08889), and/or its affiliates (which may be > known outside the > >United States as Merck Frosst, Merck Sharp & Dohme or MSD > and in Japan as > >Banyu) that may be confidential, proprietary copyrighted > and/or legally > >privileged. It is intended solely for the use of the > individual or entity > >named on this message. If you are not the intended > recipient, and have > >received this message in error, please notify us immediately > by reply > >e-mail > >and then delete it from your system. > >------------------------------------------------------------- > ----------------- > > ______________________________________________ > 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}}