Friday, 15 April 2011

curve fitting problems in R -



curve fitting problems in R -

i have quick question here new r language. not sense code right curve fitting: poly fit checks out, log , exponential fit unsure of (e fit def wrong). help appreciated , thanks. -sam

polyfit <- function(xs,ys,degree) { #polynomial fitting info set grade 3 fit3 <- lm(ys~poly(xs,degree,raw=true)) xx <- seq(0,160, length=50) plot(xs,ys,pch='@') lines(xx, predict(fit3, data.frame(xs=xx)), col="green") } logfit <- function(xs,ys) { #graph info set log(x), y logestimate = lm(ys ~ log(xs)) plot(xs,ys,pch='@') lines(xs,predict(logestimate),col='green') } efit <- function(xs,ys) { logestimate = lm(log(ys) ~ xs) plot(xs,ys,pch='@') lines(xs,predict(logestimate),col='green') }

for clarification, xs = x points, ys = y points

no, this:

efit <- function(xs,ys) { expestimate = lm(log(ys) ~ xs) plot(xs, ys,pch='@') lines(xs, exp(predict(expestimate)),col='green') }

i changed model name create distinct logfit function, though it's internal function. in model, fit log(y), predict log(y), if want see how prediction stack against real y, need untransform them, , exp(log(y)) = y.

r

No comments:

Post a Comment