# [R] Beginners Question: Make nlm work

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Aug 26 10:32:08 CEST 2004

```Arne Henningsen <ahenningsen at email.uni-kiel.de> writes:

> Hi,
>
> did you try "nls" (nonlinear least squares)? "?nlm" says:
> "For nonlinear regression, 'nls' may be better".
> Another option would be "optim".

Actually, just using nlm  according to specs might help:

> > setwd("~/Biology/R_versuch")
> > x<-mydata\$V1
> > y<-mydata\$V2
> > VH <- function(p) y ~ p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x)))

Make that

VH <- function(p) sum((y - p[1]/(1+((p[1]-0.008)/0.008)*exp(-(p[2]*x))))^2)

> > plot(x, y, xlab="Time (h)",ylab=expression(OD[600][~nm]),las=1)
> > out <- nlm(VH, p = c(3, 4e-3), hessian = TRUE)

I'm quite surprised that the other thing gives a result at all!

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

```