/**
* jQuery Plugin: Sticky Tabs
*
* @author Aidan Lister
// Set the correct tab when the page loads showStuffFromHash(context);
// Set the correct tab when a user uses their back/forward button $(window).on('hashchange', function() { showStuffFromHash(context); });
// Change the URL when tabs are clicked $('a', context).on('click', function(e) { history.pushState(null, null, this.href); showStuffFromHash(context); });
return this; }; }(jQuery));
window.buildTabsets = function(tocID) {
// build a tabset from a section div with the .tabset class function buildTabset(tabset) {
// check for fade and pills options var fade = tabset.hasClass("tabset-fade"); var pills = tabset.hasClass("tabset-pills"); var navClass = pills ? "nav-pills" : "nav-tabs";
// determine the heading level of the tabset and tabs var match = tabset.attr('class').match(/level(\d) /); if (match === null) return; var tabsetLevel = Number(match[1]); var tabLevel = tabsetLevel + 1;
// find all subheadings immediately below var tabs = tabset.find("div.section.level" + tabLevel); if (!tabs.length) return;
// create tablist and tab-content elements var tabList = $('
'); $(tabs[0]).before(tabList); var tabContent = $('
'); $(tabs[0]).before(tabContent);
// build the tabset var activeTab = 0; tabs.each(function(i) {
// get the tab div var tab = $(tabs[i]);
// get the id then sanitize it for use with bootstrap tabs var id = tab.attr('id');
// see if this is marked as the active tab if (tab.hasClass('active')) activeTab = i;
// remove any table of contents entries associated with // this ID (since we'll be removing the heading element) $("div#" + tocID + " li a[href='#" + id + "']").parent().remove();
// sanitize the id for use with bootstrap tabs id = id.replace(/[.\/?&!#<>]/g, '').replace(/\s/g, '_'); tab.attr('id', id);
// get the heading element within it, grab it's text, then remove it var heading = tab.find('h' + tabLevel + ':first'); var headingText = heading.html(); heading.remove();
// build and append the tab list item var a = $('' + headingText + ''); a.attr('href', '#' + id); a.attr('aria-controls', id); var li = $('
'); li.append(a); tabList.append(li);
// set it's attributes tab.attr('role', 'tabpanel'); tab.addClass('tab-pane'); tab.addClass('tabbed-pane'); if (fade) tab.addClass('fade');
// move it into the tab content div tab.detach().appendTo(tabContent); });
// set active tab $(tabList.children('li')[activeTab]).addClass('active'); var active = $(tabContent.children('div.section')[activeTab]); active.addClass('active'); if (fade) active.addClass('in');
if (tabset.hasClass("tabset-sticky")) tabset.rmarkdownStickyTabs(); }
// convert section divs with the .tabset class to tabsets var tabsets = $("div.section.tabset"); tabsets.each(function(i) { buildTabset($(tabsets[i])); }); };
FI 450/597 - 10.10.2023
Continuous Distributions
Pareto - default is Type II
# Make sure to load actuar!
library(actuar)
x = seq(0,10,.01)
alpha = 5 # shape
theta = 10 # scale
p = dpareto(x,shape=alpha,scale=theta) # density
P = ppareto(x,shape=alpha,scale=theta) # CDF
plot(x,p,type='l',main="PDF and CDF (blue) for Pareto",ylim=c(0,1),xlim=c(0,10))
lines(x,P,col="blue")
For a Pareto distribution with α = 3 and θ = 1000, determine VaR at
the 95% security level.
qpareto(.95,3,1000)
[1] 1714.418
and it’s worth comparing to \(\theta=10\).
qpareto(.95,3,10) # notice the difference with the change in scale parameter!
[1] 17.14418
From the STAM tables, notice that \(E[X^k]\) has a factor in the denominator of
\((\alpha-k)\).
What does this imply about the moments of a Pareto distribution?
Note: If \(X\) ~ Pareto(\(\alpha\), \(\theta\)), then \(X-d\) | \(X>d\) ~ Pareto(\(\alpha\), \(\theta+d\)).
Single-Parameter Pareto
An S-P Pareto with parameters \(\alpha,\theta\) is a Pareto (\(\alpha, \theta^*\)) that is
shifted by the \(\theta\).
sp.theta = 4
sp = dpareto1(x,shape=alpha,min=sp.theta) # density
SP = ppareto1(x,shape=alpha,min=sp.theta) # CDF
plot(x,p,type='l', main="S-P Pareto is a shifted Pareto",ylim=c(0,1),xlim=c(0,10))
lines(x,P)
lines(x,sp,col="blue")
lines(x,SP,col="blue")
However, while a Pareto is defined for \(x>0\), the S-P Pareto is only defined
for \(x>\theta\).
Inverse Pareto
Although the Inverse Pareto distribution is parameterized by \(\tau\) and \(\theta\), rather than \(\alpha\) and \(\theta\), the connection to Pareto is
straightforward.
If \(X\) ~ Pareto(\(\alpha\), \(\theta\)), then \(X^{-1}\) ~ Inverse Pareto(\(\tau=\alpha\), \(\theta^{-1}\)).
x = seq(0,2,.01)
alpha = 3 # shape
theta = .2 # scale
p = dpareto(x,shape=alpha,scale=theta) # density
invp = dinvpareto(x,shape=alpha,scale=theta) # inverse density
plot(x,p,type='l',main='Pareto and Inverse Pareto (red)',ylim=c(0,5),xlim=c(0,2))
lines(x,invp,col='red')
Gamma
Don’t confuse the Gamma(\(\alpha,\theta\)) with the gamma function,
\(\Gamma(n)=(n-1)!\), or with the
incomplete gamma function, \(\Gamma(n;x)\).
x = seq(0,20,.1)
alpha1 = 2 # shape
alpha2 = 4 # shape
theta1 = 5 # scale1
theta2 = 10 # scale2
p1 = dgamma(x,shape=alpha1,scale=theta1) # MUST use "scale=" !!!!
p1.5 = dgamma(x,shape=alpha2,scale=theta1) # MUST use "scale=" !!!!
p2 = dgamma(x,shape=alpha1,scale=theta2) # MUST use "scale=" !!!!
plot(x,p1,type='l',main='Variations on Gamma',ylim=c(0,.1),xlim=c(0,20))
lines(x,p2,col='red')
lines(x,p1.5,col='blue')
Note: The Poisson Shortcut
While finding the CDF for a Gamma distribution is SUPER simple in R,
it’s not so easy if you’re working with a pencil and paper. When going
old school, this shortcut is extremely useful to evaluate \(\Gamma(\alpha;x/\theta)\) when \(\alpha\) and is a positive integer.
Let \(N\) ~ Poisson(\(\lambda=k\)) and \(\alpha\) a positive integer. Then \(\Gamma(\alpha;k)=1-F_N(\alpha-1)=1-Pr(N<\alpha)\).
Let \(X\) ~ Gamma(\(\alpha=2,\theta=10\)). What is \(F_X(12)\)?
So, \(\alpha=2,\theta=10,\) and
\(x=12\).
pgamma(12,shape=2,scale=10) # CDF of the Gamma at x=12
[1] 0.3373727
OR
Use Poisson shortcut with \(k=\frac{x}{\theta}=1.2\).
1-ppois(1,lambda=1.2) # don't forget to use alpha-1 !
[1] 0.3373727
Sum of independent gammas
As was the case with (a,b,0), the sum of independent gammas with the
same scale parameter is also gamma with \(\alpha=\sum_i\alpha_i\) and \(\theta = \theta\).
Exponential Distribution
An exponential distribution is a gamma with \(\alpha = 1\). Therefore, given what we now
know about the sum of independent gammas, we can see easily that the sum
of \(n\) iid exponential RVs having the
same \(\theta\) is gamma(\(n,\theta\)).
Remember also that, like the geometric distribution, the exponential
distribution is memorylesss. That is,
If \(X\) ~ Exponential(\(\theta\)), then \(X-d\) | \(X>d\) ~ Exponential(\(\theta\)).
Weibull Distribution
A Weibull is a \(\tau^{\text{th}}\)
rooted exponential.
That is, if \(X\) ~
Exponential(\(\mu\)), then \(X^{1/\tau}\) ~ Weibull(\(\theta = \mu^{1/\tau},\tau\)).
A family photo
x = seq(0,10,.01)
gamma = dgamma(x,shape=2,scale=2)
expon = dexp(x,rate=1) # rate is theta
weibull = dweibull(x,shape=1/2,scale=2)
plot(x,gamma,type='l',main='Gamma Family - Gamma (black), Expon (red), Weibull (blue)',ylab='prob',ylim=c(0,1),xlim=c(0,10))
lines(x,expon,col='red')
lines(x,weibull,col='blue')
Finally, each of these
distributions has an inverse version:
If \(X\) ~ Gamma(\(\alpha,\theta\)), then \(X^{-1}\) ~ Inverse Gamma(\(\alpha,\theta^{-1}\)).
If \(X\) ~ Exponential(\(\theta\)), then \(X^{-1}\) ~ Inverse Exponential(\(\theta^{-1}\)).
If \(X\) ~ Weibull(\(\theta,\tau\)), then \(X^{-1}\) ~ Inverse Weibull(\(\theta^{-1},\tau\)).
// add bootstrap table styles to pandoc tables function bootstrapStylePandocTables() { $('tr.odd').parent('tbody').parent('table').addClass('table table-condensed'); } $(document).ready(function () { bootstrapStylePandocTables(); });