Skip to content

Instantly share code, notes, and snippets.

@mw55309
Created May 6, 2021
Embed
What would you like to do?
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?

Loading

@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)

Loading

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