require(fracdiff)
#load your data, n is the sample size
x<-matrix(scan("data.txt", n =), n, 1, byrow = TRUE)
x<-log(x)
x<-x-mean(x)
n<-length(x)
#select the truncation
m<-round(n^(0.7))
perdx<-px[2:n]
fn<-function(h)
{
lambda<-freq[1:m]^(2*h-1)
Gh=mean(perdx[1:m]*lambda)
Rh=log(Gh)-(2*h-1)*mean(log(freq[1:m]))
return(Rh)
}
est<-optimize(fn,c(0,1.5),tol = 0.00001)
hhat<-est$minimum
b <- hhat-0.5
b
我有這個功能寫在R和I想爲m,其中m < -round(N ^(0.7))其中,從0.3-0.8運行n的功率(do循環默認值是0.7,所以我給函數提供了不同的m值),並且最終得到b的字符串(每個b的冪爲從0.3-0.8開始),但到目前爲止我一直不成功。此外,我想繪製關於m的b的不同值。我真的希望任何人都可以建議我如何得到結果。任何建議非常感謝。謝謝。循環在功能,使用R
請給出'freq'和'perdx' [讓示例可重現](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – Roland
-1因爲1)這仍然不可重複; 2)在某人(我)回答之後,您更改了問題的參數; 3)爲什麼要求(fracdiff)'?代碼中的每個函數都在'base'中。 – plannapus