I am having the hardest time trying to implement this equation into a nonlinear solver in R. I am trying both the nleqslv
and BB
packages but so far getting nothing but errors. I have searched and read documentation until my eyes have bled, but I cannot wrap my brain around it. The equation itself works like this:
s2 * sum(price^(2*x+2)) - s2.bar * sum(price^(2*x)) = 0
Where s2
, s2.bar
and price
are known vectors of equal length.
The last attempt I tried in BB
was this:
gamma = function(x){
n = len(x)
f = numeric(n)
f[n] = s2*sum(price^(2*x[n]+2)) - s2.bar*sum(price^(2*x[n]))
f
}
g0 = rnorm(length(price))
results = BBsolve(par=g0, fn=gamma)