[18915] in s-news-athena

home help back first fref pref prev next nref lref last post

[S] Splus symbolic manipulation

daemon@ATHENA.MIT.EDU (alan9@carpal.ucsf.edu)
Tue Aug 10 21:28:11 1999

From: alan9@carpal.ucsf.edu
Date: Tue, 10 Aug 1999 18:23:56 -0700 (PDT)
Message-Id: <199908110123.SAA04320@carpal.ucsf.edu>
To: s-news@wubios.wustl.edu


I'm using Splus to fit data to some non-linear models derived from a base
function.  The fit formula itself is made up of a composite function consisting
of the sum of the partials of the base function.  The form of the base function
is the only thing I want to change directly as the partials and resulting
composite function get pretty long.

I've got a function of three independents, M(x,y,z).  I want to calculate
partials with respect to the independents:

	DxM <- partial of M with respect to x
	DyM <- partial of M with respect to y
	DzM <- partial of M with respect to z

And then build a composite function that I can then use in a formula to
a non-linear fitting function such as nlme or nlsList:

	GrM <- m1 * DxM + m2*DyM + m3*DzM

	nlme(formula=s~GrM(. . . ),data= . . . .)

I wanted to use deriv and managed to get the partials, but I couldn't see
how to separate and combine the elements from the three different calls.

I then tried using D() and paste() as follows:

deriv.f <- function( M )
{
	DxM <- D(M,c("x"))
	DyM <- D(M,c("y"))
	DzM <- D(M,c("z"))

	t1 <- paste("m1 * ( ", deparse(DxM), " ) ")
	t2 <- paste("+ m2 * ( ", deparse(DyM), " ) ")
	t3 <- paste("+ m3 * ( ", deparse(DzM), " ) ")

	paste(t1,t2,t3)
}

Calling deriv.f with M <- a*x*y*z

> deriv.f(M)
[1] "m1 * ( . . . rest of stuff looks ok . . . "
>

How can I now get this vector to be the body of a function?

Or, is there a much better approach that I've missed?

Any help appreciated.  Will post summary of replies.

Thanks.

Frank Ashford
Assistant Development Engineer
UCSF Orthopaedic Bioengineering Laboratory
(alan9@carpal.ucsf.edu)
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post