I need to fit a model to an existing dataset such that I can use the parameters to replicate the best-fit curve to manage the behaviour of an application. I've been trying to fit a polynomial model, but cannot escape the problem of (I think) edge effects (?) - despite fitting the model to a broader-ranged dataset than my operational requirements (exemplified by
The following R script illustrates:
dat = read.csv('https://gist.githubusercontent.com/geotheory/10ad6b2051e69213f81ccf2366938cda/raw/485c98381579d74ec581e34c1ebfa80b66b76d69/poly-test.csv') # polynomial model pm = lm(vy ~ poly(vx, degree=20, raw=TRUE), data = dat) newdat = data.frame(vx = 10^seq(4,6,.02)) newdat$vy = predict(pm, newdata = newdat) #> Warning in predict.lm(pm, newdata = newdat): prediction from a rank- #> deficient fit may be misleading plot(dat, log='x', pch=16, cex=.6) lines(newdat, col='red', lwd=3)
I've experimented with different degrees but nothing works.
If another model is better suited I'd be happy to take advice. Grateful for suggestions.