0% found this document useful (0 votes)
10 views28 pages

SIDI2

Uploaded by

Bing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views28 pages

SIDI2

Uploaded by

Bing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

library(tidyverse)

> library(ggpubr)
> library(rstatix)
> library(car)
> library(broom)
> SIDI <- read.csv("C:/Users/Cherry mae/Downloads/Sidi-Aissa-Annual-Rainfall-59-
obs.csv")
> #Histogram
> hist(SIDI$observation,
+ main = "SIDI - Annual Rainfall",
+ xlab = "Rainfall Depth (mm)",
+ col = "lightblue",
+ border = "black")
> #Density plot
> plot(density(SIDI$observation),
+ main = "Density Plot of Precipitation Observations (SIDI)",
+ xlab = "Precipitation")
> #Define the intervals (bins)
> BREAKS <- seq(min(SIDI$observation), max(SIDI$observation), by = 100)
> # Create a frequency table based on the intervals
> FREQUENCYTABLE <- cut(SIDI$observation, breaks = BREAKS, right = FALSE)
> #Display the frequency table
> table(FREQUENCYTABLE)
FREQUENCYTABLE
[150,250) [250,350) [350,450) [450,550)
22 21 14 1
> library(fitdistrplus)
> #Fit a normal distribution
> FITNORMAL <- fitdist(SIDI$observation, "norm")
> #Summary of the fit
> summary(FITNORMAL)
Fitting of the distribution ' norm ' by maximum likelihood
Parameters :
estimate Std. Error
mean 290.75763 11.747000
sd 90.23033 8.306375
Loglikelihood: -349.3569 AIC: 702.7139 BIC: 706.869
Correlation matrix:
mean sd
mean 1 0
sd 0 1

> #Extract the parameters (mean and standard deviation)


> params <- list(mean = FITNORMAL$estimate["mean"], sd =
FITNORMAL$estimate["sd"])
> #Plot the data along with the fitted normal distribution
> plotdist(SIDI$observation, "norm", para = params)
> #Calculate the mean and standard deviation
> MEAN <- mean(SIDI$observation)
> SD <- sd(SIDI$observation)
> #Define the threshold for outliers (e.g., 3 standard deviations)
> lower_bound <- MEAN - 3 * SD
> upper_bound <- MEAN + 3 * SD
> #Remove the outliers
> SIDI_NOOUTLIERS <- SIDI[SIDI$observation >= lower_bound & SIDI$observation
<= upper_bound, ]
> # Check the result
> summary(SIDI_NOOUTLIERS$observation)
Min. 1st Qu. Median Mean 3rd Qu. Max.
149.5 218.3 278.6 290.8 358.7 556.4
> #Rank the data in descending order
> SIDI <- SIDI[order(-SIDI$observation), ]
> SIDI$rank <- rank(-SIDI$observation, ties.method = "first")
> #Probabilities of exceedance
> #of the ranked annual rainfall estimated with various methods.
> #Weibull and Gringorten
> #Number of observations
> N <- nrow(SIDI)
> #Weibull plotting positions
> SIDI$weibull <- SIDI$rank / (N + 1)
> #Gringorten plotting positions
> SIDI$gringorten <- (SIDI$rank - 0.44) / (N + 0.12)
> #Exceedance probability (1 - Weibull plotting position)
> SIDI$exceedance_weibull <- 1 - SIDI$weibull
> #Exceedance probability (1 - Gringorten plotting position)
> SIDI$exceedance_gringorten <- 1 - SIDI$gringorten
> # Convert exceedance probabilities to percentages
> SIDI$percentage_exceedance_weibull <- SIDI$exceedance_weibull * 100
> SIDI$percentage_exceedance_gringorten <- SIDI$exceedance_gringorten * 100
> # Check the updated data frame
> head(SIDI[, c("observation", "percentage_exceedance_weibull",
"percentage_exceedance_gringorten")])
observation percentage_exceedance_weibull percentage_exceedance_gringorten
44 556.4 98.33333 99.05277
55 500.8 96.66667 97.36130
43 428.7 95.00000 95.66982
57 421.8 93.33333 93.97835
32 421.2 91.66667 92.28687
26 413.4 90.00000 90.59540
> #Plot the Weibull exceedance probability as percentage with linear scale
> plot(SIDI$observation, SIDI$percentage_exceedance_weibull,
+ main = "Probability Plot of the Total Annual Rainfall (Weibull Method)",
+ xlab = "Rainfall Depths (mm)",
+ ylab = "Probability of Exceedance (%)",
+ type = "b", # 'b' for both points and lines
+ col = "blue",
+ lty = 1, # Solid line
+ log = "", # Ensure both axes are linear (default)
+ ylim = c(0, 100)) # Setting y limits to 0 to 100 for percentage
> #Plot the Gringorten exceedance probability as percentage with linear scale
> plot(SIDI$observation, SIDI$percentage_exceedance_gringorten,
+ main = "Probability Plot of the Total Annual Rainfall (Gringorten Method)",
+ xlab = "Rainfall Depths (mm)",
+ ylab = "Probability of Exceedance (%)",
+ type = "b", # 'b' for both points and lines
+ col = "red",
+ lty = 1, # Solid line
+ log = "", # Ensure both axes are linear (default)
+ ylim = c(0, 100)) # Setting y limits to 0 to 100 for percentage
> #Plot the Weibull exceedance probability as a line
> plot(SIDI$observation, SIDI$rescaled_exceedance_weibull,
+ main = "Annual Rainfall",
+ xlab = "Rainfall Depths (mm)",
+ ylab = "Probability of Exceedance (Rescaled)",
+ type = "l", # 'l' for lines only
+ col = "blue",
+ lty = 1, # Solid line
+ ylim = c(0, 1)) # Setting y limits to 0 to 1 for rescaled values
> #Plot the Gringorten exceedance probability as a line
> plot(SIDI$observation, SIDI$rescaled_exceedance_gringorten,
+ main = "Annual Rainfall",
+ xlab = "Rainfall Depths (mm)",
+ ylab = "Probability of Exceedance (Rescaled)",
+ type = "l", # 'l' for lines only
+ col = "red",
+ lty = 1, # Solid line
+ ylim = c(0, 1)) # Setting y limits to 0 to 1 for rescaled values
> ______________________________________________________________________________
Error: unexpected input in "__"
> #Rescale the percentage of exceedance to a range of 0-1
> SIDI$rescaled_exceedance_weibull <- SIDI$percentage_exceedance_weibull / 100
> SIDI$rescaled_exceedance_gringorten <-
SIDI$percentage_exceedance_gringorten / 100
> #Plot the Weibull exceedance probability as rescaled values
> plot(SIDI$observation, SIDI$rescaled_exceedance_weibull,
+ main = "Probability Plot of the Total Annual Rainfall",
+ xlab = "Rainfall Depths (mm)",
+ ylab = "Probability of Exceedance (Rescaled)",
+ type = "b", # 'b' for both points and lines
+ col = "blue",
+ lty = 1, # Solid line
+ ylim = c(0, 1)) # Setting y limits to 0 to 1 for rescaled values
> #Plot the Gringorten exceedance probability as rescaled values
> plot(SIDI$observation, SIDI$rescaled_exceedance_gringorten,
+ main = "Probability Plot of the Total Annual Rainfall",
+ xlab = "Rainfall Depths (mm)",
+ ylab = "Probability of Exceedance (Rescaled)",
+ type = "b", # 'b' for both points and lines
+ col = "red",
+ lty = 1, # Solid line
+ ylim = c(0, 1)) # Setting y limits to 0 to 1 for rescaled values
> _____________________________________________
Error: unexpected input in "__"
> #NORMAL DISTRIBUTION
> # Ensure your SIDI observations are in a vector format
> observations <- SIDI$observation
> # Create a normal probability plot
> qqnorm(observations,
+ main = "Normal Probability Plot",
+ xlab = "Annual Rainfall (mm)",
+ ylab = "Probability of Exceedance",
+ xlim = c(100, 800)) # Change the x-axis limits as needed
> ylim = c(0, 100)
> # Add the best fitted line (solid line)
> qqline(observations, col = "blue", lty = 1)
> # Generate theoretical quantiles for the normal distribution
> theoretical_quantiles <- qnorm(ppoints(length(observations)), mean = MEAN, sd
= SD)
> # Add the theoretical normal line (dotted line)
> lines(theoretical_quantiles, sort(observations), col = "red", lty = 2)
> ___________________________________________________________
Error: unexpected input in "__"
> # Load necessary library
> library(MASS)
> # Ensure your SIDI observations are in a vector format
> observations <- SIDI$observation
> # Extract fitted parameters
> mean_fit <- FITNORMAL$estimate["mean"]
> sd_fit <- FITNORMAL$estimate["sd"]
> # Define the selected probabilities (as percentages)
> selected_probabilities <- c(10,20,30,40,50,60,70,80,90) / 100 # Convert
percentages to probabilities
> # Calculate the estimated annual rainfall for these probabilities
> estimated_rainfall <- qnorm(selected_probabilities, mean = mean_fit, sd = sd_fit)
> # Calculate return periods (T) from the probabilities
> # Return period (T) = 1 / (1 - P)
> return_periods <- 1 / (1 - selected_probabilities)
> # Create a data frame to display the results, converting probabilities to
percentage
> results_df <- data.frame(
+ Probability_Percentage = selected_probabilities * 100, # Convert to percentage
+ Estimated_Rainfall_mm = estimated_rainfall,
+ Return_Period_years = return_periods
+)
> # Display the results
> print(results_df)
Probability_Percentage Estimated_Rainfall_mm Return_Period_years
1 10 175.1228 1.111111
2 20 214.8179 1.250000
3 30 243.4408 1.428571
4 40 267.8980 1.666667
5 50 290.7576 2.000000
6 60 313.6172 2.500000
7 70 338.0745 3.333333
8 80 366.6974 5.000000
9 90 406.3925 10.000000
> ###############################
> #CALCULATING RETURN PERIOD
> # Load necessary library
> library(dplyr)
> # Sort the observations in descending order
> sorted_data <- sort(SIDI$observation, decreasing = TRUE)
> # Calculate the number of observations
> n <- length(sorted_data)
> # Create a data frame with rank and exceedance probability
> return_period_data <- data.frame(
+ Rank = 1:n,
+ Rainfall = sorted_data,
+ Exceedance_Probability = (1:n) / (n + 1)
+)
> # Calculate return period
> return_period_data <- return_period_data %>%
+ mutate(Return_Period = 1 / Exceedance_Probability)
> # Display the return period data
> print(return_period_data)
Rank Rainfall Exceedance_Probability Return_Period
1 1 556.4 0.01666667 60.000000
2 2 500.8 0.03333333 30.000000
3 3 428.7 0.05000000 20.000000
4 4 421.8 0.06666667 15.000000
5 5 421.2 0.08333333 12.000000
6 6 413.4 0.10000000 10.000000
7 7 408.8 0.11666667 8.571429
8 8 402.1 0.13333333 7.500000
9 9 399.5 0.15000000 6.666667
10 10 394.4 0.16666667 6.000000
11 11 382.0 0.18333333 5.454545
12 12 380.9 0.20000000 5.000000
13 13 366.5 0.21666667 4.615385
14 14 364.5 0.23333333 4.285714
15 15 360.2 0.25000000 4.000000
16 16 357.2 0.26666667 3.750000
17 17 342.0 0.28333333 3.529412
18 18 333.5 0.30000000 3.333333
19 19 329.6 0.31666667 3.157895
20 20 326.9 0.33333333 3.000000
21 21 321.5 0.35000000 2.857143
22 22 319.1 0.36666667 2.727273
23 23 310.1 0.38333333 2.608696
24 24 308.6 0.40000000 2.500000
25 25 308.0 0.41666667 2.400000
26 26 294.3 0.43333333 2.307692
27 27 294.1 0.45000000 2.222222
28 28 288.5 0.46666667 2.142857
29 29 281.8 0.48333333 2.068966
30 30 278.6 0.50000000 2.000000
31 31 275.9 0.51666667 1.935484
32 32 273.0 0.53333333 1.875000
33 33 260.3 0.55000000 1.818182
34 34 258.5 0.56666667 1.764706
35 35 257.0 0.58333333 1.714286
36 36 255.0 0.60000000 1.666667
37 37 252.6 0.61666667 1.621622
38 38 246.4 0.63333333 1.578947
39 39 242.8 0.65000000 1.538462
40 40 235.7 0.66666667 1.500000
41 41 235.7 0.68333333 1.463415
42 42 225.6 0.70000000 1.428571
43 43 222.6 0.71666667 1.395349
44 44 222.1 0.73333333 1.363636
45 45 214.6 0.75000000 1.333333
46 46 210.0 0.76666667 1.304348
47 47 208.5 0.78333333 1.276596
48 48 206.0 0.80000000 1.250000
49 49 205.8 0.81666667 1.224490
50 50 205.0 0.83333333 1.200000
51 51 197.8 0.85000000 1.176471
52 52 192.8 0.86666667 1.153846
53 53 185.9 0.88333333 1.132075
54 54 185.0 0.90000000 1.111111
55 55 172.1 0.91666667 1.090909
56 56 161.8 0.93333333 1.071429
57 57 151.0 0.95000000 1.052632
58 58 150.7 0.96666667 1.034483
59 59 149.5 0.98333333 1.016949
> # Plotting Probability of Exceedance vs. Rainfall Depth
> plot(return_period_data$Rainfall,
+ return_period_data$Exceedance_Probability,
+ type = "b",
+ col = "blue",
+ xlab = "Rainfall Depth (mm)",
+ ylab = "Probability of Exceedance",
+ main = "SIDI - Annual Rainfall",
+ ylim = c(0, 1), # Set y-axis limits from 0 to 1
+ pch = 16) # 'pch' controls the point style
> # Optionally add gridlines for better visibility
> grid()
> ____________________________________
Error: unexpected input in "__"
> # Plotting Return Period vs. Rainfall Depth
> plot(return_period_data$Rainfall,
+ return_period_data$Return_Period,
+ type = "b", # Type "b" for both points and lines
+ col = "blue",
+ xlab = "Rainfall Depth (mm)",
+ ylab = "Return Period (Years)",
+ main = "SIDI - Annual Rainfall",
+ pch = 16) # Solid circle points
> # Optionally add gridlines for better visibility
> grid()
> _________________________________________________________
Error: unexpected input in "__"
> # Step 1: Sort the rainfall data in descending order
> sorted_data <- sort(SIDI$observation, decreasing = TRUE)
> # Step 2: Define the selected probabilities in percentage
> selected_probabilities <- seq(10, 100, by = 10) / 100 # Convert to decimals
> # Step 3: Interpolate the rainfall depth for the selected probabilities
> n <- length(sorted_data)
> rainfall_depths <- quantile(sorted_data, probs = 1 - selected_probabilities)
> # Step 4: Calculate the return periods for each selected probability
> return_periods <- 1 / selected_probabilities
> # Step 5: Create a data frame to display the results
> results <- data.frame(
+ Probability_Percentage = selected_probabilities * 100, # Convert back to
percentages
+ Rainfall_Depth = rainfall_depths,
+ Return_Period_Years = return_periods
+)
> # Display the results
> print(results)
Probability_Percentage Rainfall_Depth Return_Period_Years
90% 10 409.72 10.000000
80% 20 372.26 5.000000
70% 30 331.94 3.333333
60% 40 308.48 2.500000
50% 50 278.60 2.000000
40% 60 255.40 1.666667
30% 70 229.64 1.428571
20% 80 207.50 1.250000
10% 90 185.72 1.111111
0% 100 149.50 1.000000
> # Assuming the following vectors for return periods and square root transformed
rainfall depths
> return_periods <- c(60, 30, 20, 15, 12, 10, 8.571429, 7.5, 6.666667, 6,
+ 5.454545, 5, 4.615385, 4.285714, 4, 3.750000, 3.529412,
+ 3.333333, 3.157895, 3.000000, 2.857143, 2.727273,
+ 2.608696, 2.500000, 2.400000, 2.307692, 2.222222,
+ 2.142857, 2.068966, 2.000000, 1.935484, 1.875000,
+ 1.818182, 1.764706, 1.714286, 1.666667, 1.621622,
+ 1.578947, 1.538462, 1.500000, 1.463415, 1.428571,
+ 1.395349, 1.363636, 1.333333, 1.304348, 1.276596,
+ 1.250000, 1.224490, 1.200000, 1.176471, 1.153846,
+ 1.132075, 1.111111, 1.090909, 1.071429, 1.052632,
+ 1.034483, 1.016949)
> # Square root transformed rainfall depths
> transformed_depths <- c(23.59, 22.38, 20.71, 20.54, 20.52, 20.33, 20.22, 20.05,
+ 19.99, 19.86, 19.54, 19.52, 19.14, 19.09, 18.98, 18.90,
+ 18.49, 18.26, 18.15, 18.08, 17.93, 17.86, 17.61, 17.57,
+ 17.55, 17.16, 17.15, 16.99, 16.79, 16.69, 16.61,
+ 16.52, 16.13, 16.08, 16.03, 15.97, 15.89, 15.70,
+ 15.58, 15.35, 15.35, 15.02, 14.92, 14.90, 14.65,
+ 14.49, 14.44, 14.35, 14.35, 14.32, 14.06, 13.89,
+ 13.63, 13.60, 13.12, 12.72, 12.29, 12.28, 12.22)
> # Create a data frame for better handling
> transformed_data <- data.frame(Return_Period = return_periods,
+ Transformed_Depth = transformed_depths)
> # Plot the transformed data
> plot(transformed_data$Return_Period,
+ transformed_data$Transformed_Depth,
+ type = "b", # Both points and lines
+ log = "x", # Logarithmic scale for x-axis
+ col = "blue",
+ xlab = "Return Period (Years)",
+ ylab = "Square Root of Rainfall Depth (mm)",
+ main = "SIDI - Annual Rainfall",
+ pch = 16) # Solid circle points
> # Optionally add gridlines for clarity
> grid()
> # Assuming the following vectors for original rainfall depths and return periods
> original_depths <- c(556.4, 500.8, 428.7, 421.8, 421.2, 413.4, 408.8, 402.1,
+ 399.5, 394.4, 382.0, 380.9, 366.5, 364.5, 360.2,
+ 357.2, 342.0, 333.5, 329.6, 326.9, 321.5, 319.1,
+ 310.1, 308.6, 308.0, 294.3, 294.1, 288.5, 281.8,
+ 278.6, 275.9, 273.0, 260.3, 258.5, 257.0, 255.0,
+ 252.6, 246.4, 242.8, 235.7, 235.7, 225.6, 222.6,
+ 222.1, 214.6, 210.0, 208.5, 206.0, 205.8, 205.0,
+ 197.8, 192.8, 185.9, 185.0, 172.1, 161.8, 151.0,
+ 150.7, 149.5)
> # Square root transformed rainfall depths
> transformed_depths <- c(23.59, 22.38, 20.71, 20.54, 20.52, 20.33, 20.22, 20.05,
+ 19.99, 19.86, 19.54, 19.52, 19.14, 19.09, 18.98,
+ 18.90, 18.49, 18.26, 18.15, 18.08, 17.93, 17.86,
+ 17.61, 17.57, 17.55, 17.16, 17.15, 16.99, 16.79,
+ 16.69, 16.61, 16.52, 16.13, 16.08, 16.03, 15.97,
+ 15.89, 15.70, 15.58, 15.35, 15.35, 15.02, 14.92,
+ 14.90, 14.65, 14.49, 14.44, 14.35, 14.35, 14.32,
+ 14.06, 13.89, 13.63, 13.60, 13.12, 12.72, 12.29,
+ 12.28, 12.22)
> # Create a data frame for better handling
> data_comparison <- data.frame(Rank = 1:length(original_depths),
+ Original_Depth = original_depths,
+ Transformed_Depth = transformed_depths)
> # Plotting the raw vs transformed data
> par(mar=c(5, 5, 4, 5) + 0.1) # Adjust margins for dual axis plot
> # Plot the original rainfall depth
> plot(data_comparison$Rank,
+ data_comparison$Original_Depth,
+ type = "b",
+ col = "red",
+ xlab = "Return Period",
+ ylab = "Rainfall Depth (mm)",
+ main = "Raw vs Transformed Rainfall Depths",
+ pch = 16)
> # Create a second y-axis for the transformed depths
> par(new = TRUE)
> plot(data_comparison$Rank,
+ data_comparison$Transformed_Depth,
+ type = "b",
+ col = "blue",
+ axes = FALSE,
+ xlab = "",
+ ylab = "")
> axis(4, at=seq(0, 25, by=5), las=1) # Add y-axis on the right
> mtext("Square Root Transformed Depth (mm)", side=4, line=3) # Label for the
right axis
> # Add legend
> legend("topright", legend=c("Raw Depth (mm)", "Transformed Depth (mm)"),
+ col=c("red", "blue"), lty=1, pch=c(16, NA), bty="n")
> # Optional grid for better visibility
> grid()
>
##################################################
##
> # Square root transformed rainfall depths
> transformed_depths <- c(23.59, 22.38, 20.71, 20.54, 20.52, 20.33, 20.22,
+ 20.05, 19.99, 19.86, 19.54, 19.52, 19.14, 19.09,
+ 18.98, 18.90, 18.49, 18.26, 18.15, 18.08, 17.93,
+ 17.86, 17.61, 17.57, 17.55, 17.16, 17.15, 16.99,
+ 16.79, 16.69, 16.61, 16.52, 16.13, 16.08, 16.03,
+ 15.97, 15.89, 15.70, 15.58, 15.35, 15.35, 15.02,
+ 14.92, 14.90, 14.65, 14.49, 14.44, 14.35, 14.35,
+ 14.32, 14.06, 13.89, 13.63, 13.60, 13.12, 12.72,
+ 12.29, 12.28, 12.22)
> # Total number of events
> N <- length(transformed_depths)
> # Rank the transformed depths in descending order
> ranked_depths <- rank(-transformed_depths)
> # Calculate the probability of exceedance
> exceedance_probability <- ranked_depths / (N + 1)
> # Calculate the probability of non-exceedance
> non_exceedance_probability <- 1 - exceedance_probability
> # Create a data frame to store the results
> results <- data.frame(Rank = ranked_depths,
+ Transformed_Depth = transformed_depths,
+ Exceedance_Probability = exceedance_probability,
+ Non_Exceedance_Probability = non_exceedance_probability)
> # Print the results
> print(results)
Rank Transformed_Depth Exceedance_Probability Non_Exceedance_Probability
1 1.0 23.59 0.01666667 0.98333333
2 2.0 22.38 0.03333333 0.96666667
3 3.0 20.71 0.05000000 0.95000000
4 4.0 20.54 0.06666667 0.93333333
5 5.0 20.52 0.08333333 0.91666667
6 6.0 20.33 0.10000000 0.90000000
7 7.0 20.22 0.11666667 0.88333333
8 8.0 20.05 0.13333333 0.86666667
9 9.0 19.99 0.15000000 0.85000000
10 10.0 19.86 0.16666667 0.83333333
11 11.0 19.54 0.18333333 0.81666667
12 12.0 19.52 0.20000000 0.80000000
13 13.0 19.14 0.21666667 0.78333333
14 14.0 19.09 0.23333333 0.76666667
15 15.0 18.98 0.25000000 0.75000000
16 16.0 18.90 0.26666667 0.73333333
17 17.0 18.49 0.28333333 0.71666667
18 18.0 18.26 0.30000000 0.70000000
19 19.0 18.15 0.31666667 0.68333333
20 20.0 18.08 0.33333333 0.66666667
21 21.0 17.93 0.35000000 0.65000000
22 22.0 17.86 0.36666667 0.63333333
23 23.0 17.61 0.38333333 0.61666667
24 24.0 17.57 0.40000000 0.60000000
25 25.0 17.55 0.41666667 0.58333333
26 26.0 17.16 0.43333333 0.56666667
27 27.0 17.15 0.45000000 0.55000000
28 28.0 16.99 0.46666667 0.53333333
29 29.0 16.79 0.48333333 0.51666667
30 30.0 16.69 0.50000000 0.50000000
31 31.0 16.61 0.51666667 0.48333333
32 32.0 16.52 0.53333333 0.46666667
33 33.0 16.13 0.55000000 0.45000000
34 34.0 16.08 0.56666667 0.43333333
35 35.0 16.03 0.58333333 0.41666667
36 36.0 15.97 0.60000000 0.40000000
37 37.0 15.89 0.61666667 0.38333333
38 38.0 15.70 0.63333333 0.36666667
39 39.0 15.58 0.65000000 0.35000000
40 40.5 15.35 0.67500000 0.32500000
41 40.5 15.35 0.67500000 0.32500000
42 42.0 15.02 0.70000000 0.30000000
43 43.0 14.92 0.71666667 0.28333333
44 44.0 14.90 0.73333333 0.26666667
45 45.0 14.65 0.75000000 0.25000000
46 46.0 14.49 0.76666667 0.23333333
47 47.0 14.44 0.78333333 0.21666667
48 48.5 14.35 0.80833333 0.19166667
49 48.5 14.35 0.80833333 0.19166667
50 50.0 14.32 0.83333333 0.16666667
51 51.0 14.06 0.85000000 0.15000000
52 52.0 13.89 0.86666667 0.13333333
53 53.0 13.63 0.88333333 0.11666667
54 54.0 13.60 0.90000000 0.10000000
55 55.0 13.12 0.91666667 0.08333333
56 56.0 12.72 0.93333333 0.06666667
57 57.0 12.29 0.95000000 0.05000000
58 58.0 12.28 0.96666667 0.03333333
59 59.0 12.22 0.98333333 0.01666667
> ##################
> # Create a data frame for plotting
> plot_data <- data.frame(Transformed_Depth = transformed_depths,
+ Exceedance_Probability = exceedance_probability)
> # Plotting
> plot(plot_data$Transformed_Depth,
+ plot_data$Exceedance_Probability,
+ type = "b",
+ col = "blue",
+ pch = 19,
+ xlab = "Transformed Rainfall Depth (mm)",
+ ylab = "Probability of Exceedance",
+ main = "SIDI - Annual Rainfall")
> # Add grid for better visualization
> grid()
> ########################
> # Load required packages
> library(ggplot2)
> # Square root transformed rainfall depths
> transformed_depths <- c(23.59, 22.38, 20.71, 20.54, 20.52, 20.33, 20.22,
+ 20.05, 19.99, 19.86, 19.54, 19.52, 19.14, 19.09,
+ 18.98, 18.90, 18.49, 18.26, 18.15, 18.08, 17.93,
+ 17.86, 17.61, 17.57, 17.55, 17.16, 17.15, 16.99,
+ 16.79, 16.69, 16.61, 16.52, 16.13, 16.08, 16.03,
+ 15.97, 15.89, 15.70, 15.58, 15.35, 15.35, 15.02,
+ 14.92, 14.90, 14.65, 14.49, 14.44, 14.35, 14.35,
+ 14.32, 14.06, 13.89, 13.63, 13.60, 13.12, 12.72,
+ 12.29, 12.28, 12.22)
> # Create a data frame for ggplot
> data <- data.frame(Transformed_Depth = transformed_depths)
> # Create the histogram with density plot
> ggplot(data, aes(x = Transformed_Depth)) +
+ geom_histogram(aes(y = ..density..),
+ bins = 10,
+ fill = "lightblue",
+ color = "black",
+ alpha = 0.7) +
+ geom_density(color = "red",
+ size = 1) +
+ labs(title = "SIDI - Annual Rainfall",
+ x = "Transformed Rainfall Depth (mm)",
+ y = "Normal Probability Density") +
+ theme_minimal()
Warning messages:
1: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.

ℹ Please use `linewidth` instead.


This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
2: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.

ℹ Please use `after_stat(density)` instead.


This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
> # Perform cube root transformation
> cbrt_transformed <- (rainfall_depths)^(1/3)
> # Create a data frame for the transformed data
> data_cbrt <- data.frame(Transformed_Depth = cbrt_transformed)
> # Rank the transformed data in descending order
> data_cbrt <- data_cbrt[order(-data_cbrt$Transformed_Depth), ]
> data_cbrt$Rank <- 1:nrow(data_cbrt)
Error in 1:nrow(data_cbrt) : argument of length 0
> # Load required packages
> library(dplyr)
> # Original rainfall depths (replace this with your actual data)
> rainfall_depths <- c(556.4, 500.8, 428.7, 421.8, 421.2, 413.4, 408.8,
+ 402.1, 399.5, 394.4, 382.0, 380.9, 366.5, 364.5,
+ 360.2, 357.2, 342.0, 333.5, 329.6, 326.9, 321.5,
+ 319.1, 310.1, 308.6, 308.0, 294.3, 294.1, 288.5,
+ 281.8, 278.6, 275.9, 273.0, 260.3, 258.5, 257.0,
+ 255.0, 252.6, 246.4, 242.8, 235.7, 225.6, 222.6,
+ 222.1, 214.6, 210.0, 208.5, 206.0, 205.8, 205.0,
+ 197.8, 192.8, 185.9, 185.0, 172.1, 161.8, 151.0,
+ 150.7, 149.5)
> # Perform cube root transformation
> transformed_depths <- rainfall_depths^(1/3)
> # Create a data frame
> data <- data.frame(Transformed_Depth = transformed_depths)
> # Calculate ranks and probability of exceedance
> N <- nrow(data) # Total number of observations
> data <- data %>%
+ arrange(desc(Transformed_Depth)) %>%
+ mutate(Rank = row_number(),
+ Probability_Exceedance = 1 - (Rank / (N + 1)))
> # View the results
> print(data)
Transformed_Depth Rank Probability_Exceedance
1 8.224870 1 0.98305085
2 7.941236 2 0.96610169
3 7.540228 3 0.94915254
4 7.499556 4 0.93220339
5 7.495998 5 0.91525424
6 7.449438 6 0.89830508
7 7.421704 7 0.88135593
8 7.380935 8 0.86440678
9 7.364992 9 0.84745763
10 7.333517 10 0.83050847
11 7.255842 11 0.81355932
12 7.248870 12 0.79661017
13 7.156346 13 0.77966102
14 7.143305 14 0.76271186
15 7.115104 15 0.74576271
16 7.095295 16 0.72881356
17 6.993191 17 0.71186441
18 6.934768 18 0.69491525
19 6.907630 19 0.67796610
20 6.888716 20 0.66101695
21 6.850574 21 0.64406780
22 6.833485 22 0.62711864
23 6.768627 23 0.61016949
24 6.757696 24 0.59322034
25 6.753313 25 0.57627119
26 6.651661 26 0.55932203
27 6.650154 27 0.54237288
28 6.607674 28 0.52542373
29 6.556122 29 0.50847458
30 6.531211 30 0.49152542
31 6.510044 31 0.47457627
32 6.487154 32 0.45762712
33 6.384958 33 0.44067797
34 6.370207 34 0.42372881
35 6.357861 35 0.40677966
36 6.341326 36 0.38983051
37 6.321369 37 0.37288136
38 6.269221 38 0.35593220
39 6.238539 39 0.33898305
40 6.177127 40 0.32203390
41 6.087604 41 0.30508475
42 6.060499 42 0.28813559
43 6.055958 43 0.27118644
44 5.987009 44 0.25423729
45 5.943922 45 0.23728814
46 5.929736 46 0.22033898
47 5.905941 47 0.20338983
48 5.904029 48 0.18644068
49 5.896369 49 0.16949153
50 5.826514 50 0.15254237
51 5.777000 51 0.13559322
52 5.707244 52 0.11864407
53 5.698019 53 0.10169492
54 5.562375 54 0.08474576
55 5.449117 55 0.06779661
56 5.325074 56 0.05084746
57 5.321545 57 0.03389831
58 5.307383 58 0.01694915
> # Plot the exceedance curve
> ggplot(data, aes(x = Transformed_Depth, y = Probability_Exceedance)) +
+ geom_line(color = "blue", size = 1) +
+ geom_point(color = "blue", size = 2) +
+ labs(title = "SIDI - Annual Rainfall",
+ x = "Cube Root Transformed Rainfall Depth (mm)",
+ y = "Probability of Exceedance (%)") +
+ theme_minimal() +
+ scale_y_continuous(labels = scales::percent)
> #######
> # Load required packages
> library(ggplot2)
> # Original rainfall depths (replace this with your actual data)
> rainfall_depths <- c(556.4, 500.8, 428.7, 421.8, 421.2, 413.4, 408.8,
+ 402.1, 399.5, 394.4, 382.0, 380.9, 366.5, 364.5,
+ 360.2, 357.2, 342.0, 333.5, 329.6, 326.9, 321.5,
+ 319.1, 310.1, 308.6, 308.0, 294.3, 294.1, 288.5,
+ 281.8, 278.6, 275.9, 273.0, 260.3, 258.5, 257.0,
+ 255.0, 252.6, 246.4, 242.8, 235.7, 225.6, 222.6,
+ 222.1, 214.6, 210.0, 208.5, 206.0, 205.8, 205.0,
+ 197.8, 192.8, 185.9, 185.0, 172.1, 161.8, 151.0,
+ 150.7, 149.5)
> # Perform cube root transformation
> transformed_depths <- rainfall_depths^(1/3)
> # Create a data frame for ggplot
> data <- data.frame(Transformed_Depth = transformed_depths)
> # Create the histogram with relative frequency and overlay the density plot
> ggplot(data, aes(x = Transformed_Depth)) +
+ geom_histogram(aes(y = ..count../sum(..count..)),
+ bins = 10,
+ fill = "lightblue",
+ color = "black",
+ alpha = 0.7) +
+ geom_density(aes(y = ..density..),
+ color = "red",
+ size = 1) +
+ labs(title = "SIDI - Annual Rainfall",
+ x = "Cube Root Transformed Rainfall Depth (mm)",
+ y = "Relative Frequency") +
+ theme_minimal() +
+ scale_y_continuous(sec.axis = sec_axis(~ ., name = "Density")) # Optional:
Secondary axis for density
> # Perform log transformation
> log_transformed <- log(rainfall_depths)
> # Create a data frame for the transformed data
> data_log <- data.frame(Transformed_Depth = log_transformed)
> # Rank the transformed data in descending order
> data_log <- data_log[order(-data_log$Transformed_Depth), ]
> data_log$Rank <- 1:nrow(data_log)
Error in 1:nrow(data_log) : argument of length 0
> # Calculate exceedance probability
> total_observations <- nrow(data_log)
> data_log$Exceedance_Probability <- data_log$Rank / (total_observations + 1)
Error in data_log$Rank : $ operator is invalid for atomic vectors
> # View the results
> print(data_log)
[1] 6.321487 6.216207 6.060757 6.044531 6.043108 6.024416 6.013226 5.996701
5.990214 5.977366
[11] 5.945421 5.942537 5.903999 5.898527 5.886659 5.878296 5.834811
5.809643 5.797880 5.789654
[21] 5.772998 5.765505 5.736895 5.732046 5.730100 5.684600 5.683920
5.664695 5.641198 5.629777
[31] 5.620038 5.609472 5.561835 5.554896 5.549076 5.541264 5.531807
5.506956 5.492238 5.462560
[41] 5.418764 5.405376 5.403128 5.368776 5.347108 5.339939 5.327876
5.326905 5.323010 5.287256
[51] 5.261653 5.225209 5.220356 5.148076 5.086361 5.017280 5.015291
5.007296
> # Perform log transformation
> transformed_depths <- log(rainfall_depths)
> # Create a data frame
> data <- data.frame(Transformed_Depth = transformed_depths)
> # Calculate ranks and probability of exceedance
> N <- nrow(data) # Total number of observations
> data <- data %>%
+ arrange(desc(Transformed_Depth)) %>%
+ mutate(Rank = row_number(),
+ Probability_Exceedance = 1 - (Rank / (N + 1)))
> # Plot the probability of exceedance vs log-transformed rainfall depth
> ggplot(data, aes(x = Transformed_Depth, y = Probability_Exceedance)) +
+ geom_line(color = "blue", size = 1) +
+ geom_point(color = "blue", size = 2) +
+ labs(title = "SIDI - Annual Rainfall",
+ x = "Log Transformed Rainfall Depth (mm)",
+ y = "Probability of Exceedance (%)") +
+ theme_minimal() +
+ scale_y_continuous(labels = scales::percent) # Convert y-axis to percentage
> # Load required packages
> library(ggplot2)
> library(dplyr)
> # Original rainfall depths (replace this with your actual data)
> rainfall_depths <- c(556.4, 500.8, 428.7, 421.8, 421.2, 413.4, 408.8,
+ 402.1, 399.5, 394.4, 382.0, 380.9, 366.5, 364.5,
+ 360.2, 357.2, 342.0, 333.5, 329.6, 326.9, 321.5,
+ 319.1, 310.1, 308.6, 308.0, 294.3, 294.1, 288.5,
+ 281.8, 278.6, 275.9, 273.0, 260.3, 258.5, 257.0,
+ 255.0, 252.6, 246.4, 242.8, 235.7, 225.6, 222.6,
+ 222.1, 214.6, 210.0, 208.5, 206.0, 205.8, 205.0,
+ 197.8, 192.8, 185.9, 185.0, 172.1, 161.8, 151.0,
+ 150.7, 149.5)
> # Perform log transformation
> transformed_depths <- log(rainfall_depths)
> # Create a data frame for plotting
> data <- data.frame(Transformed_Depth = transformed_depths)
> # Create the histogram with density overlay
> ggplot(data, aes(x = Transformed_Depth)) +
+ geom_histogram(aes(y = ..density..), bins = 10, fill = "lightblue", color =
"black", alpha = 0.6) +
+ geom_density(color = "red", size = 1) +
+ labs(title = "SIDI - Annual Rainfall",
+ x = "Log Transformed Rainfall Depth (mm)",
+ y = "Relative Frequency") +
+ theme_minimal()
> # Load required packages
> library(ggplot2)
> library(gridExtra)

Attaching package: ‘gridExtra’

The following object is masked from ‘package:dplyr’:


combine

> # Perform transformations


> sqrt_transformed <- sqrt(rainfall_depths)
> cbrt_transformed <- (rainfall_depths)^(1/3)
> log_transformed <- log(rainfall_depths)
> # Create data frames for each transformation
> data_sqrt <- data.frame(Transformed_Depth = sqrt_transformed)
> data_cbrt <- data.frame(Transformed_Depth = cbrt_transformed)
> data_log <- data.frame(Transformed_Depth = log_transformed)
> # Histogram with density overlay for square root transformed data
> plot_sqrt <- ggplot(data_sqrt, aes(x = Transformed_Depth)) +
+ geom_histogram(aes(y = ..density..), bins = 10, fill = "lightblue", color =
"black", alpha = 0.6) +
+ geom_density(color = "red", size = 1) +
+ labs(title = "Square Root Transformation",
+ x = "Square Root Transformed Rainfall Depth (mm)",
+ y = "Density") +
+ theme_minimal()
> # Histogram with density overlay for cube root transformed data
> plot_cbrt <- ggplot(data_cbrt, aes(x = Transformed_Depth)) +
+ geom_histogram(aes(y = ..density..), bins = 10, fill = "lightgreen", color =
"black", alpha = 0.6) +
+ geom_density(color = "blue", size = 1) +
+ labs(title = "Cube Root Transformation",
+ x = "Cube Root Transformed Rainfall Depth (mm)",
+ y = "Density") +
+ theme_minimal()
> # Histogram with density overlay for log transformed data
> plot_log <- ggplot(data_log, aes(x = Transformed_Depth)) +
+ geom_histogram(aes(y = ..density..), bins = 10, fill = "lightyellow", color =
"black", alpha = 0.6) +
+ geom_density(color = "purple", size = 1) +
+ labs(title = "Log Transformation",
+ x = "Log Transformed Rainfall Depth (mm)",
+ y = "Density") +
+ theme_minimal()
> # Combine all plots into one
> grid.arrange(plot_sqrt, plot_cbrt, plot_log, ncol = 3)

You might also like