diff --git a/8/P8.png b/8/P8.png new file mode 100644 index 0000000..c38eaa9 Binary files /dev/null and b/8/P8.png differ diff --git a/8/script.R b/8/script.R new file mode 100755 index 0000000..17af68d --- /dev/null +++ b/8/script.R @@ -0,0 +1,44 @@ +#!/bin/env Rscript + +# Libraries +library("pracma") +library("ggplot2") + +# Set the seed for the RNG +set.seed(2009) + +cauchy_location <- 1 +cauchy_scale <- 1.8 +cauchy_gen <- rcauchy(n = 107, location = cauchy_location, scale = cauchy_scale) +cauchy_gen <- sort(cauchy_gen) + +quantile_idxs <- 1:107 / (107 + 1) + +cauchy_quantiles <- sapply(quantile_idxs, function(p) { + cauchy_location + cauchy_scale * tan(pi * (p - 0.5)) +}) + +norm_mean <- -2.8 +norm_var <- 1.4 +norm_quantiles <- sapply(quantile_idxs, function(p) { + norm_mean + sqrt(2 * norm_var) * erfinv(2 * p - 1) +}) + +df <- data.frame( + quantile_idxs = quantile_idxs, + cauchy_gen = cauchy_gen, + cauchy_quantiles = cauchy_quantiles, + norm_quantiles = norm_quantiles +) + +# Then plot them and save the output +plot <- ggplot(df, aes(x = quantile_idxs)) + + geom_line(aes(y = cauchy_gen, color = "Generated")) + + geom_line(aes(y = cauchy_quantiles, color = "Cauchy Quantiles")) + + geom_line(aes(y = norm_quantiles, color = "Normal Quantiles")) + + xlab("Quantiles") + + ylab("") + + scale_color_manual(values = c("red", "blue", "green")) + + theme(legend.title = element_blank()) + +ggsave(plot = plot, "output.png") diff --git a/README.md b/README.md index eb1af96..d403b7d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ https://docs.google.com/document/d/1kS8zsUVcjWqqpty2CcXHi8jTA-QsOA_2Q0VsUJ4OfXM https://docs.google.com/document/d/1DnvOxo3GlUY7sBHUCcyMEbMlQE2AYFBWAOSrNZyb4d4 +## 8 + +https://docs.google.com/document/d/1x_AsfHc4JNxV8P6oOfUoZCu1yLQ9TQ82zRSoT7pDRrM + # Util ## 6