Earlier, I posted a question concerning the syntax of nls() when the
nonlinear function within the call is specified outside of nls().
Sundar showed me how to do this. Now I have a slightly more complex
problem that is analogous to a broken-stick regression but in a
non-linear context.
I want my data to be fit to a non-rectangular hyperbola if the value of
the independent variable (I) is less than some value (�Icut�, to be
estimated) and to be fit to a constant value (to be estimated) if the
value of the independent variable is greater than or equal to �Icut�.
That is, if the value of the independent variable is less than Icut,
then fit the non-rectangular hyperbola, otherwise fit a constant.
Here is the function that I wrote. �a� is the non-rectangular hyperbola
and �b� is the constant. When I give this to nls() I get an error
message stating:
Error in nlsModel(formula, mf, start) : singular gradient matrix at
initial parameter estimates
> NRHyperbolic.cut
function (Am,alpha,theta,Rd,I,Icut,const)
{
b<-rep(1e6,length(I))
yes<- (I>=Icut)
vec<-as.numeric(yes)
a<-(1/(2*theta))*(alpha*I+Am-sqrt((alpha*I+Am)^2-4*theta*alpha*I*Am))-Rd
b[yes]<-vec[yes]*rep(const,length(I[yes]))
apply(cbind(a,b),1,min)
}
This is a non-rectangular hyperbola (a)
Bill Shipley
Subject Matter Editor, Ecology
North American Editor, Annals of Botany
D�partement de biologie, Universit� de Sherbrooke,
Sherbrooke (Qu�bec) J1K 2R1 CANADA
[EMAIL PROTECTED]
<http://callisto.si.usherb.ca:8080/bshipley/>
http://callisto.si.usherb.ca:8080/bshipley/
[[alternative HTML version deleted]]
______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html