Katharine,

The problem of estimation of parameters in R is that you have to know the value of the initial estimates very accurately, otherwise it does not converge.

The example below could be resolved in Excel, however in does not converge. How to solve the problem?

I made the chart on a logarithmic scale to better visualize the differences.

Send the data file attached.

The commands are below:

tx.br <- read.table('c:/tx.br.H.txt',header=F,dec=',')
tx.br <-tx.br[,1]
id<-1:100

qx.suav <- function(id,A,B,C,D,E,F,G,H,K)
 (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))

HP <- nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),
         data=data.frame(id=id,tx.br=tx.br),
trace=TRUE,nls.control(maxiter=50000,warnOnly=TRUE,minFactor = 0.1),
        algorithm='port',
        start=list(A=0.000644,B=0.016761290,C=0.10927095582,D=0.00094877,
          
E=5.949082737,F=24.526811,G=0.000046733960,H=1.0970550987,K=0.771722501657),
         lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))

HP

matplot(cbind(log(fitted(HP)), log(tx.br)),type="l")



----- Original Message ----- From: "Katharine Mullen" <k...@few.vu.nl>
To: "AneSR" <citb...@terra.com.br>
Cc: <r-help@r-project.org>
Sent: Thursday, December 10, 2009 9:55 PM
Subject: Re: [R] non-linear regression


You did not provide the data or a way of generating it.

I would guess that Excel finds the same solution (the same residual sum-of
squares) as nls but that it uses a weak convergence criterion and/or does
not give you information regarding why it terminates.

Regarding the step size:  you can set the minimum step size factor via the
minFactor argument of control.

qx.suav <- function(id,A,B,C,D,E,F,G,H,K)
 (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))

## make noisy data from model
id <- 1:1000
tx.br <- qx.suav(id,A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,
                E=0.0002127,F=38.5448420,G=0.0000115,H=1.1109286,
                K=0.382070638)
set.seed(1)
tx.br <- tx.br + rnorm(length(tx.br),0,.0001)

HP <- nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),
         data=data.frame(id=id,tx.br=tx.br),
         trace=TRUE,nls.control(maxiter=5000,warnOnly=TRUE),
         algorithm='port',
         start=list(A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,
           E=0.0002127,F=38.5448420,G=0.0000115,H=1.1109286,
           K=0.382070638),
         lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))
matplot(cbind(fitted(HP), tx.br),type="l")

On Thu, 10 Dec 2009, AneSR wrote:


I have a non-linear regression with 8 parameters to solve .... however it
does not converge ... easily solves the excel ... including the initial
estimates used in the R were found in the excel ... Another question is how
to establish the increments of R by the parameters in the search ..


qx.suav<-function(id,A,B,C,D,E,F,G,H,K){(A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))}
HP<-nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),data=data.frame(id=id,tx.br=tx.br),
trace=TRUE,nls.control(maxiter=5000),algorithm='port',start=list(A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,E=0.0002127,F=38.5448420,G=0.0000115,H=1.1109286,K=0.382070638),lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))
summary(HP)

How to solve this problem in R?

Ane
--
View this message in context: http://n4.nabble.com/non-linear-regression-tp959977p959977.html
Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




--------------------------------------------------------------------------------



No virus found in this incoming message.
Checked by AVG - www.avg.com

07:36:00
0,000757
0,000356
0,000290
0,000232
0,000199
0,000283
0,000128
0,000235
0,000230
0,000179
0,000197
0,000172
0,000294
0,000307
0,000411
0,000619
0,000812
0,000949
0,001116
0,001134
0,001159
0,001151
0,001321
0,001235
0,001296
0,001287
0,001241
0,001469
0,001278
0,001466
0,001440
0,001881
0,001457
0,001843
0,001754
0,001796
0,001915
0,002199
0,002120
0,002471
0,002213
0,002478
0,002975
0,002583
0,002751
0,003388
0,003956
0,004369
0,004062
0,004410
0,004939
0,005492
0,005961
0,006311
0,006846
0,007637
0,008968
0,010612
0,010907
0,011986
0,013174
0,014316
0,015557
0,017824
0,018740
0,020338
0,022034
0,022339
0,025929
0,030967
0,033520
0,039556
0,041168
0,044811
0,049932
0,047401
0,060318
0,063559
0,064084
0,077614
0,080425
0,094073
0,102383
0,116288
0,112727
0,114192
0,137330
0,159065
0,138378
0,135844
0,148244
0,165927
0,180803
0,217185
0,241570
0,249358
0,309202
0,269479
0,325142
0,461620
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to