Search code examples
rnls

R nls : could not find function "a"


I'm trying to fit the information with nls() function. The formula is: enter image description here

but the R be angry :)

> dk1
                        Q   H
                1  43.754  21
                2  74.434  52
                3  94.601  72
                4 115.327  81
                5 135.751 109
                6  72.990  54
                7  35.756  12
                8  36.685   2
                9  35.799   2
> k1_H0
                [1] 0
> n_N <- nls(Q ~ a((H-k1_H0)^b)*(exp(1)^(c(log10(H-k1_H0)^2))), data = dk1, start = list( a = 0.1, b = 0.1, c=0.1), trace = T)
Error in eval(expr, envir, enclos) : could not find function "a"

Solution

  • You might try:

    nls(Q ~ a*((H-k1_HO)^b)*exp(c*(log10(H-k1_HO)^2)), data = dk1, start = list( a = 0.1, b = 0.1, c=0.1), trace = T)
    

    which should with the appropriate starting values give the outcome (otherwise an error is mentioning "singular gradient").

    R needs a * sign to know it's a mutliplication, otherwise a() or c() are considered as functions. And for the exponential you should check out ?exp.