[R] About Passing Arguments to Function

From: Edward Wijaya <ewijaya_at_gmail.com>
Date: Fri, 23 May 2008 10:14:02 +0900


Hi,

Below I have a function mlogl_k,
later it's called with "nlm" .

__BEGIN__

vsamples<- c(14.7, 18.8, 14, 15.9, 9.7, 12.8)

mlogl_k <- function( k_func, x_func, theta_func, samp) {

     tot_mll <- 0
     for (comp in 1:k_func) {
       curr_mll <- (- sum(dgamma(samp, shape = x_func,
scale=theta_func, log = TRUE)))
       tot_mll <- tot_mll + curr_mll
     }

     tot_mll

}

# Calling the function above
mlogl_out <- nlm(mlogl_k, mean(vsamples), k_func =2, x_func = 1, theta_func = 1, samp=vsamples)

__END__
I thought under NLM, I already assign
the parameter correctly.
However it gives me the following error.

Error in f(x, ...) : unused argument(s) (14.3166666666667) Calls: nlm -> <Anonymous> -> f
Execution halted

What's wrong with my code above?


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 Fri 23 May 2008 - 01:17:54 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 Fri 23 May 2008 - 02:30:45 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.

list of date sections of archive