0

I am trying to fit my modely~exp((a*x1+b*x2+c)^d)+f but I getting an error as I am not sure how to incorporate mapply with nlsLM from Package:minpack.lm

ERROR:

     Error in fn(par, ...) : 
       unused arguments (x1 = c(0.203114295490632, -0.16516023916803, 
             0.0870323364177826, 

More explanation with different structure of the data:

So the first call to fun should be:y[1,1,],x1[1,1,],x2[1,1,]:fit the model using these value and give the results.then go to next call and do the same:y[1,2,],x1[1,2,],x2[1,2,]...etc

Barry
  • 739
  • 1
  • 8
  • 29
  • Does `fun(x1=x1, x2=x2, y=y)` work? – germcd Mar 09 '15 at 14:49
  • If `y` is a list, select the element containing what you want, e.g. `y[[1]]`. – Alex A. Mar 09 '15 at 15:25
  • Where in the docs for `nlsLM` does it say it accepts arguments named `x1`, `x2`, and `y`? – r2evans Mar 09 '15 at 15:35
  • I think you need to organize the data differently when passing it to `mapply`. Can you expand on what data you expect to be used on the first call of `fun`? It is not clear to me what exactly will be passed in each call to `fun`. – r2evans Mar 09 '15 at 15:42
  • 1
    I had a long comment with proposed things to test until you cleared things up with your edit. I'm a little confused now, but it's clear to me that everything I was thinking before was under incorrect assumptions of your data. Have you been able to get `fun` to work manually? – r2evans Mar 09 '15 at 16:08
  • 1
    By manually, I mean: can you successfully execute the code that would do the first batch only of regression? I cannot get it to work manually, likely because I am neither familiar with `nlsLM` nor with your data structures. My unposted comment will do no good since it does not make sense with your edited (3D) data. – r2evans Mar 09 '15 at 20:09

1 Answers1

1

I haven't tried it, but it looks like nlsLM requires a data.frame for its data argument (which is more consistent with model fitting), try:

fun <- function(x1, x2, y) {
      out <- nlsLM(y~exp((a*x1+b*x2+c)^d)+f, data = data.frame(x1=x1,x2=x2,y=y),
           start = list(a = 3, b = 0.1, c=0.02,d = 1,f=0.02))
    }
 out=mapply(fun, x1=x1, x2=x2, y=y)
jimmyb
  • 4,227
  • 2
  • 23
  • 26
  • I get two errors with this: `lmdif: info = 0. Improper input parameters` and `Missing value or an infinity produced when evaluating the model`. – r2evans Mar 09 '15 at 15:42