vendredi 15 mai 2015

Initial paramater estimate in nlsLM method and use it in nls again

I come to to end with "Basically, unless your starting parameter estimates are relatively close to the final, fitted values (or unless the model is extremely "well behaved"), nls will fail." So I looked for other method such as nlsLM

So I have this simulation data and exponential equation to fit it.

library(minpack.lm)
sp<-c(1,1,1,1,0.4,0,0.11,0.75,0.85,1,1,0,0,0)   #sim data for y axis
wer<-1-sp

curr_sim<-c(8,7,6,5,4,3.6,3.8,4.2,4.4,4.6,4.8,3,3.2,3.4) #sim data for x axis jw <- seq(0,20,0.1) eq <-function(jw,Jc_jex1,delta_E){1-exp((-0.00000003)*1000000000*exp(-delta_E*(1-jw/Jc_jex1)^2))} #equation to fit the data

fit using Levenberg-Marquardt algorithm

P_calc <- nls(sp~eq(jw,Jc_jex1,delta_E),data=ds,start=c(Jc_jex1=10,delta_E=30.73),trace=T)

after I got this

Error in nlsLM(sp ~ eq(jw, Jc_jex1, delta_E), data = ds, start = c(Jc_jex1 = 6, : number of iterations exceeded maximum of 50

Plot sim data and fit result together

plot(curr_sim,wer,xlim=c(0,20),log="y", ylim=c(1e-12,1), main="Simulation results", xlab="Current J", ylab="sw", font.lab=2,col="red")
aa <- 1-predict(P_calc,jw)
lines(jw[1:113],aa[1:113], lty=43, col="red")   # fit line 

as you can see fitting is not good. There are those kind of list I want to do

  1. Estimate initial parameters with using another function first. I dont know which method is the best.
  2. Use those initial parameters in P_calc
  3. use ifelse for dropping some values for this kind of contidion drop<-ifelse(jw<Jc_jex1,P_calc,1) and plot only dropped values for fit
  4. if possible to these process in a only one function.

Aucun commentaire:

Enregistrer un commentaire