[R] Self-starting nonlinear power law function
Scherber, Christoph
cscherb1 at gwdg.de
Wed Dec 4 12:03:19 CET 2013
Dear all,
I have just written the self-starting power law function myself. Here it is:
##
# Self-starting power law function written by C. Scherber
powermodel=function(x,a,b,c)
{a+b*x^c}
powermodelInit=function(mCall,LHS,data){
xy=sortedXyData(mCall[["x"]],LHS,data)
lmFit1=lm(xy[,"y"]~1) #for "intercept", a
lmFit2=lm(log(xy[,"y"])~log(xy[,"x"])) #for b and c
coefs1=coef(lmFit1)
coefs2=coef(lmFit2)
a=coefs1
b=exp(coefs2[1])
c=coefs2[2]
value=c(a,b,c)
names(value)=mCall[c("a","b","c")]
value
}
SSpower=selfStart(powermodel,powermodelInit,c("a","b","c"))
##
# make sure that x and y are positive when using the function.
Best wishes,
Christoph
More information about the R-help
mailing list