[R] Problems running a 4-parameter Weibull function with nls
Spencer Graves
spencer.graves at pdf.com
Fri Nov 5 21:28:52 CET 2004
Might "nls" be testing values for "lag" that exceed min(X)? That
might produce the error you observe.
I routine reparameterize problems like this to send boundaries to
Inf, e.g.:
x0 <- min(df$X)
fit<-nls(Y ~ max.*(1 -
exp(-(rate*(X-x0+exp(ln.lag)))^shape)),df,start=start.est, x0=x0)
##NOT TESTED
(Also, I try to avoid conficts between objects / variables I use
and, e.g., standard system functions like "max" and "df". R can
determine whether a function or a non-function is required in most but
not all contexts.)
hope this helps.
spencer graves
Mike Saunders wrote:
>Hi,
>
>I am rather new to R, but both myself and another much more experience user cannot figure this out. I have a collegue who has a 800+ nonlinear regressions to run for seed germination (different species, treatments, etc.) over time. I created a looping structure to extract the parameters from each regression; I will then use the parameters themselves for further analysis. I would like to fit a 4-parameter, sigmoidal shape Weibull because it it paramatized to have a maximum germination rate (max), a time lag for the start of germination (lag), a germination rate (rate) and a shape parameter (shape).
>
>Here is a copy of this bit of the code:
>
>start.est=list(max=max(df$Y),rate=1/(df$X[tx]-((df$X[tz-1]+df$X[tz])/2)),
> lag=(df$X[tz-1]+df$X[tz])/2,shape=1.1)
>nls.control(maxiter=1000,minFactor=1/8192)
>fit<-nls(Y ~ max*(1 - exp(-(rate*(X-lag))^shape)),df,start=start.est)
>
>
>Here is one column of the data (X=Julian day, Y = % germination):
>
> X Y
>1 111 0.0000000
>2 125 0.0000000
>3 131 0.0000000
>4 138 0.3076923
>5 145 0.4260355
>6 152 0.4733728
>7 159 0.5443787
>8 166 0.5680473
>9 173 0.5680473
>10 180 0.5917160
>11 187 0.5917160
>12 194 0.5917160
>13 201 0.6153846
>14 208 0.6153846
>15 215 0.6153846
>16 223 0.6153846
>17 229 0.6153846
>18 236 0.6153846
>19 245 0.6153846
>
>Here is the error I keep getting:
>
>Error in numericDeriv(form[[3]], names(ind), env) :
> Missing value or an Infinity produced when evaluating the model
>
>
>I have tried these things to get this to work:
> 1) Mess with the starting values quite a bit
> 2) Seed the regression with linear estimates between my known points (i.e., figure out daily averages). I then wanted to regress on these to get starting estimates to use with the real data.
> 3) Drop out all the 0s in the seeded data
> 4) Add jitter to the seeded data
>I should note that this worked to get a 3-parameter Gompertz to work, but that functional form is more difficult to interpret biologically.
>
>I am out of ideas. Thoughts anyone? I would appreciate any help.
>
>Mike Saunders
>Research Assistant
>Department of Forest Ecosystem Sciences
>University of Maine
>
>
> [[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
>
>
--
Spencer Graves, PhD, Senior Development Engineer
O: (408)938-4420; mobile: (408)655-4567
More information about the R-help
mailing list