Skip to content
Prev 74868 / 398502 Next

passing variable to formula environment

Eric Archer wrote:
Hi, Eric,

I think the easiest way to do this is to use substitute:

# return gompertz fit
Gompertz <- function(data, Xintercept, Lzero, start) {
   gomp <- substitute(length ~ Lzero * exp(k * (1 - exp(-g * (age - 
Xintercept)))),
                      list(Xintercept = Xintercept, Lzero = Lzero))
   nls(gomp, data, start)
}

Gompertz(growth, 0, 87, list(k = 0.5, g = 0.5))

HTH,

--sundar