Conditional nls

I am trying to install conditional nls using R 2.15.1. The same code worked fine with R 2.13, but now R 2.15.1 throws errors.

x <- seq(from = 17, to = 47, by = 5)
y <- c(26.2, 173.6, 233.9, 185.9, 115.4, 62.0, 21.7)
Data <- data.frame(y, x)

Fit <- nls(formula =  y ~ ifelse(test = x <= Mu, yes = Mean <- c1*exp(-((x-Mu)/Sigma11)^2), no =  Mean <- c1*exp(-((x-Mu)/Sigma12)^2)),
       data = Data, start = list(c1 = 240, Mu = 25, Sigma11 = 5, Sigma12 = 14), algorithm = "port",
       lower = list(Sigma11 = 0, Sigma12 = 0))

      

Mistake

Error in nls(formula = y ~ ifelse(test = x <= Mu, yes = Mean <- c1 * exp(-((x -  : 
  parameters without starting value in 'data': Mean

      

Edited

I am coming up with the following model:

$f(x) = c_{1}  \exp\left(-\left(\frac{x-\mu}{\sigma_{(x)}}\right)^2\right)$

where $\sigma_{(x)} = \sigma_{11}$ if  $x \le \mu$ and $\sigma_{(x)} = \sigma_{12}$ if  $x > \mu$

      

0


source to share


1 answer


This code works in R 2.15.1.



x <- seq(from = 17, to = 47, by = 5)
y <- c(26.2, 173.6, 233.9, 185.9, 115.4, 62.0, 21.7)
Data <- data.frame(y, x)

Fit <- nls(formula =  y ~ ifelse(test = x <= Mu, ye = c1*exp(-((x-Mu)/Sigma11)^2), no = c1*exp(-((x-Mu)/Sigma12)^2)),
       data = Data, start = list(c1 = 240, Mu = 25, Sigma11 = 5, Sigma12 = 14), algorithm = "port",
       lower = list(Sigma11 = 0, Sigma12 = 0))

      

0


source







All Articles