[R] Solving Systems of Non-linear equations
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Nov 30 17:37:42 CET 2005
Go to http://mathomatic.orgserve.de/math/ and install mathomatic
(its free) or just connect to the online server and do this.
The C output, i.e the result of the two code c commands,
can be used verbatim in R.
Note that mathomatic does not support logs but for simply
problems like this its very useful.
Note that 1-> and 2-> are the mathomatic prompts and what
comes after them are what I typed in. The entry goes into
the corresponding equation space, i.e. equation 1 or equation 2.
1-> mean = a/(a+b)
a
#1: mean = -------
(a + b)
1-> variance = (a*b)/(((a+b)^2) * (a+b+1))
a*b
#2: variance = -------------------------
(((a + b)^2)*(a + b + 1))
2-> eliminate b
Solving equation #1 for (b)...
1
(a^2)*(---- - 1)
mean
#2: variance = ---------------------------------------------------
1 1
(((a + (a*(---- - 1)))^2)*(a + (a*(---- - 1)) + 1))
mean mean
2-> a
mean*(1 - mean)
#2: a = mean*(--------------- - 1)
variance
2-> simplify
((mean^2) - (mean^3))
#2: a = --------------------- - mean
variance
2-> eliminate a
Solving equation #1 for (a)...
b*mean ((mean^2) - (mean^3))
#2: ---------- = --------------------- - mean
(1 - mean) variance
2-> b
mean*(1 - mean)
#2: b = (--------------- - 1)*(1 - mean)
variance
2-> simplify
((mean^2) - mean)
#2: b = (1 + -----------------)*(mean - 1)
variance
2-> code c
b = ((1.0 + (((mean * mean) - mean) / variance)) * (mean - 1.0));
2-> #1
b*mean
#1: a = ----------
(1 - mean)
1-> code c
a = (b * mean / (1.0 - mean));
On 11/30/05, Scott Story <sstory at montana.edu> 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.
>
>
>
> --
> Scott Story
> Graduate Student
> MSU Ecology Department
> 319 Lewis Hall
> Bozeman, Mt 59717
> 406.994.2670
> sstory at montana.edu
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list