Skip to content

Instantly share code, notes, and snippets.

@schnellp
schnellp / params-from-quantiles.R
Created April 28, 2015 13:09
An R function for finding parameters of normal, beta, and gamma distributions that match a given pair of quantiles
params.from.quantiles <- function(q, p, family="normal", start=c(0.5, 0.5)) {
# Finds parameter values of distributions that closely match
# the specified quantiles.
#
# Args:
# q: A vector of quantiles (length 2, strictly increasing)
# p: A vector of percentiles (length 2, strictly increasing)
# family: One of "normal", "beta", or "gamma" specifying
# which family of distributions to use
# start: starting values for parameter search
@schnellp
schnellp / qqfind.R
Created April 28, 2015 13:38
Which normal Q-Q plot is of the real data?
qqfind <- function(x) {
# Generates the normal Q-Q plot for the given data
# as well as for three samples of the same size
# from a normal distribution with matching
# mean and variance.
#
# If it's obvious which one is the real data,
# it might not be normally distributed.
#
# Return value is the index of the plot