fit_param_dist.Rd
Fit multiple parametric distributions, compute KL divergence, simulate best fit
fit_param_dist(vector, num_bins = 30, verbose = TRUE)
Numeric vector of data to fit
Number of bins for the empirical histogram
Logical indicating whether to print results
Function to simulate data from the best-fitting distribution
set.seed(123)
n <- 1000
vector <- rnorm(n)
start <- proc.time()[3]
simulate_function <- fit_param_dist(vector)
#> [1] 12.56009975 0.06457125 9.61265383 9.60274199 9.57615179 NaN
#> [7] Inf 0.01611113 Inf 0.01283163 0.15734994 Inf
#> [1] "Best distribution based on KL divergence: normal"
end <- proc.time()[3]
print(paste("Time taken:", end - start))
#> [1] "Time taken: 0.239000000000001"
simulated_data <- simulate_function(n) # Generate 100 samples from the best-fit distribution
par(mfrow = c(1, 2))
hist(vector, main = "Original Data", xlab = "Value", ylab = "Frequency")
hist(simulated_data, main = "Simulated Data", xlab = "Value", ylab = "Frequency")