极值理论:找到门槛

时间:2014-05-22 04:30:28

标签: r

我有代码来查找一系列退货的超额:

bet<-read.csv("Book1.csv")
bet

threshold <- function(bet, n = floor(0.05 * length(as.vector(bet))), 
                      doplot = TRUE) 
{    
  if (class(bet) == "timeSeries") {
    stopifnot(isUnivariate(bet))
  } else {
    bet = as.vector(bet)
  }

  X = rev(sort(as.vector(bet)))
  thresholds = unique(X)  
  indices = match(X[n], thresholds)  
  indices = pmin(indices + 1, length(thresholds))
  ans = thresholds[indices]
  names(ans) = paste("n=", as.character(n), sep = "")

  if (doplot) {         
    plot(x, type = "h", col = "steelblue", main = "Threshold Value")   
    grid()
    rug(as.vector(x), ticksize = 0.01, side = 4)    
    for (u in ans) {
      abline(h = u, lty = 3, col = "red")
    }
  }
  ans
}

## findThreshold -
# Threshold giving (at least) 200 exceedances for Bet:
bet = as.timeSeries(data(bet))
threshold(bet, n = c("monthly", "quarterly"))

运行程序后,出现以下错误:

Error in as.POSIXct.numeric(time(x)) : 'origin' must be supplied

怎么解决?我究竟做错了什么?

0 个答案:

没有答案