Skip to content
Back to formatted view

Raw Message

Message-ID: <49AB9BC9.6090703@statistik.tu-dortmund.de>
Date: 2009-03-02T08:41:45Z
From: Uwe Ligges
Subject: nls does not accept start values
In-Reply-To: <OF1D96A50A.67EE108C-ONC125756D.002957D5-C125756D.0029D674@precheza.cz>

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 you really want to orgnize it that way, why not simpler as in:

form <- list(y ~ 1/(a - x), a = mean(y))
fit <- nls(form[[1]], data.frame(x=x, y=y), start = form[2])


Uwe Ligges


> If it matters
> WXP,  R2.9.0 devel.
> 
> Regards
> Petr
> 
> petr.pikal at precheza.cz
> 
> ______________________________________________
> 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.