### UNCERTAINTY ESTIMATION FOR AN ESTIMATED PARAMETER
### RANGE AVAILABLE
### THIS CODE CAN BE USED FOR THE SYMMETRICAL OR NON-SYMMETRICAL RANGE...
### ... WITH RESPECT TO THE ESTIMATED PARAMETER
rm(list=ls())
set.seed(2)
n <- 102
Parameter <- 15 ### Parameter: Gw
x <- c(9, 50) ### Lower limit and upper limit of possible values for the parameter
### Step 1: Determine the magnitude of the range
magnitude_x <- max(x)- min(x) ### Range
### Step 2: Verify if the range is symmetrical around the parameter
values.inf.Parameter <- (Parameter - min(x))/magnitude_x
values.sup.Parameter <- (max(x)- Parameter)/magnitude_x
symmetry <- c(values.inf.Parameter , values.sup.Parameter)
print(symmetry * 100) ### Percentage of values located on both sides of the parameter
## [1] 14.63415 85.36585
### Step 3: Simulate a sample of size n from a Uniform distribution U(x_min, x_max)
sample_1 <- runif(n * values.inf.Parameter, min = min(x), max = Parameter)
sample_2 <- runif(n * values.sup.Parameter, min = Parameter, max = max(x))
sample <- c(sample_1 , sample_2) ### Simulation of the values using the uniform distribution
### Step 4: Estimate the sample mean and the sample standard deviation
Mean_sample <- mean(sample)
sd_sample <- sd(sample)
### Step 5: Determine a Confidence interval (CI)
lim_inf_CI <- Mean_sample - 1.96*sd_sample/sqrt(n) ### Lower limit of the confidence interval
lim_sup_CI <- Mean_sample + 1.96*sd_sample/sqrt(n) ### Upper limit of the confidence interval
CI <- c(lim_inf_CI,lim_sup_CI) ### confidence interval
magnitude_CI <- lim_sup_CI - lim_inf_CI ### Magnitude of the confidence interval
### Step 6: Estimate the uncertainty (U)
uncertainty_1 <- ((max(x) -min(x))/(2* Parameter))*100 ### Uncertainty based on range
uncertainty_2 <- (((1.96 * sd_sample)/(sqrt(n) *Parameter)))*100 ### Uncertainty based on confidence interval
print(Mean_sample)
## [1] 29.19793
print(sd_sample)
## [1] 11.95562
print(CI)
## [1] 26.87772 31.51815
print(magnitude_CI)
## [1] 4.640428
print(magnitude_x)
## [1] 41
print(uncertainty_1)
## [1] 136.6667
print(uncertainty_2)
## [1] 15.46809