Friday, June 19, 2015

Nonlinear fit to exponential decay model in R

I had some trouble looking around for a non linear model that could fit exponential decay model on R. Finally this is what I have. Hopefully, the next code searcher will find it easier to hunt for such a code!
 :D

The data is in this format:
Week  TAD
0          a
1          b
….
(a and b are values of Cellulose concentration)

ti = seq(0,11, 0.1)
kSAD = nls(TAD~exp(-k*Week), start =list(k= 0.5), trace=T)
summary(kSAD)
plot(Week,TAD, pch=16, xlab="Week", ylab="Cellulose concentration microcosms in mg/mL", cex.lab=1.45,cex.axis=1.5)
lines(ti, predict(kSAD, list(Week = ti)), col="black", lty=3, lwd=2)
arrows(Week, TAD-RETAD, Week, TAD+RETAD, length=0.05, angle=90, code=3)
Created by Pretty R at inside-R.org

Enjoy! <3

No comments:

Post a Comment