Re: [R] solving equation system

From: Spencer Graves <>
Date: Fri 24 Jun 2005 - 02:30:30 EST

          Have you considered writing a function to compute the sum of squares of deviations from equality and using "optim"? I use sum of squares not sum of absolute values, because if my functions are differentiable, the sum of squares will also be differentible while the sum of absolute values will not be. This means that sum of absolute values will not work well with a quasi-Newton algorithm.

          Also, have you considered making plots? If I understand your example, you can solve for lambda using (II) as lambda = x/mean(X). Then you can use (I) to solve for "c". To understand this, it would help to plot the digamma function. If you do this (e.g.,, you will see that there are countably infinite solutions to this equation. If you want the positive solution, I suggest you try to solve for ln.c = log(c) rather than "c" directly, because that should make "optim" more stable.   More generally, it often helps to make, e.g., contour or perspective plots and to try to find a parameterization that will make the sum of squares of errors approximatly parabolic in your parameters.

          My favorite reference on this is Bates and Watts (1988) Nonlinear Regression Analysis and Its Applications (Wiley). There may be better, more recent treatments of this subject, but I am not familiar with them.

          spencer graves
p.s. I never (no never, not ever) use "c" as a variable name, because it is the name of a common R function. R is smart enough to distinguish between a function and a non-function in some contexts but not in all. When I want a name for a new object, I routinely ask R to print my proposed name. If it returns "Error: object ... not found", I can use "...".

Carsten Steinhoff wrote:

> Hello,
> I want to solve some two dimensional equation system with R. Some systems
> are not solvable analytically.
> Here is an example:
> (I) 1/n*sum{from_i=1_to_n}(Xi) = ln lambda + digamma(c)
> (II) mean(X) = x / lambda
> I want to find lambda and c,
> which R-function could do that task?
> Carsten
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA <>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Fri Jun 24 02:34:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:00 EST