{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Maximum Likelihood estimation of a power law" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "source": [ "using MaximumLikelihoodPower\n", "const MLE = MaximumLikelihoodPower; # make a short name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The power-law distribution is known as the Pareto distribution. We get $10^6$ samples from the Pareto distribution" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "seed = 12; α = 0.5;\n", "data = MLE.Example.makeparetodata(α, seed);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can recover the exponent $\\alpha$ from the data by minimizing the\n", "[Kolmogorov-Smirnov](https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test) statistic.\n", "We compute the Kolmogorov-Smirnov statistic for $101$ equally-spaced values of $\\alpha$.\n", "\n", "`scanKS` returns the value that minimizes the statistic and the two bracketing values. The error is $1/1000$, about as good as can be expected with $10^6$ data points." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "3-element Array{Float64,1}:\n", " 0.4991\n", " 0.4992\n", " 0.4993" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scanKS(data, range(.495, length=101, stop=.505))" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.7.0-beta2", "language": "julia", "name": "julia-0.7" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.7.0" } }, "nbformat": 4, "nbformat_minor": 1 }