implicit formula while calling "onls"

I want to realize "implicit formula" using onls package. I failed and the error message is:

Error in optimize(optFCT, interval = INTERVAL, x2 = PRED[i], y2 = RESP[i],  : 
  invalid function value in 'optimize'

Bellow is the code.

library(onls)
library(NISTnls)
# Gauss3 data set in NISTnls
x <- Gauss3[[2]]
y <- Gauss3[[1]]

# explicit function
f1 = function(p1,p2,p3,p4,p5,p6,p7,p8,x){
      out <- p1*exp( -p2*x ) + p3*exp( -(x-p4)**2 / p5**2 ) +
        p6*exp( -(x-p7)**2 / p8**2)  
      out
}

# implicit function(call fortran library)
f2 = function(p1,p2,p3,p4,p5,p6,p7,p8,cc){
  y <- as.double(seq(1:250))
  p <- c(p1,p2,p3,p4,p5,p6,p7,p8)  
  out <- .Fortran("mod_gauss3_mp_comp_wiv",  p, cc, y)
  out[[3]]

}

# explicit function calling
mod1 <- onls(y ~ f1(p1,p2,p3,p4,p5,p6,p7,p8,x),  
             start = list(p1=96.67721580, p2= 0.01022701 ,p3=101.03267362, 
                          p4=113.34143890 , p5=24.68932944  ,p6=62.89014355 ,
                          p7=149.00508535,p8=18.95058582))

# implicit function calling
dyn.load("Gauss3.so")
info <- .Fortran("mod_gauss3_mp_init")
mod2 <- onls(y ~ f2(p1,p2,p3,p4,p5,p6,p7,p8,x),  
             start = list(p1=96.67721580, p2= 0.01022701 ,p3=101.03267362, 
                          p4=113.34143890 , p5=24.68932944  ,p6=62.89014355 ,
                          p7=149.00508535,p8=18.95058582))

The first calling "f1" works, and the second calling "f2" failed. the response of f1 and f2 is the same. Where is the error? I tried "f2" using nls of stats package. It works.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.