Adjust data to exponential model in R

Asked

Viewed 3,208 times

3

Good night,

I have two variables about insect growth: y- head width measurements(0.5,0.8,0.10,0.12,0.16) x- age at which they were measured (1,2,3,4,5)

I need to see if this growth fits an exponential growth. I need the values of the generated equation, of p and r 2, in addition to F (although F does not think it is possible, it is?).

I couldn’t find a way to do it in R.

Thank you

Bruna

  • 2

    Have you tried a logarithmic transformation of y and run a linear regression with lm()?

  • what is p, F is test F?

2 answers

1

Your question lacks some explanations, but in a basic way you can do so in R:

x<- c(1,2,3,4,5)
y<- c(0.5,0.8,0.10,0.12,0.16)

cbind(x,y)
n<-length(x)

cbind(x,log(y),x*log(y),x^2)
cbind(sum(x),sum(log(y)),sum(x*log(y)),sum(x^2))
num = sum(x*log(y)) - sum(x)*sum(log(y))/n
denom = sum(x^2) - sum(x)^2/n
a=num/denom
b=sum(log(y))/n - a*sum(x)/n

A = exp(a)
B = exp(b)

plot(x,y,col="blue",pch=19)
curvaexp<-curve(B*exp(a*x), NULL,NULL, 5, add=T, col=2)

curvaexp

r2.lm = lm(y ~ curvaexp$y) 
r2<- summary(r2.lm)$r.squared #<--- Coeficiente de Determinaçao
var.test(y, curvaexp$y)# variancia F

0

An answer in English

https://stackoverflow.com/questions/26560849/exponential-regression-with-nls-in-r

basically, uses @Bernardo’s proposal (lm() in the log(head width) - this gives you a linear problem solution. And use this solution as a non-linear (exponential) problem solving inicalization using nls.

But I think nls doesn’t give you those measurements that Voce wants, p, r 2 etc. Who gives that is the linear reassessment. But the linear process is not in terms of head size but in log of head size.

What is the difference of the solution only using log and lm() and using nls? The solution using log only assumes that Existence is

y = a * Exp(b * x)

that apart from the log on both sides of the

log y = a + b*x

Using nls, the model can be

y = a * Exp(b * x) + c

Browser other questions tagged

You are not signed in. Login or sign up in order to post.