It is not very clear what you are trying to do here, and
form <- structure(list(a = list(quote(y ~ 1/(a - x)), "list(a=mean(y))")),
.Names = "a")
is using a historic anomaly (see the help page).
I am gussing you want to give nls an object containing a formula and
an expression for the starting value. It seems you are re-inventing
self-starting nls models: see ?selfStart and MASS$ ca p. 216.
One way to use them in your example is
mod <- selfStart(~ 1/(a - x), function(mCall, data, LHS) {
structure(mean(eval(LHS, data)), names="a")
}, "a")
nls(y ~ mod(x, a))
But if you want to follow ypur route, youer starting values would be
better to be a list that you evaluate in an appropriate context
(which y is this supposed to be?). nls() knows where it will find
variables, but it is not so easy for you to replicate its logic
without access to its evaluation frames.
On Mon, 2 Mar 2009, Petr PIKAL wrote:
Hi to all
OK as I did not get any response and I really need some insight I try
again with different subject line
I have troubles with correct evaluating/structure of nls input
Here is an example
# data
x <-1:10
y <-1/(.5-x)+rnorm(10)/100
# formula list
form <- structure(list(a = list(quote(y ~ 1/(a - x)), "list(a=mean(y))")),
.Names = "a")
# This gives me an error due to not suitable default starting value
fit <- nls(form [[1]] [[1]], data.frame(x=x, y=y))
# This works and gives me a result
fit <- nls(form [[1]] [[1]], data.frame(x=x, y=y), start=list(a=mean(y)))
*** How to organise list "form" and call to nls to enable to use other
then default starting values***.
I thought about something like
fit <- nls(form [[1]] [[1]], data.frame(x=x, y=y), start=get(form [[1]]
[[2]]))
^^^^^^^^^^^^^^^^^^^
but this gives me an error so it is not correct syntax. (BTW I tried eval,
assign, sustitute, evalq and maybe some other options but did not get it
right.
I know I can put starting values interactively but what if I want them
computed by some easy way which is specified by second part of a list,
like in above example.
If it matters
WXP, R2.9.0 devel.
Regards
Petr
petr.pi...@precheza.cz
--
Brian D. Ripley, rip...@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
______________________________________________
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.