[R] Function not working as I'd like

David Carlson dcarlson at tamu.edu
Wed Oct 23 20:58:17 CEST 2013

Your problem is here


That produces a logical vector of TRUE/FALSE values, but the
length of the vector stays the same even though the number of
TRUEs is changing. Try 


David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of smugg55
Sent: Wednesday, October 23, 2013 9:25 AM
To: r-help at r-project.org
Subject: [R] Function not working as I'd like

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
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 =
+ ans = data.frame(p = prob, quantile = q, tail.expectation =
empirical.prob = ep)
+ ans
+ }

Note that there are no problems pulling xi, beta, and u, and es
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
correctly, as that number should be decreasing as the quantile

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

View this message in context:
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible

More information about the R-help mailing list