簡體   English   中英

R / S中的非線性回歸

[英]Nonlinear regression in R / S

我有一個與R / S /非線性回歸相關的問題,我不是R程序員,所以我需要幫助。

我有兩個數組-tt和td。

我需要找到參數a,b和c,因此對於非線性函數,最小二乘法的總和最小:

td / tt - a * exp( b * tt ) + c 

我不知道該怎么做。 我嘗試了nls()函數, nls2() nad沒有運氣...

提前致謝。

編輯:

我的資料:

td <-as.array(0.2, 0.4, 0.8, 1.5, 3);

tt <-as.array(0.016, 0.036, 0.0777, 0.171, 0.294);

使用以下答案中的方法,我獲得了隨機數據的確定值,但是我使用的數據返回缺少值或評估模型消息時產生的無窮大。

很抱歉沒有盡快提供數據。

您的數據:

n <- 100
td <- runif(n)
tt <- runif(n)
data <- data.frame(td = td, tt = tt)

功能的組合結果

a <- 0.5
b <- 2
c <- 5
y <- jitter(td / tt - a * exp( b * tt ) + c)

(實際上,直到那時您才知道a,b和c是什么。在這里,我們將它們與答案進行比較。)

擬合:

nls(
  y ~ td / tt - a * exp( b * tt ) + c, 
  data = data, 
  start = list(a = 1, b = 1, c = 1)
)

答案:

Nonlinear regression model
  model:  y ~ td/tt - a * exp(b * tt) + c 
   data:  data 
     a      b      c 
0.4996 2.0008 4.9994 
 residual sum-of-squares: 0.0001375

Number of iterations to convergence: 7 
Achieved convergence tolerance: 1.604e-06

暫無
暫無

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

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