I am making a self-starting nonlinear function to model the relation
of tree height (H) and diameter (D) in a forest stand. The function
I am trying is H=a*exp[b*(D+5.8)^(-c)]. To calculate the initial
estimates of the parameters, I linearized the formula by taking
logarithms and fixing the parameter c=1. Then I calculated the
initial estimates of a and b using lm() on the linearized form. The
function works well if I am giving a single variable as an dependent
variable, but if I use some transformation of height (e.g. (H-1.3))
as dependent variable, the expression in lm()-model is not
right. That is perhaps because of the mode of the object LHS is now
"call", but I have not found how to get the program handle it
correctly. Has someone any idea? I am using R1.5.1 on Windows NT.
Lauri
My code is
dhexp <- deriv(~ a*exp(b*(D+5.8)^(-c)), c("a","b","c"), function(D,a,b,c) {} )
dhexpInit <- function(mCall, LHS, data) {
+ equation <- paste('log(',LHS,') ~ I((',mCall[["D"]],'+5.8)^-1.0)')
+ print(equation)
+ linear <- lm(as.formula(equation),data=data)
+ value <- c(exp(coef(linear)[1]), coef(linear)[2], 1.0)
+ names(value) <- mCall[c("a", "b", "c")]
+ value
+ }