Fit power curve that goes through specified coordinates in r -
i have following x-y pairs:
x <- seq(.3, .7, by=0.01) y <- .5 * (x**-2.5) + runif(n = 41, min = -0.25, max = 0.25) i find parameters , b of curve form y-hat = * (x ** b), such sum of squared error between y , y-hat minimized.
furthermore, curve must pass through coordinates (0.7, 1.0). need solve a, since b = -log(a)/log(0.7).
i can in excel solver, writing own algorithm solve in r beyond current ability. i'm guessing built in solution exists anyway. looked powerlaw package there doesn't appear way force curve through specified point.
set.seed(101) x <- seq(.3, .7, by=0.01) y <- .5 * (x**-2.5) + runif(n = 41, min = -0.25, max = 0.25) you need reasonable starting point: can 1 log-log regression.
m1 <- lm(log(y)~log(x)) ## hope data positive a_est <- exp(coef(m1)[1]) now you're ready estimate:
n1 <- nls(y ~ a*x^(-log(a)/log(0.7)),start=list(a=a_est)) <- coef(n1) b <- -log(a)/log(0.7) plot(x,y) curve(a*x^b,add=true,col="red")
Comments
Post a Comment