Skip to content

need suggestion about building formual

2 messages · Simple, Spencer Graves

#
Thanks for your kind respond. Although the answer didn't solve my question 
clearly,maybe I still not understand the art of R.

I'm sorry that I had not talked the problem clearly, maybe a example with more 
detail will be suitable as suggested in the the posting guide.
 
In function fitting program, such as Sigmaplot, a fitting formula, can be  
write in separate form:
G=a+(b*x)^(1/2)
k=exp((G-G0)/(R*T))
fit k to y

of course,in R's nls, can write as:
mynls<-nls(formula=y~exp((a+(b*x)^(1/2)-G0)/(R*T)),data=mydata,...)

In this example, the formula is simple and acceptable. However, when the 
formula is more complexity,writing all in one formula,the readability will be 
damaged.So I'm looking for a way to write simple and readable code in this 
situation.
Spencer Graves wrote:
10 days later
#
Have you considered writing a function to do the complex math and 
then calling nls referring to that function?  Consider the following 
(not tried):

expg <- function(a., x, G0, R, T){
	exp((a.[1]+(a.[2]*x)^(1/2)-G0)/(R*T))
}

mynls<-nls(formula=y~expg(a.=c(a, b), x=x, G0=G0, R=R, T=T),
       data=mydata,...)

	  If "nls" stops prematurely, I then write another function, "SSE" to 
compute the sum of squares of deviations from y and then ask "optim" to 
minimize "SSE", using "hessian=TRUE".  If you try this and have trouble 
making it work, please send another post.

	  spencer graves
Simple wrote: