I need to constrain the parameters a and m within the following least squares fitting code of a nonlinear curve, I am using R
set.seed(1)
pacman::p_load(gslnls)
n <- 50
Datos <- data.frame(
theta = (1:n) / n,
Xb_exp = 2.5 * exp(-1.5 * (1:n) / n) + rnorm(n, sd = 0.1))
plot(Datos$theta,Datos$Xb_exp)
Ajuste<- gsl_nls(fn=y~1-exp(-a*((x-(-2))/length(Xb_exp))^(m+1)),
data=data.frame(y=Datos$Xb_exp, x=Datos$theta), start=c( a= 1, m= 1), algorithm = "lmaccel", control = gsl_nls_control(scale = "levenberg", avmax = 0.75),trace = TRUE,)
summary(Ajuste)
a<- predict(Ajuste, interval="prediction", level=0.99)
a<- a[, -c(2,3)]
Datos<- dplyr::mutate(Datos, Xb_mod=a)
plot(Datos$theta, Datos$Xb_mod)