【问题标题】:Error: min(p, na.rm = TRUE) >= 0 is not TRUE错误:min(p, na.rm = TRUE) >= 0 不是 TRUE
【发布时间】:2013-12-06 00:55:38
【问题描述】:

我在第 32 页遇到了 interesting presentation,我开始复制并理解所提供的代码

演示文稿中的代码如下:

#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

附加问题

非常感谢影子。

我不知道如何更改函数引用。 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]) )

【问题讨论】:

  • theta[1] 或 theta[2] 是否永远小于零?您将两者都作为需要为正的参数发送。

标签: r


【解决方案1】:

这里出现错误的原因是包fExtremesevir 都实现了函数qgpd 的不同版本。在evir 版本中,p 可以小于0,而fExtremes 包仅实现qgpdp&gt;=0

最简单的解决方案是将qgpd 函数调用更改为evir:::qgpd

【讨论】:

    猜你喜欢
    • 2016-04-15
    • 2017-01-28
    • 2013-03-27
    • 2020-12-19
    • 1970-01-01
    • 2019-10-04
    • 2017-05-22
    • 1970-01-01
    • 2018-01-17
    相关资源
    最近更新 更多