[R] Function not working as I'd like

smugg55 michael.jensen at oliverwyman.com
Wed Oct 23 16:25:14 CEST 2013


Hey all,

So I wrote/borrowed some code (no, I'm not trying to claim all of the work
I've done below as my own). Ideally what I'd like the code to do is
calculate ep for each iteration of q. Here's the code:

> gpdriskmeasures = function(x , prob =
> c(0,.1,.2,.25,.3,.4,.5,.6,.7,.75,.8,.9,.95,.99))
+ {
+ xi = gpd.model$par.ests["xi"]
+ beta = gpd.model$par.ests["beta"]
+ u = gpd.model$threshold
+ q = u + (beta*((1-prob)^(-xi)-1))/xi
+ es = (q + (beta - xi * u))/(1 - xi)
+ ep =
1-length(ninetyoneclaims$total.chg[ninetyoneclaims$total.chg>q])/length(ninetyoneclaims$total.chg)
+ ans = data.frame(p = prob, quantile = q, tail.expectation = es,
empirical.prob = ep)
+ ans
+ }

Note that there are no problems pulling xi, beta, and u, and es calculates
correctly. I'll also show what the results look like:

> gpdriskmeasures(ninetyoneclaims$total.chg)
      p  quantile tail.expectation empirical.prob
1  0.00  200000.0         336856.8      0.9878478
2  0.10  210058.6         351517.2      0.9878478
3  0.20  221704.1         368490.5      0.9878478
4  0.25  228270.1         378060.5      0.9878478

As you can see the empirical.prob (which is ep) is not calculating
correctly, as that number should be decreasing as the quantile (q)
increases.

Any help would be most appreciated! Thanks in advance for anyone that can
help.



--
View this message in context: http://r.789695.n4.nabble.com/Function-not-working-as-I-d-like-tp4678878.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list