philippe massicotte
2014-Dec-03 12:37 UTC
[R] Substitute initial guesses of parameters in a function
Hi everyone, I have a formula like this: f <- as.formula(y ~ p0a * exp(-0.5 * ((x - p1a)/p2a)^2)) I would like to "dynamically" provide starting values for p0a, p1a, p2a. Is there a way to do it? #Params estimates p <- c(12, 10, 1) # This is where I have difficulties mystart <- substitute(...) nls(formula = f, start = mystart) Regards, Philippe [[alternative HTML version deleted]]
Duncan Murdoch
2014-Dec-03 13:02 UTC
[R] Substitute initial guesses of parameters in a function
On 03/12/2014 7:37 AM, philippe massicotte wrote:> Hi everyone, I have a formula like this: > > f <- as.formula(y ~ p0a * exp(-0.5 * ((x - p1a)/p2a)^2)) > > I would like to "dynamically" provide starting values for p0a, p1a, p2a. Is there a way to do it?Just give a named vector of starting values.> > #Params estimates > p <- c(12, 10, 1)Should be p <- c(p0a = 12, p1a = 10, p2a = 1)> > # This is where I have difficulties > mystart <- substitute(...) > > nls(formula = f, start = mystart)Now start = p will work. No need to mess with substitute. (And no need to use as.formula on the very first line; that's already a formula.) Duncan Murdoch> > Regards, > Philippe > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
philippe massicotte
2014-Dec-03 16:09 UTC
[R] Substitute initial guesses of parameters in a function
Thank you!> Date: Wed, 3 Dec 2014 08:02:17 -0500 > From: murdoch.duncan at gmail.com > To: pmassicotte at hotmail.com; r-help at r-project.org > Subject: Re: [R] Substitute initial guesses of parameters in a function > > On 03/12/2014 7:37 AM, philippe massicotte wrote: > > Hi everyone, I have a formula like this: > > > > f <- as.formula(y ~ p0a * exp(-0.5 * ((x - p1a)/p2a)^2)) > > > > I would like to "dynamically" provide starting values for p0a, p1a, p2a. Is there a way to do it? > > Just give a named vector of starting values. > > > > #Params estimates > > p <- c(12, 10, 1) > > Should be p <- c(p0a = 12, p1a = 10, p2a = 1) > > > > # This is where I have difficulties > > mystart <- substitute(...) > > > > nls(formula = f, start = mystart) > > Now start = p will work. No need to mess with substitute. (And no need > to use as.formula on the very first line; that's already a formula.) > > Duncan Murdoch > > > > Regards, > > Philippe > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]