[R] Problem with logarithmic nonlinear model using nls() from the `stats' package
Casper Ti. Vector
caspervector at gmail.com
Sat Oct 1 15:55:38 CEST 2011
Ah, now I see...
Thanks very much :)
On Sat, Oct 01, 2011 at 09:27:34AM -0400, Gabor Grothendieck wrote:
> On Sat, Oct 1, 2011 at 5:28 AM, Casper Ti. Vector
> <caspervector at gmail.com> wrote:
> Its linear given c so calculate the residual sum of squares using lm
> (or lm.fit which is faster) given c and optimize over c:
>
> set.seed(123) # for reproducibility
> x <- 1:10
> y <- 1 + 2 * log(1 + 3 * x) + rnorm(1, sd = 0.5)
> fitc <- function(c) lm.fit(cbind(1, log(1 + c * x)), y)
> rssvals <- function(c) sum(resid(fitc(c))^2)
> out <- optimize(rssvals, c(0.01, 10))
>
> which gives:
> 0.7197666 2.0000007 2.9999899
--
Using GPG/PGP? Please get my current public key (ID: 0xAEF6A134,
valid from 2010 to 2013) from a key server.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111001/f576ad89/attachment.bin>
More information about the R-help
mailing list