GEV distribution and probability error

Hi, could you please help me out with this error?
Error in pgev(threshold, loc = location, scale = scale, shape = shape, :
invalid shape
In addition: Warning message:
In min(scale) : no non-missing arguments to min; returning Inf

I'm trying to calculate probability of value exceeding 1.8 from this data set

Install and load necessary packages

if (!requireNamespace("extRemes", quietly = TRUE)) {
install.packages("extRemes")
}
library(extRemes)

Your provided data

data <- c(2.7857, 2.11, 1.72, 1.6937, 1.6227, 1.6067, 1.5975, 1.59, 1.58, 1.5632, 1.55, 1.54,
1.538, 1.5357, 1.5266, 1.5266, 1.522, 1.522, 1.52, 1.52, 1.5151, 1.5151, 1.5128,
1.5128, 1.51, 1.5082, 1.5082, 1.5037, 1.5037, 1.5, 1.49, 1.4854, 1.4831, 1.4785,
1.4785, 1.4739, 1.4716, 1.4716, 1.4625, 1.46, 1.4579, 1.4579, 1.4556, 1.45, 1.4464,
1.4464, 1.4464, 1.4419, 1.44, 1.44, 1.4373, 1.4373, 1.435, 1.4258, 1.4258, 1.4258,
1.4235, 1.42, 1.4144, 1.41, 1.41, 1.4, 1.3984, 1.3961, 1.3938, 1.3938, 1.3915, 1.39,
1.39, 1.39, 1.39, 1.3869, 1.3869, 1.3846, 1.3823, 1.38, 1.38, 1.3778, 1.3755, 1.3755,
1.3755, 1.37, 1.37, 1.37, 1.37, 1.3686, 1.3686, 1.3663, 1.3663, 1.3663, 1.3617,
1.3617, 1.36, 1.3571, 1.3549, 1.3526, 1.3526, 1.35, 1.348, 1.348, 1.348, 1.348,
1.348, 1.348, 1.3457, 1.3457, 1.3457, 1.34, 1.34, 1.3365, 1.3365, 1.33, 1.3274,
1.3274, 1.3274, 1.3251, 1.3251, 1.3251, 1.3228, 1.32, 1.32, 1.3182, 1.3182, 1.3182,
1.3137, 1.3137, 1.3137, 1.3114, 1.3114, 1.31, 1.3068, 1.3068, 1.3022, 1.3022, 1.3,
1.2953, 1.2953, 1.293, 1.29, 1.2862, 1.2862, 1.2862, 1.2839, 1.2816, 1.28, 1.28,
1.277, 1.277, 1.2747, 1.2747, 1.27, 1.2679, 1.26, 1.25, 1.25, 1.245, 1.245, 1.245,
1.2427, 1.2427, 1.23, 1.23, 1.2267, 1.2244, 1.2221, 1.22, 1.2175, 1.2129, 1.21,
1.21, 1.2083, 1.1854, 1.1786, 1.1786, 1.17, 1.1488, 1.1374)

Fit GEV distribution to the data

gev_fit <- fgev(data)

Threshold value

threshold <- 1.8

Extract GEV parameters

location <- gev_fit$results[1, "location"]
scale <- gev_fit$results[1, "scale"]
shape <- gev_fit$results[1, "shape"]

Calculate the probability of exceeding the threshold

prob_exceed_threshold <- pgev(threshold, loc = location, scale = scale, shape = shape, lower.tail = FALSE)

Print the result

cat("Probability of exceeding", threshold, ":", prob_exceed_threshold, "\n")

Plot histogram of the data

hist(data, main = "Histogram of Provided Data", xlab = "Value", col = "lightblue", border = "black")

Plot fitted GEV distribution

curve(dgev(x, loc = location, scale = scale, shape = shape), add = TRUE, col = "red", lwd = 2)

Hi @Pawel_Dunin,

i had to change the part "Extract GEV parameters" to

location <- gev_fit$param["loc"]
scale <- gev_fit$param["scale"]
shape <-gev_fit$param["shape"]

then the rest worked. Using your code i get NULL for location, scale and shape and the same error message.

I'm assuming you are using the package evd for the fgev function.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.