Fit a non parametric copulaΒΆ

In this example we are going to estimate a normal copula from a sample using non parametric representations.

from __future__ import print_function
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
ot.Log.Show(ot.Log.NONE)

Create data

R = ot.CorrelationMatrix(2)
R[1, 0] = 0.4
copula = ot.NormalCopula(R)
sample = copula.getSample(30)

Estimate a normal copula using BernsteinCopulaFactory

distribution = ot.BernsteinCopulaFactory().build(sample)

Draw fitted distribution

graph = distribution.drawPDF()
view = viewer.View(graph)
[X0,X1] iso-PDF

Out:

/home/devel/project/build/python/src/site-packages/openturns/viewer.py:432: UserWarning: No contour levels were found within the data range.
  contourset = self._ax[0].contour(X, Y, Z, **contour_kw)

Estimate a normal copula using KernelSmoothing

distribution = ot.KernelSmoothing().build(sample).getCopula()
graph = distribution.drawPDF()
view = viewer.View(graph)
plt.show()
[X0,X1] iso-PDF

Total running time of the script: ( 0 minutes 0.231 seconds)

Gallery generated by Sphinx-Gallery