[R] Solving Systems of Non-linear equations
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Nov 30 17:05:14 CET 2005
On 11/30/2005 10:14 AM, Scott Story wrote:
> I am trying to write a function that will solve a simple system of
> nonlinear equations for the parameters that describe the beta
> distribution (a,b) given the mean and variance.
>
>
> mean = a/(a+b)
> variance = (a*b)/(((a+b)^2) * (a+b+1))
>
> Any help as to where to start would be welcome.
You should use a package like Maple or Mathematica (or just some pencil
and paper work) to determine the solution. Then the function is really
easy to write.
Maple gives
> solve({mean = a/(a+b),variance = (a*b)/(((a+b)^2) * (a+b+1))},{a,b});
{a = -mean*(variance+mean^2-mean)/variance,
b = (variance+mean^2-mean)*(mean-1)/variance}
from which you can write your own function pretty easily.
Duncan Murdoch
More information about the R-help
mailing list