[R] selfStart function problem
Douglas Bates
bates at stat.wisc.edu
Wed Aug 14 16:14:03 CEST 2002
"Lauri Mehtätalo" <Lauri.Mehtatalo at metla.fi> writes:
> 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
> + }
Although I am responding quite late to this message I hope this will
help. I did not see other responses.
The recommended way of handling LHS inside the start function is as
xy <- sortedXyData(mCall[["D"]], LHS, data)
That will provide you with a data frame with variables 'x' and 'y'
that result from evaluating the expressions for the D argument and the
left hand side.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list