[R] EXAMPLE OF HOW TO USE R FOR EXPONENTIAL DISTRIBUTION & EXPONENTIAL REGRESSION

Bert Gunter bgunter@4567 @ending from gm@il@com
Tue Nov 27 18:38:17 CET 2018


... but do note that a nonlinear fit to the raw data will give a(somewhat)
different result than a linear fit to the transformed data. In the former,
the errors are additive and in the latter they are multiplicative. Etc.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Nov 27, 2018 at 9:11 AM Sarah Goslee <sarah.goslee using gmail.com> wrote:

> Hi,
>
> Please also include R-help in your replies - I can't provide
> one-on-one tutorials.
>
> Without knowing where you got your sample code, it's hard to help. But
> what are you trying to do?
>
> It doesn't have to be that complicated:
>
> x <- 1:10
> y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 )
> plot(x, y, pch=20)
>
> # basic straight line of fit
> fit <- glm(y~x)
>
> abline(fit, col="blue", lwd=2)
> exp.lm <- lm(y ~ exp(x))
> lines(1:10, predict(exp.lm, newdata=data.frame(x=1:10)))
>
>
> On Tue, Nov 27, 2018 at 9:34 AM Tolulope Adeagbo
> <tolulopeadeagbo using gmail.com> wrote:
> >
> > Hello,
> >
> > So I found this example online but there seems to be an issue with the
> "Start" points. the result is giving somewhat a straight line
> >
> > # get underlying plot
> > x <- 1:10
> > y <- c(0.00, 0.00,0.0033,0.0009,0.0025,0.0653,0.1142,0.2872,0,1 )
> > plot(x, y, pch=20)
> >
> > # basic straight line of fit
> > fit <- glm(y~x)
> > co <- coef(fit)
> > abline(fit, col="blue", lwd=2)
> >
> > # exponential
> > f <- function(x,a,b) {a * exp(b * x)}
> > fit <- nls(y ~ f(x,a,b), start = c(a=1 , b=c(0,1)))
> > co <- coef(fit)
> > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2)
> >
> >
> > # exponential
> > f <- function(x,a,b) {a * exp(b * x)}
> > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1))
> > co <- coef(fit)
> > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green", lwd=2)
> > # logarithmic
> > f <- function(x,a,b) {a * log(x) + b}
> > fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1))
> > co <- coef(fit)
> > curve(f(x, a=co[1], b=co[2]), add = TRUE, col="orange", lwd=2)
> >
> > # polynomial
> > f <- function(x,a,b,d) {(a*x^2) + (b*x) + d}
> > fit <- nls(y ~ f(x,a,b,d), start = c(a=1, b=1, d=1))
> > co <- coef(fit)
> > curve(f(x, a=co[1], b=co[2], d=co[3]), add = TRUE, col="pink", lwd=2)
> >
> > On Tue, Nov 27, 2018 at 12:28 PM Sarah Goslee <sarah.goslee using gmail.com>
> wrote:
> >>
> >> Hi,
> >>
> >> Using rseek.org to search for exponential regression turns up lots of
> information, as does using Google.
> >>
> >> Which tutorials have you worked thru already, and what else are you
> looking for?
> >>
> >> Sarah
> >>
> >> On Tue, Nov 27, 2018 at 5:44 AM Tolulope Adeagbo <
> tolulopeadeagbo using gmail.com> wrote:
> >>>
> >>> Good day,
> >>> Please i nee useful materials to understand how to use R for
> exponential
> >>> regression.
> >>> Many thanks.
> >>
>
>
> --
> Sarah Goslee (she/her)
> http://www.numberwright.com
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list