Adjust data to exponential model in R

3

Good evening,

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

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

I could not figure out how to do this in R.

Thank you

Bruna

    
asked by anonymous 08.02.2015 / 00:56

2 answers

1

In your question there are some explanations, but basically you can do this 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
    
25.02.2015 / 03:09
0

An answer in English

link

Basically, use the @Bernardo proposal (lm () in the log (head width) - this gives you a solution to the linear problem.) And use this solution as an inicalization of nonlinear problem solving (exponential regression) using or nls.

But I think nls does not give you these measures you want, p, r ^ 2 etc. Who gives this is linear regression. But the linear regression is not in terms of head size but rather in log of head size.

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

y = a * exp (b * x)

that by taking the log from the 2 sides of the

log y = a + b * x

Using nls, the template can be

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

    
20.02.2015 / 21:00