Thank you very much.

now, i call
mle(minuslogl=loglik, start=start, method <<- method, fixed=list())
in the mle.wrap() function, and the profile.mle() worked.

however, it created a variable named "method" in user workspace. if there had been a variable with same name, then the value of that variable would be destroyed.

Is there a way to avoid that happen? Thanks again.

Regards,
Jinsong

On 2011-8-5 14:56, r-b...@r-project.org wrote:
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14647

Brian Ripley<rip...@stats.ox.ac.uk>  changed:

            What    |Removed                     |Added
----------------------------------------------------------------------------
              Status|NEW                         |CLOSED
          Resolution|                            |INVALID

--- Comment #1 from Brian Ripley<rip...@stats.ox.ac.uk>  2011-08-04 11:21:41 
EDT ---
This is not a bug in R, just in your understanding of scoping.

Please review the R FAQ and only use R-bugs for things you 'know for
certain' should work.

On Thu, 4 Aug 2011, r-b...@r-project.org wrote:

https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14647

           Summary: profile.mle can not get correct result
           Product: R
           Version: R 2.13.1
          Platform: ix86 (32-bit)
        OS/Version: Windows 32-bit
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: S4methods
        AssignedTo: r-c...@r-project.org
        ReportedBy: jsz...@yeah.net
   Estimated Hours: 0.0


Hi there,

I hope to wrap mle() in a function, just like the following:

mle.wrap<- function(x, n, r, method = "BFGS") {
   loglik<- function(alpha, beta) {
      P<- pnorm(alpha + beta * x)
      -(sum(r * log(P)) + sum((n - r) * log(1-P)))
   }
   start<- list(alpha = 0, beta = 0)
   mle(minuslogl = loglik, start = start, method = method, fixed = list())
}

Then I call this function:

x<- c(100, 56, 32, 18, 10, 1)
r<- c(18, 17, 10, 6, 4, 3)
n<- c(18, 22, 17, 21, 23, 20)

z<- mle.wrap(x, n, r)

profile(z,1)
An object of class "profile.mle"
Slot "profile":
$alpha
  z par.vals.alpha par.vals.beta
1 0    -1.17522678    0.03674818


Slot "summary":
Maximum likelihood estimation

Call:
mle(minuslogl = loglik, start = start, method = method, fixed = list())

Coefficients:
         Estimate Std. Error
alpha -1.17522678 0.21572863
beta   0.03674818 0.00656062

-2 log L: 111.1682

The result of profile(z,1) was not correct. I tried to track the bug (or
feature?), and found that:

pfit<- tryCatch(eval.parent(call, 2L), error = identity)

give the following error message:

<simpleError in match.arg(method): object 'method' not found>

Therefore, I thought that
call$method<- fitted@method
should be add into the profile.mle at, e.g., after
call$minuslogl<- fitted@minuslogl


Regards,
Jinsong

--
Configure bugmail: https://bugs.r-project.org/bugzilla3/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

_______________________________________________
R-core list: https://stat.ethz.ch/mailman/listinfo/r-core



______________________________________________
R-help@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.

Reply via email to