logistic inverse CDF in r

# Define the logistic inverse cumulative distribution function (CDF)
logistic_inv_cdf <- function(p, mean = 0, scale = 1) {
  if (any(p < 0) || any(p > 1)) {
    stop("Probability values must be between 0 and 1.")
  }

  q <- log(p / (1 - p))
  mean + scale * q
}

# Example usage
# Define probability values
prob_values <- c(0.1, 0.5, 0.9)

# Calculate inverse CDF for the defined probabilities
result <- logistic_inv_cdf(prob_values)
print(result)

This code defines a function logistic_inv_cdf in R that computes the inverse cumulative distribution function (CDF) of the logistic distribution for given probability values. The function takes probability values between 0 and 1 and computes the inverse CDF using the formula mean + scale * log(p / (1 - p)), where mean and scale are the mean and scale parameters of the logistic distribution, respectively. The function checks if the provided probabilities are within the valid range (0 to 1) and throws an error if they are not. Finally, an example usage of the function is demonstrated by calculating the inverse CDF for probability values 0.1, 0.5, and 0.9, and printing the results.