From: Edward Wijaya <ewijaya_at_gmail.com>

Date: Thu, 22 May 2008 11:21:07 +0900

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 22 May 2008 - 02:28:41 GMT

Date: Thu, 22 May 2008 11:21:07 +0900

Thanks so much.

- Edward

On Thu, May 22, 2008 at 11:17 AM, Charilaos Skiadas <cskiadas_at_gmail.com> wrote:

*> Try:
**>
*

> mlogl_out <- nlm(mlogl, mean(vsamples), vsamples)

*>
**> or
**>
**> mlogl_out <- nlm(mlogl, mean(vsamples), x=vsamples)
**>
**> The argument vsamples=vsamples is passed to mlogl, since nlm does not
**> recognize it. But mlogl doesn't have a vsamples argument, only alpha and x
**> arguments. So you have to either leave mean(vsamples) and vsamples unnamed,
**> or else name them alpha and x respectively, as you told mlogl. Or change the
**> argument names in mlogl.
**>
**> Haris Skiadas
**> Department of Mathematics and Computer Science
**> Hanover College
**>
**> On May 21, 2008, at 10:05 PM, Edward Wijaya wrote:
**>
**>> Hi,
**>>
**>> I tried to compute maximum likelihood under gamma distribution,
**>> using nlm function. The code is this:
**>>
**>> __BEGIN__
**>>
**>> vsamples<- c(103.9, 88.5, 242.9, 206.6, 175.7, 164.4)
**>>
**>> mlogl <- function(alpha, x) {
**>> if (length(alpha) > 1) stop("alpha must be scalar")
**>> if (alpha <= 0) stop("alpha must be positive")
**>> return(- sum(dgamma(x, shape = alpha, log = TRUE)))
**>> }
**>>
**>> mlogl_out <- nlm(mlogl, mean(vsamples),vsamples=vsamples)
**>> print(mlogl_out)
**>>
**>> __END__
**>>
**>> However, it gives the following error:
**>>
**>> Error in f(x, ...) :
**>> unused argument(s) (vsamples = c(103.9, 88.5, 242.9, 206.6, 175.7,
**>> 164.4))
**>> Calls: nlm -> <Anonymous> -> f
**>> Execution halted
**>>
**>>
**>> What's wrong in my way of calling 'nlm" function?
**>> Please advice.
**>>
**>> - Edward
**>>
**>
**>
**>
**>
**>
**>
*

R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 22 May 2008 - 02:28:41 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Thu 22 May 2008 - 09:30:39 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*