0

I am trying to estimate the values of 4 parameters with the nls() function using a few variables from a large dataframe. However, when I run my script, I get this error:

Error in formula.default(object, env = baseenv()) : invalid formula

The formula should be correct, as it works properly when I use it elsewhere. Could it possibly be due to the fact that there are more parameters in the function than I tell nls to estimate? Could there be issues with the fact that there are both constant parameters and variables in the function?

Below is the code. For simplicity, I have changed all the parameters to "param1, param2, etc.", and the variables in my data frame to "var1, var2, etc.".

Many thanks.

  param1 <- 0.5
  param2 <- 25 
  param3 <- 1 
  param4 <- 400 
  param5 <- -46.02 
  param6 <- 15

params <- nls(formula = (-(param1*param2*var1)/((param1*var1)+param2)+(param3*exp(param4*(1/(param6 - param5))-(1/(var2-param5))))), start = list(param1=.5, param2=25, param3=1, param4=400))
S K
  • 3
  • 3
  • 2
    the formula needs to have a left-hand side to denote the response variable: `formula = y ~ ....` In what other context did you use it where it worked?? – Ben Bolker Oct 14 '16 at 20:03
  • Thank you. I have made this change, but now get the error, "singular gradient matrix at initial parameter estimates". This seems to be a common error when using nls(). – S K Oct 15 '16 at 20:18

0 Answers0