Import the library
In [1]:
import pyvinecopulib as pv
Create an independence bivariate copula
In [2]:
pv.Bicop()
Out[2]:
Create a Gaussian copula See help(pv.BicopFamily) for the available families
In [3]:
pv.Bicop(family=pv.BicopFamily.gaussian)
Out[3]:
Create a 90 degrees rotated Clayon copula with parameter = 3
In [4]:
pv.Bicop(family=pv.BicopFamily.clayton, rotation=90, parameters=[3])
Out[4]:
Create a t copula with correlation of 0.5 and 4 degrees of freedom and showcase some methods
In [5]:
cop = pv.Bicop(family=pv.BicopFamily.student, rotation=0, parameters=[0.5, 4])
u = cop.simulate(n=10, seeds=[1, 2, 3])
fcts = [cop.pdf, cop.cdf,
cop.hfunc1, cop.hfunc2,
cop.hinv1, cop.hinv2,
cop.loglik, cop.aic, cop.bic]
[f(u) for f in fcts]
Out[5]:
Different ways to fit a copula...
In [6]:
u = cop.simulate(n=1000, seeds=[1, 2, 3])
# Create a new object an sets its parameters by fitting afterwards
cop2 = pv.Bicop(pv.BicopFamily.student)
cop2.fit(data=u)
print(cop2)
# Otherwise, define first an object to control the fits:
# - pv.FitControlsBicop objects store the controls
# - here, we only restrict the parametric family
# - see help(pv.FitControlsBicop) for more details
# Then, create a copula from the data
controls = pv.FitControlsBicop(family_set=[pv.BicopFamily.student])
print(controls)
cop2 = pv.Bicop(data=u, controls=controls)
print(cop2)
Similarly, when the family is unkown, there are two ways to also do model selection...
In [7]:
# Create a new object an selects both its family and parameters afterwards
cop3 = pv.Bicop()
cop3.select(data=u)
print(cop3)
# Or create directly from data
cop3 = pv.Bicop(data=u)
print(cop3)
In [ ]: