[R] problems with nls function

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jul 15 05:57:04 CEST 2005


The start list should only contain parameters, not x.  Also
your function appears to have multiple errors including
reference to temp (presumably intended as tmp?)
and b(x-m) which presumably should be b*(x-m).

On 7/14/05, Yimeng Lu <yl2058 at columbia.edu> wrote:
> Sorry that I specified the x as
> x=c(0, 0.4, 0.7, 1, 1.4, 1.6, 1.8, 2:10)
> 
> The error message is the same.
> 
> Thanks.
> 
> Hanna
> 
>  ----- Original Message -----
>  From: Yimeng Lu
>  To: r-help at stat.math.ethz.ch
>  Sent: Thursday, July 14, 2005 11:19 PM
>  Subject: problems with nls function
> 
> 
>  Hello,
> 
>  I was trying to fit a generalized logistic curve and my code for testing
>  if the function "nls" is working is like this
>  #######
>  #define the generalized logistic curve function
>  glogit=function(a, b, c, m, t, x)
> 
>  {
> 
>  tmp = 1/(1 + t * exp(-b * (x - m)))^(1/t)
> 
>  model.func = a + tmp * c
> 
>  #define the gradient vector
> 
>  Z = cbind(1, c*(x-m)*tmp^(t+1)*exp(-b*(x-m)), tmp, -c*b*exp(-b*(x-m)) *temp^(t+1), -c*tmp*(1/t)* (log(tmp) + tmp^(-t) * exp(-b(x-m))))
> 
>  attr(model.func,"gradient")=Z
> 
>  model.func
> 
>  }
> 
> 
> 
>  a= 0
> 
>  b=3
> 
>  c=6
> 
>  m=2
> 
>  t=0.75
> 
>  x=c(1:10)
> 
>  y=a + c/(1 + t * exp(-b * (x - m)))^(1/t) + rnorm(16, sd=0.01)
> 
>  plot(data.frame(x=x, y=y), type = "p", col = "red")
> 
>  nls(y ~ glogit(a, b, c, m, t, x), data=data.frame(y=y,x=x), start=list(a=1, b=2, c=3, m=1, t=0, x), trace=T)
> 
>  #####End.
> 
>  When I ran this code, I got the error "Error in assign(i, temp, envir = env) : attempt to use zero-length variable name".   What does this error mean?  How should I fix it?
> 
> 
> 
>  Many thanks.
> 
>  Hanna Lu
> 
>  Dept. of Biostatistics
> 
>  Columbia University
> 
>        [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list