0

I am writing a function that allows many starting parameter combinations to be tried to fit nonlinear regression as nlsList() only allows one set of starting parameters.

I have managed this fine but want to add a predictions data frame into the function for easy plotting that returns the best fit curve at smaller increments of x than the data supplies. For example having 100 points instead of 10 to achieve a nice smooth predicted curve.

In my function arguments I specify the formula as an argument and treat is a formula within the function. Some of the formulas include a function that I make to encompass the non-linear relationship. I then use do.call(function, new.starting params) to pass on the predicted parameters onto a predictions data frame.

I have not found a way of isolating and passing any defined and fixed variables from the function to the do.call() function.

Is there a way to get the values that are defined in the formula? So Tc = 25 in this example...

model = y ~ schoolfield.high(ln.c, Ea, Eh, Th, temp = x, Tc = 25)
formula <- as.formula(model)
vars <- all.vars(formula[[3]])

This returns :

"ln.c" "Ea"   "Eh"   "Th"   "x" 

I am wondering if there is a way to isolate defined variables from a formula object, or if there is any other way I could do this?

  • First of all, are you aware of the nls2 package? Then, I don't really understand your question. There is a lot of fluff that doesn't really seem relevant, but the actual problem is poorly defined. I'm not even sure if you don't understand `do.call` or if your problem is related to formula objects. – Roland Apr 27 '16 at 12:00
  • I was not aware of the nls2 package. Thanks for the heads up. My problem is in the formula object and accessing defined portions of formula objects. Think I might need to remove some of the context and concentrate on the specific problem. – Daniel Padfield Apr 27 '16 at 12:04
  • 1
    If the problem is to separate the named and unnamed arguments then we can convert `model` into a list like this: `as.list(model[[3]])[-1]` and easiliy determine which are which. – G. Grothendieck Apr 27 '16 at 12:07
  • That will do nicely. Thanks so much. And thanks for nls2 even though I did not know it existed. Seems I may be reinventing the wheel. – Daniel Padfield Apr 27 '16 at 12:09

0 Answers0