Nothing Special   »   [go: up one dir, main page]

Session2 Copula

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Copulas in R

Alex Isakson

March 15, 2022

alex.isakson@cass.city.ac.uk
Bayes Business School
Overview

• Fitting Data: Revision


• Copulas: Basics and Plotting
• Copulas: Fitting
• Creating Tables

1
Fitting Data: Revision
Fitting Data: Revision

Fit MLE numerically: MASS

• fitdistr(X, string) : fit data x with distribution from string: ”beta”,


”cauchy”, ”chi-squared”, ”exponential”, ”gamma”, ”geometric”,
”log-normal”, ”lognormal”, ”logistic”, ”negative binomial”,
”normal”, ”Poisson”, ”t” and ”weibull” are possible.

2
Copulas: Basics and Plotting
Copulas: Basics and Plotting

We use primarily the package copula

• claytonCopula(par, d) : Clayton copula with parameter par and


dimension d
• normalCopula(par, d) : Gaussian copula with parameter par and
dimension d
• tCopula(par, d, df) : Gaussian copula with parameter par, degrees
of freedom df and dimension d
• gumbelCopula(par, d) : Gumbel copula with parameter par and
dimension d
• mvdc(c, m, par m) : distribution made from copula c and margin
distributions m with parameters par m. Note: m must be a vector of
strings and par m must be a list

For more details, see:


https://cran.r-project.org/web/packages/copula/copula.pdf
3
Copulas: Basics and Plotting

Copulas and Sklar’s theorem:


For copula objects:

• pCopula(x, c) : density of the copula c at points x


• dCopula(x, c) : cdf of the copula c at points x

• rCopula(n, c) : random number generator of copula c

For objects made by mvdc:

• pMvdc(x, mv) : density of the distribution mv at points x


• dMvdc(x, mv) : cdf of the distribution mv at points x
• rMvdc(n, mv) : random number generator of distribution mv

4
Copulas: Basics and Plotting

For 3d plotting we use the package plotly

• plot ly(x = x, y = y, z = M) : compute plot for (x,y,M). Note: M


is a matrix.
• add surface() : show plot

Note: each option after plot ly have to be accompanied by % > %


A lot of additional recources can be found here: https://plotly.com/r/

5
Copulas: Basics and Plotting

Fast plotting:

• persp(c, xCopula) : fast 3d plot for density (dCopula) or cdf


(pCopula) of copula c
• contour(c, xCopula) : contourplot for density (dCopula) or cdf
(pCopula) of copula c
• contourplot2(c, xCopula, col.regions = col) : contourplot for
density (dCopula) or cdf (pCopula) of copula c

Note: these work like plot(). So, options like main, xlab, xlim etc. are
available.

6
Copulas: Fitting

• fitMvdc(x, mv, start) : fit Mvdc for data x and object mvdc. Note:
start-parameter must be provided in start as a list.
• fitCopula(c, x, method = ’ml’) : fit MLE for copula c and data x.

7
Copulas: Kendall’s Tau

• tau(c) : calculate Kendall’s tau for copula c.


• cor(x1, x2, method = ”kendall”) : calculate empirical Kendall’s tau
for data x1 and x2.

8
Creating Tables

Simple Table:

• as.table(m) : transform matrix m into a table.


• write.table(t, file ) : save table t as file.

Fancy Table:

• gt(m) : transform matrix m into a gt table.

• tab header(title = a, subtitle = b ) : option of adding title and


subtitle.

Note: each option after gt have to be accompanied by % > %.


A lot of additional recources can be found here:
https://gt.rstudio.com/articles/intro-creating-gt-tables.html

You might also like