Hi Bob,
On Nov 5, 2009, at 3:04 PM, <robertagnew at discover.com> <robertagnew
at discover.com
> wrote:
> I am missing something fundamental. I ran the function nlm, but I
> don't
> understand how to extract the optimal solution as a numeric vector.
> The
> function produces it as one element of a list. I don't see anything
> in
> the R documentation about converting such a list element to the
> vector it
> displays.
Are you just asking how to pull out the appropriate parts of the
returned value from the nlm function call?
Taking code from the Example section of ?nlm, run this:
R> f <- function(x, a) sum((x-a)^2)
R> r <- nlm(f, c(10,10), a=c(3,5))
Now look at "r"
R> r
$minimum
[1] 3.371781e-25
$estimate
[1] 3 5
$gradient
[1] 6.750156e-13 -9.450218e-13
$code
[1] 1
$iterations
[1] 2
To get the minimum, or estimate you just access it like:
R> r$minimum
[1] 3.371781e-25
R> r$estimate
[1] 3 5
Is this what you're asking?
-steve
ps:
r[['minimum']] and r[['estimate']] would also work, as would
r[[1]]
and r[[2]]
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact