R 极值理论:寻找阈值

R 极值理论:寻找阈值,r,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<-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"))

怎么解决呢??我做错了什么

您正在使用哪些外部库
Is单变量
as.timeSeries
不是基函数。我怀疑您的问题是当您使用.timeSeries(data(bet))而与
threshold
函数无关时。您的
bet
数据的小样本也会很有用。
Error in as.POSIXct.numeric(time(x)) : 'origin' must be supplied