I am trying to compute probability of exceedance
in R. Here is the link that has detail and formula for computing exceedance probability. I tried to replicate the procedure with the following sample code, however, I am no way near the attached example plotting. Once, i figured out how to do this- i would then like to apply the procedure on a data.frame
that has multiple variables
.
library(tidyverse)
A = sample(0:5000, 2500)
A = A[order(A, decreasing = TRUE)]
Rank = 1:2500
DF = data.frame(cbind(A,Rank))
DF$Prob = 100*(DF$Rank/(length(DF$Prob+1)))
ggplot(data = DF, aes(x=Prob, y=A))+
geom_line() + scale_y_continuous(trans = "log10")
The formula to compute Prob
is not well implemented in the question. it is adding 1 to DF$Prob
and then taking its length
when it should add 1 to the length
.
DF <- data.frame(A, Rank)
DF$Prob <- DF$Rank/(length(DF$Rank) + 1)
ggplot(data = DF, aes(x = Prob, y = A)) +
geom_line() +
scale_x_continuous(breaks = seq(0, 1, by = 0.20),
labels = percent) +
scale_y_continuous(trans = "log10")
Data creation code.
I have changed the data set example.
The code below is reproducible, since set.seed
is used and the sample
has decreasing probabilities.
set.seed(1234)
A <- sample(0:5000, 2500, prob = exp(seq(10, 0, length.out = 5001)))
A <- A[order(A, decreasing = TRUE)]
Rank <- 1:2500