[R] please help me

Dieter Menne dieter.menne at menne-biomed.de
Wed Oct 10 10:12:00 CEST 2007


azadeh sadeghian <a.sadeghian1386 <at> yahoo.com> writes:

> 
>   I am student M.S. statistics in department statistics . I am working in  the
function "nls" in the [R 2.3.1]

You should update to a more recent version of R (2.6.0 is current)

> with 246 data and want to fit the "exp" model to vectors( v and u ) but I have 
> a problem to use it
You note 246 data, but I count much less

>   u
>   5.000000e-13 2.179057e+03 6.537171e+03 1.089529e+04 1.525340e+04
>   1.961151e+04 2.396963e+04 2.832774e+04 3.268586e+04 3.704397e+04
>  4.140209e+04 4.576020e+04 5.011831e+04 5.447643e+04
>   v
>  8.382562e-01 4.090868e+02 1.311053e+03 2.124143e+03 3.365494e+03
>  2.138903e+03 7.687774e+03 1.028396e+04 1.004186e+04 2.059798e+04
>  1.438464e+04 2.861373e+04 2.294919e+04 2.807701e+04
> data1<-data.frame(u=u ,v=v)
>     nls(v~c0+(ce*(1-exp((-u)/ae))),data=data1,start=list(c0=0,ce=1000,ae=3000))
> Error in nls(v ~ c0 + (ce * (1 - exp((-u)/ae))), data = data1, start = list(c0
= 0,  : 
>         step factor 0.000488281 reduced below 'minFactor' of 0.000976563

To find out what was wrong, plot your data and your start value fit. You can see
that the start values are far off. But, more importantly, note that you data go
up exponential-like and don't level off, while you model function does. So even
if you find better start values, you result may be unreasonable: how should the
poor fitting function know when to bend down? This might be caused by the subset
of the 246 data points you presented here.

Dieter

u = c(
  5.000000e-13, 2.179057e+03, 6.537171e+03, 1.089529e+04, 1.525340e+04,
  1.961151e+04, 2.396963e+04, 2.832774e+04, 3.268586e+04, 3.704397e+04,
 4.140209e+04, 4.576020e+04, 5.011831e+04, 5.447643e+04)
v = c(
 8.382562e-01, 4.090868e+02, 1.311053e+03, 2.124143e+03, 3.365494e+03,
 2.138903e+03, 7.687774e+03, 1.028396e+04, 1.004186e+04, 2.059798e+04,
 1.438464e+04, 2.861373e+04, 2.294919e+04, 2.807701e+04)
data1 = data.frame(u=u ,v=v)
start=list(c0=0,ce=1000,ae=3000)
v1= with(start,c0+(ce*(1-exp((-u)/ae))))
plot(u,v)
lines(u,v1)
v1= nls(v~c0+(ce*(1-exp((-u)/ae))),data=data1,start=start,trace=TRUE)



More information about the R-help mailing list