[R] Beginners Question: Make nlm work
p.dalgaard at biostat.ku.dk
Thu Aug 26 12:22:40 CEST 2004
Peter Dalgaard <p.dalgaard at biostat.ku.dk> writes:
> 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")
> > > mydata<-read.table("YJG45-7_Growth.dat")
> > > x<-mydata$V1
> > > y<-mydata$V2
> > > VH <- function(p) y ~ p/(1+((p-0.008)/0.008)*exp(-(p*x)))
> Make that
> VH <- function(p) sum((y - p/(1+((p-0.008)/0.008)*exp(-(p*x))))^2)
> > > plot(x, y, xlab="Time (h)",ylab=expression(OD[~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!
Ah, sorry. That was fixed in another branch of this thread. So much
for skimming emails in the morning...
It would be good to see that actual output inside "out". However, the
real problem seems to be that the nlm algorithm is quite sensitive to
getting the typsize argument approximately right. nlm(VH, p=c(3,4e-3),
typsize=c(1,1e-3), ....) appears to fare considerably better.
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
More information about the R-help