I'm trying to fit a simple power law model to a data set that is as follows:
rev weeks 17906.4 1 5303.72 2 2700.58 3 1696.77 4 947.53 5 362.03 6
The goal being to pass the power line through and use it to predict
rev vlaues for future weeks. A bunch of research has led me to the
nls function, which I implemented as follows.
newMod <- nls(rev ~ a*weeks^b, data=modeldf, start = list(a=1,b=1)) predict(newMod, newdata = data.frame(weeks=c(1,2,3,4,5,6,7,8,9,10)))
While this works for an
lm model, I get a
singular gradient error, which I understand has to do with my starting values
b. I tried different values, even going so far as to plot this in Excel, pass a lone, get an equation, then use the values from the equation, but I still get the error. I looked at a bunch of answers like this one and tried the second answer (couldn't understand the first), but to no result.
I could really use some help here on how to find the right starting values. Or alternatively, what other function I can use instead of nls.
In case you want to recreate
mydf with ease:
mydf <- data.frame(rev=c(17906.4, 5303.72, 2700.58 ,1696.77 ,947.53 ,362.03), weeks=c(1,2,3,4,5,6))