簡體   English   中英

R 中的指數衰減 Model 的自啟動函數

[英]Self Starting Functions for Exponential Decay Model in R

我正在研究指數衰減 model 我想估計衰減率。 我當前的 model 使用自啟動SSasymp ,來自stats package 的 SSasymp。 我還編寫了第二個 model,我只關注啟動參數,這需要minpack.lm package。 我的問題是,有沒有另一種方法可以估計起始參數來交叉檢查SSasymp function。 我(認為)我了解代碼在估算起始參數時所做的工作,但我想獲得一些反饋,說明SSasymp是否適合與此數據一起使用的 function 或者是否還有另一個 function 我可以使用。

library(stats)
library(minpack.lm)
library(broom)
library(ggplot2)

df<-data.frame(Date=seq(1:66),
           Level=c(1438072839.75,   1397678053.5,   1358947420.5,   1313619938.25,  1269224528.25, 
1246776954.75,  1207201162.5,   1176229091.25,  1136063160, 1103721704.25,  1080591637.5,    
1048286667, 1017840460.5,   1001057052, 975815001,  943568665.5,    932026210.5,    916996593.75,    
903904288.5,    887578544.25,   871428547.5,    855417720,  843504839.25,   825835607.25,    
816060303.75,   803506361.25,   801213123,  797977217.25,   793483994.25,   780060123,  766265609.25,    
756172471.5,    746615497.5,    738002936.25,   723741644.25,   711969181.5,    696032998.5,     
686162453.25,   671953166.25,   674184571.5,    664739475,  641091932.25,   627358484.25,    
616740068.25,   602261552.25,   592440797.25,   584160403.5,    569780103.75,   556305753,   
551682927,  546535062,  537782506.5,    524251944.75,   519277188.75,   503598795,  498481312.5,     
487907885.25,   479760227.25,   474773064.75,   468246932.25,   460561701,  455266345.5,     
448451890.5,    447760119,  441236056.5,    438884417.25))

dfDecay<-nls(Level~ SSasymp(Date, Asym, R0, lrc), data = df)
dfFitted<-augment(dfDecay)
ggplot(df, aes(x=Date,y=Level))+geom_point()+  geom_line( aes(y=dfFitted$.fitted), color="red")

dfDecay2<-nlsLM(Level~b*exp(-a*Date), 
                   data = df,
                   start= list(a=.01,b=1.5e+09),
                   algorithm = "LM")
fitDecay2<-augment(dfDecay2)
ggplot(df, aes(x=Date,y=Level))+geom_point()+  geom_line( aes(y=fitDecay2$.fitted), color="red")

關於起始值:

  1. 取兩邊的原木並安裝線性 model。
  2. 參數應該具有相似的大小以避免數值問題,因此使用Level/1e9代替Level 這只是改變了測量 Level 的單位。
  3. 使用線性 model 的起始值, nls應該足夠了。

這給出了:

fm0 <- lm(log(Level/1e9) ~ Date, df)
st <- list(a = exp(coef(fm0)[[1]]), b = -coef(fm0)[[2]])
nls(Level/1e9 ~ a * exp(-b * Date ), df, start = st)

給予:

Nonlinear regression model
  model: Level/1e+09 ~ a * exp(-b * Date)
   data: df
     a      b 
1.3532 0.0183 
 residual sum-of-squares: 0.08055

Number of iterations to convergence: 4 
Achieved convergence tolerance: 4.023e-07

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM