0
input <- "
t y
1 5.3
2 7.2
3 9.6
4 12.9
5 17.1
6 23.2"
dat<-read.table(textConnection(input),header=TRUE,sep="")
t<-dat[,1]
y<-dat[,2]
y=3.975*(1.341^t)
是合適的結果,我該如何使用nls
函數來得到它?
也許問題是如何表達公式?如何擬合指數曲線如a * b^t in r?
nls(y~(a*b^t))
Error in getInitial.default(func, data, mCall = as.list(match.call(func, :
no 'getInitial' method found for "function" objects
通過你的知識/經驗。根據公式,兩者都應該大於零。總是t = 1的值可用嗎?如果是,請將此用於'a'的值。採取第二個,並計算(不適合)B,並使用它。如果他們從錯誤的地方開始,非線性擬合可能會失敗(或只找到最小值)。順便說一下a = 10,b = 10也起作用。 –
考慮使用log(texp)代替t來避免getInitial失敗的簡單策略。 –