簡體   English   中英

錯誤:min(p,na.rm = TRUE)> = 0不是TRUE

[英]Error: min(p, na.rm = TRUE) >= 0 is not TRUE

我在第32頁上遇到了一個有趣的演示 ,我開始復制並理解了所提供的代碼

演示文稿中的代碼如下:

#Unicredit banks code
library(evir)
library(fExtremes)
# Quantile function of lognormal-GPD severity distribution
qlnorm.gpd = function(p, theta, theta.gpd, u)
  {
    Fu = plnorm(u, meanlog=theta[1], sdlog=theta[2])
    x = ifelse(p<Fu,
               qlnorm( p=p, meanlog=theta[1], sdlog=theta[2] ),
               qgpd( p=(p - Fu) / (1 - Fu) , xi=theta.gpd[1], mu=theta.gpd[2], beta=theta.gpd[3]) )
  return(x)
  }
# Random sampling function of lognormal-GPD severity distribution

rlnorm.gpd = function(n, theta, theta.gpd, u)
  {
  r = qlnorm.gpd(runif(n), theta, theta.gpd, u)
  }

set.seed(1000)
nSim = 1000000 # Number of simulated annual losses
H = 1500 # Threshold body-tail
lambda = 791.7354 # Parameter of Poisson body
theta1 = 2.5 # Parameter mu of lognormal (body)
theta2 = 2 # Parameter sigma of lognormal (body)
theta1.tail = 0.5 # Shape parameter of GPD (tail)
theta2.tail = H # Location parameter of GPD (tail)
theta3.tail = 1000 # Scale parameter of GPD (tail)
sj = rep(0,nSim) # Annual loss distribution inizialization
freq = rpois(nSim, lambda) # Random sampling from Poisson
for(i in 1:nSim) # Convolution with Monte Carlo method
  sj[i] = sum(rlnorm.gpd(n=freq[i], theta=c(theta1,theta2), theta.gpd=c(theta1.tail, theta2.tail, theta3.tail), u=H))

但是我遇到了無法解決的錯誤:

Error: min(p, na.rm = TRUE) >= 0 is not TRUE

附加問題

非常感謝Shadow。

我不知道如何更改功能參考。 像qgpd.fExtremes到qgpd.evir一樣容易嗎?

再次感謝Shadow指出這一點。 對於任何希望更改對不同包中的函數的引用的人(在上面的示例中,從fExtremes到evir的添加,就像添加evir :: :( function)一樣簡單。

例:

evir:::qgpd( p=(p - Fu) / (1 - Fu) , xi=theta.gpd[1], mu=theta.gpd[2], beta=theta.gpd[3]) )

在這里出現錯誤的原因是軟件包fExtremesevir都實現了qgpd函數的不同版本。 evir版本中, p可以小於0,而fExtremes軟件包僅對p>=0實施qgpd

最簡單的解決方案是將qgpd函數調用更改為evir:::qgpd

暫無
暫無

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

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