Hi Daniel & Granville
@mathesong
@padpadpadpad
I have these issues:
-
Every time I call nls_multstart, I get different results for the fitting parameters on the same exact data. How can I get this fixed and get all time similar results for the fitting parameters ( eta , ntotperl , sig ).
-
As you see from the image below, I am fitting two data (blueData, redData) in for loop and get the fitting parameters for each separately. Expecting I get similar fitting parameters for (eta , ntotperl , sig) for both data. As you see in the image, those two curves very similar except they are pi phase shifted from one another.
-
I noticed the fitting sometimes takes the value I assigned in 'lower' in nls_multstart function as shown in the image below , ntotperl=0.00e+00
If I don't specify values in "lower", I get negative valuse for ( eta , ntotperl , sig) which are not realistic.
For both data (blueData, redData), the expected positive values for (eta , ntotperl , sig) are eta =~ 2.40e5, ntotperl =~ 2.34e-9, sig = ~8.0e10 and they could be different but they need to be consistent every time I run nls_multstart
For beta1 and beta2 they are random phase or angels in radiance and they can take any values. p1 is the max-min for each data ~ 0.002 -0.004
Here are the data, function , and nls_multstart input parametrs
your help is really appreciated
Thank you
Abdo
sitedata
OPT_blueData:
0.0029621019 0.0031441264 0.0033358000 0.0034986460 0.0036702868 0.0038132915 0.0039111097 0.0040373835 0.0040803743 0.0040709897 0.0040105137 0.0038815037 0.0036576319 0.0034387452 0.0031434025 0.0028047877 0.0023944182 0.0019696996 0.0015332042 0.0011084089 0.0007231027 0.0003991168 0.0001695899 0.0000978363
OPT_redData:
1.298375e-03 1.122535e-03 9.253372e-04 7.426770e-04 5.618236e-04 3.994846e-04 2.674853e-04 1.632676e-04 1.043999e-04 9.799412e-05 1.429881e-04 2.435567e-04 4.067242e-04 6.214411e-04 8.943345e-04 1.213109e-03 1.571810e-03 1.957492e-03 2.328627e-03 2.716439e-03 3.082478e-03 3.345800e-03 3.505097e-03 3.535086e-03
Volt:
-4.6 -4.4 -4.2 -4.0 -3.8 -3.6 -3.4 -3.2 -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0
lam:
1264
custom function
`
mzmfunc <- function(p1, beta1, beta2, eta, ntotperl , sig , Volt1, Volt2,lamb) {
lamb<- lamb*1e-9
l<-0.63e-2
co_mod<- 1
capperl<-0.26e-9
cap <- capperllco_mod
vbi_va <- 0.4
m_va <- 0.3
mgrad <- (1.0/m_va) - 2.0
qo <- -1*((mgrad+2)/(mgrad+1))*exp(log(vbi_va)/(mgrad+2))*cap
qt <- qo*exp(((mgrad+1)/(mgrad+2))*log(vbi_va))
ntot <- ntotperllco_mod*co_mod
qcap1<- qt*exp(((mgrad+1)/(mgrad+2))*log(1- Volt1/vbi_va))
phi1<- (-2*pi/lamb)etaqcap1
qcap2<- qt*exp(((mgrad+1)/(mgrad+2))*log(1- Volt2/vbi_va))
phi2<- (-2*pi/lamb)etaqcap2
A1<- sqrt(abs(p1*( 1-sig*(ntot+qcap1))))
A2<- sqrt(abs(p1*( 1-sig*(ntot+qcap2))))
Eo1<- -1i * 0.5 ( A1exp(-1i * (phi1+beta1)) + A2*exp(-1i * (phi2+beta2)) )
Eo2<- 0.5*( A1*exp(-1i (phi1+beta1)) - A2exp(-1i * (phi2+beta2)) )
pow1<- abs(Eo1*Conj(Eo1))
pow2<- abs(Eo2*Conj(Eo2))
return(pow1)
}
`
nls_multstart
`
result1 <- nls_multstart(OPT~ mzmfunc( p1, beta1, beta2, eta, ntotperl, sig , Volt1 = 0, Volt2 = Volt, lamb =lam),
data = sitedata,
iter = 1000,
start_lower = c(p1 = 0.001, beta1 = 0, beta2 = 0, eta = 0 , ntotperl = 0, sig = 0),
start_upper = c(p1 = 0.006 , beta1 = 2*pi, beta2 = 2*pi, eta = 3e5 , ntotperl = 1e-9, sig =10e10),
supp_errors = 'Y',
convergence_count = 300,
na.action = na.omit,
lower = c(p1 = 0.0001,beta1=0, beta2 = 0, eta =0, ntotperl = 0, sig = 0))
`
![capture](https://user-images.githubusercontent.com/598125/42476057-a7b893a4-839a-11e8-87bb-48ff7bfcd953.PNG)