R 中指数衰减或逻辑增长的预测

Prediction of Exponential Decay or Logistic Growth in R

我试图在 R 中预测一些东西,但我不确定应该使用什么语法。我知道,对于多项式,我可以这样做:

predict(glm(Y ~ X +I(X^2) + I(X^3) +... I(X^n),data=mydata))

我已经成功了,但我想知道如何预测形式的方程

y = C(1-e^(-kx))

y = a/(1 + b*e^(-kx)), k>0

我不确定我可以提供什么示例数据来很好地说明这一点...

一个例子:

    set.seed(1234)
    # Parameters for simulated data
    C<-1
    k<-2
    # Set x values and compute y for them
    x<-seq(-100,120,1)/100
    y<-C*(1-exp(-k*x))+rnorm(length(x),sd=0.1)
    # Plot the points
    plot(x,y); grid()
    # Do the fit
    fit<-nls(y ~ C*(1-exp(-k*x)), data=data.frame(y,x), start=list(C=5,k=5))
    # Plot the fit
    lines(x, predict(fit, list=(x=x)), col="red")

    > fit
    Nonlinear regression model
      model: y ~ C * (1 - exp(-k * x))
       data: data.frame(y, x)
        C     k 
    1.022 1.987 
     residual sum-of-squares: 2.147

    Number of iterations to convergence: 8 
    Achieved convergence tolerance: 1.338e-07