Exponential Fit with R

I have such a data set

Df

xy 7.3006667 -0.14383333 -0.8983333 0.02133333 2.7953333 -0.07466667 

and I would like to correspond to an exponential function such as y = a * (exp (bx)).

This is what I tried and the error I get

 f <- function(x,a,b) {a * exp(b * x)} st <- coef(nls(log(y) ~ log(f(x, a, b)), df, start = c(a = 1, b = -1))) Error in qr.qty(QR, resid) : NA/NaN/Inf in foreign function call (arg 5) In addition: Warning messages: 1: In log(y) : NaNs produced 2: In log(y) : NaNs produced fit <- nls(y ~ f(x, a, b), data = df, start = list(a = st[1], b = st[2])) Error in nls(y ~ exp(a + b * x), data = df, start = list(a = st[1], : singular gradient 

I believe that this is due to the fact that the journal is not defined for negative numbers, but I do not know how to solve this.

+1
source share
1 answer

I have a problem with a problem here.

 f <- function(x,a,b) {a * exp(b * x)} fit <- nls(y~f(x,a,b),df,start=c(a=1,b=1)) summary(fit)$coefficients # Estimate Std. Error t value Pr(>|t|) # a -0.02285668 0.03155189 -0.7244157 0.6008871 # b 0.25568987 0.19818736 1.2901422 0.4197729 plot(y~x, df) curve(predict(fit,newdata=data.frame(x)), add=TRUE) 

Odds are very poorly estimated, but this is not surprising: you have two parameters and three data points.

As for your code: the first call to nls(...) throws an error, so st never set to anything (although it may matter from some earlier code). Then you try to use this in the second nls(...) call.

+2
source

Source: https://habr.com/ru/post/1259888/


All Articles