[R] term.formula error when updating an nls object
Peter Ehlers
ehlers at ucalgary.ca
Wed Jan 27 12:17:37 CET 2010
Ken,
You just need to wrap the rhs of your formula in I() to
get around update()'s parsing of terms.
m2 <- update(m1, . ~
I(Rm * Contrast^ex/(Contrast^fx + sig^fx)),
start = list(Rm = 30, sig = 0.05, ex = 3,
fx = 3.1))
-Peter Ehlers
Ken Knoblauch wrote:
> Hi,
>
> I'm getting an error that I don't understand when updating an nls
> object. Here is a toy example.
>
> dd <- structure(list(Contrast = c(0.00376, 0.03759, 0.12782, 0.25564,
> 0.50376, 1), Response = c(0.29915, 6.13248, 29.01709, 30.0641,
> 29.46581, 27.67094)), .Names = c("Contrast", "Response"), class =
> "data.frame", row.names = c(NA,
> -6L))
>
> m1 <- nls(Response ~
> Rm * Contrast^ex/(Contrast^ex + sig^ex),
> data = dd,
> start = list(Rm = 30, sig = 0.05, ex = 3))
>
> m2 <- update(m1, . ~
> Rm * Contrast^ex/(Contrast^fx + sig^fx),
> start = list(Rm = 30, sig = 0.05, ex = 3,
> fx = 3.1))
> Error in terms.formula(tmp, simplify = TRUE) : invalid power in formula
>
> but there is nothing wrong with fitting the second model directly
> with nls
>
> m2a <- nls(Response ~
> Rm * Contrast^ex/(Contrast^fx + sig^fx),
> data = dd,
> start = list(Rm = 30, sig = 0.05, ex = 3,
> fx = 3.1))
>
>
> nor with fitting the model with the data transformed (though it is
> not necessarily the way I would like to fit the model in this
> case).
>
> m2b <- update(m1, log(.) ~ log(.))
> m3 <- update(m2b, . ~
> log(Rm * Contrast^ex/(Contrast^fx + sig^fx)),
> start = list(Rm = 30, sig = 0.05, ex = 3,
> fx = 3.1))
>
> sessionInfo()
> R version 2.10.1 Patched (2010-01-25 r51051)
> i386-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods
> [7] base
>
> Thanks, in advance, for any help.
>
> Ken
>
--
Peter Ehlers
University of Calgary
More information about the R-help
mailing list