Skip to content

Instantly share code, notes, and snippets.

@mw55309
Created May 6, 2021 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mw55309/7bf8f159efadfedbdf81ae7202d2fe7e to your computer and use it in GitHub Desktop.
Save mw55309/7bf8f159efadfedbdf81ae7202d2fe7e to your computer and use it in GitHub Desktop.
d <- data.frame(frac=seq(0.1,1.0,by=0.1), total=c(116,175,215,246,271,291,308,323,336,348))
plot(d$frac, d$total, pch=16, xlim=c(0,3), ylim=c(0,400))
fit <- lm(formula = total ~ I(1/frac), data=d)
nd <- data.frame(frac=seq(0.1,3.0,by=0.1))
nd$pred <- predict(fit, newdata=nd)
lines(nd$frac,nd$pred)
@mw55309
Copy link
Author

mw55309 commented May 6, 2021

Actually lm(formula = total ~ I(1/(frac+0.5)), data=d) is a far better fit, so how do I get R to learn the 0.5 bit?

@mw55309
Copy link
Author

mw55309 commented May 7, 2021

Much better but still a wee bit off

d <- data.frame(frac=seq(0.1,1.0,by=0.1), total=c(116,175,215,246,271,291,308,323,336,348))

plot(d$frac, d$total, pch=16, xlim=c(0,3), ylim=c(0,400))

fit <- lm(formula = total ~ I(log(frac)), data=d)

nd <- data.frame(frac=seq(0.1,3.0,by=0.1))

nd$pred <- predict(fit, newdata=nd)

lines(nd$frac,nd$pred)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment