简体   繁体   English

R的指数衰减或对数增长的预测

[英]Prediction of Exponential Decay or Logistic Growth in R

I'm trying to predict something in R, and I'm not sure what syntax I should use. 我正在尝试预测R中的某些内容,但不确定应使用哪种语法。 I know that, for a polynomial, I can do: 我知道,对于一个多项式,我可以做到:

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

which I have been successful with, but I am wondering how to predict equations of the form 我已经成功完成了,但是我想知道如何预测形式的方程

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

or 要么

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

I'm not sure what example data I can give to illustrate this well... 我不确定我可以提供哪些示例数据来很好地说明这一点...

An example: 一个例子:

    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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM