Here is a sample code where i am trying to fit multiple distribution. Can someone please look into the error and run the code to its entirety? Thanks
# Step 1: Load required libraries
library(ismev)
library(tidyverse)
library(fitdistrplus)
# Step 2: Read and preprocess the streamflow data
streamflow <- data.frame(date = seq(as.Date("1980-01-01"),
to = as.Date("2020-12-31"),
by = "day"),
value = runif(14976,1,500))
# Step 3: Calculate annual maximum flows
annual_max <- aggregate(streamflow$value, by = list(year = format(streamflow$date, "%Y")), FUN = max)
# Step 4: Fit multiple probability distributions to the annual maximum flows
distributions <- c("norm", "logis", "gev") # Specify the distributions to be fitted
fit_results <- fitdist(annual_max$x, distributions)
# Step 5: Calculate return periods and associated flow values for each distribution
return_periods <- c(2, 5, 10, 25, 50, 100) # Specify desired return periods in years
# Loop through each distribution and calculate return flows
results <- data.frame(Return_Period = return_periods)
for (i in 1:length(distributions)) {
return_flows <- qfunc(return_periods, distname = distributions[i], distr = fit_results[[i]])
results[, paste(distributions[i], "Flow_Value", sep = "_")] <- return_flows
}
Error point
at fit_results it throws the following error
fit_results <- fitdist(annual_max$x, distributions)
Error in exists(ddistname, mode = "function") :
first argument has length > 1
1.,
fitdistrplus::fitdistisn't vectorized, you needlapply, 2., There does not appear to be a `"gev" distribution available. I have not looked at the rest.