Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
MATLAB Statistics Toolbox™ 估計 Copula 與 Copula 亂數求取方法 來源:Copulafit 函數說明 在 MATLAB 的 Statistics Toolbox 中,可運用下列提供方法估計 Copula 的參數與模擬。其提供的 Copula 套裝函數共有 1. Gaussian Copula 2. t Copula 3. Archimedean copula 包含'Clayton', 'Frank', or 'Gumbel'。 運用指令為 copulafit: Fit copula to data copularnd: Copula random numbers Gaussian Copula 所謂的 Gaussian Copula 即為多元常態分配下的 copula 函數,其定義為:b 若 X ( X 1 , X 2 ,..., X n ) 是 多元常態分配,則其邊際函數 F1 ,..., Fn 皆為常態分配,且存在唯一的 Copula 函數,使得 C RN (u1 ,..., u n ) R ( 1 (u1 ),..., 1 (u n )) 其中 R :標準的多元常態分配,存在著對稱且正定的相關矩陣 R。 1 則是單維標準常態分配的反函數。 當 n=2 時,我們可以得到此時的 Copula 函數為: 1 ( u ) 1 ( v ) C (u, v) N R s 2 2 R12 st t 2 1 exp{ }dsdt 2 (1 R122 )1 / 2 2(1 R122 ) t Copula t-copula 是指多元 Student’s t 分配下的 copula 函數,假設 X ( X 1 , X 2 ,..., X n ) 服從多元標準常態分配, 其相關矩陣為 R , Y 是 2 分配的隨機變數,自由度為 v ,則 t-copula 函數為: Cvt , R (u1 ,..., un ) t v, R (t v1 (u1 ),..., t v1 (un )) 其中 u i C t v,R v Y X i , i 1,..., n 。當 n=2 時,我們可以得到 t-copula 函數為: (u, v) t v1 ( u ) tv1 ( v ) s 2 2 R12 st t 2 ( v 2) / 2 1 { 1 } dsdt 2 (1 R122 )1 / 2 v(1 R122 ) Archimedean copula 多元 Archimedean Copulas Clayton-n-Copula 函數:當 α>0 ( x) x 1 => n C (u1 ,..., un ) ui n 1 i 1 1 Gumbel-n-Copula 函數 :當 α>1 ( x) ( ln x) => 1 n C (u1 ,..., un ) exp ( ln ui ) i 1 Frank-n-Copula 函數 :當 α>0,n>3 x 1 e ( x) ln 1 e => 一、首先,若已知邊際分配情況 n e ui 1 1 C (u1...un ) ln 1 i 1 n 1 ei 1 MATLAB 連續分配套件有下列指令 Continuous Distributions (Data) pdf — Probability density functions cdf — Cumulative distribution functions inv — Inverse cumulative distribution functions stat — Distribution statistics functions fit — Distribution fitting functions like — Negative log-likelihood functions rnd — Random number generators MATLAB Statistics Toolbox for Copula 運用 2 Continuous Distributions (Data) Name Beta Exponential Extreme value pdf cdf inv betapdf, betacdf, betainv, pdf cdf icdf exppdf, expcdf, expinv, pdf cdf icdf stat betastat fit betafit, mle like rnd betalike betarnd, random, randtool expstat expfit, mle, explike dfittool evpdf, pdf evcdf, cdf evinv, icdf evstat evfit, mle, randtool evlike dfittool Gamma gampdf, gamcdf, gaminv, pdf cdf icdf Generalized gevpdf, gevcdf, gevinv, extreme value pdf cdf icdf Generalized gppdf, pdf gpcdf, cdf gpinv, Pareto gamstat gevstat lognpdf, logncdf, logninv, pdf cdf icdf Normal normpdf, normcdf, norminv, (Gaussian) pdf cdf icdf pdf cdf icdf Rayleigh raylpdf, raylcdf, raylinv, pdf cdf icdf gpstat gpfit, lognstat lognfit, mle, gevlike raylstat gevrnd, random, randtool gplike gprnd, random, randtool lognlike lognrnd, random, dfittool normstat normfit, mle, gamrnd, randg, random, randtool mle,dfittool Rician randtool normlike normrnd, randn, dfittool random, randtool pearsrnd pearsrnd paretotails random raylfit, mle, raylrnd, random, dfittool randtool dfittool Uniform unifpdf, unifcdf, unifinv, (continuous) pdf cdf icdf Weibull wblpdf, wblcdf, wblinv, pdf cdf icdf MATLAB gamlike mle,dfittool Pearson system Piecewise gevfit, evrnd, random, randtool dfittool icdf Lognormal gamfit, mle, exprnd, random, Statistics Toolbox for Copula 運用 unifstat unifit, mle unifrnd, rand, random wblstat wblfit, mle, dfittool 3 wbllike wblrnd, random Name pdf cdf inv stat (反函數) (統計 rnd 量) Chi-square chi2pdf, pdf chi2cdf, cdf chi2inv, icdf chi2stat chi2rnd, random, randtool F fpdf, pdf fcdf, cdf finv, icdf fstat frnd, random, randtool Noncentral ncx2pdf, ncx2cdf, ncx2inv, ncx2stat ncx2rnd, random, chi-square pdf cdf icdf Noncentral F ncfpdf, pdf ncfcdf, cdf ncfinv, icdf randtool ncfstat ncfrnd, random, randtool Noncentral t nctpdf, pdf nctcdf, cdf nctinv, icdf nctstat nctrnd, random, randtool Student's t tpdf, pdf tcdf, cdf tinv, icdf tstat trnd, random, randtool 例如,若虛設一組資料是 N(3,16),另一組是 Gamma(0.2,0.3)的資料如下: data = 3+4*randn(2000,1); data1= gamrnd(0.2,0.3,1,2000); 函數含義 :R = gamrnd(A,B,m,n) generates gamma random numbers with parameters A and B, where scalars m and n are the row and column dimensions of R. he gamma pdf is 則可用 mle 指令求得 phat = 3.0746 4.0807 pci = 2.8956 3.9590 3.2536 4.2123 0.0587 0.1174% => returns MLEs and 95% confidence intervals for the parameters. MATLAB Statistics Toolbox for Copula 運用 4 [nlogL,AVAR] = normlike(phat ,data) nlogL = 5.6504e+003 AVAR = 0.0083 -0.0000 -0.0000 0.0042 函數含義 :nlogL = normlike(params,data) returns the negative of the normal log-likelihood function for the parameters params(1) = mu and params(2) = sigma, given the vector data. [nlogL,AVAR] = normlike(params,data) also returns the inverse of Fisher's information matrix, AVAR. If the input parameter values in params are the maximum likelihood estimates, the diagonal elements of AVAR are their asymptotic variances. AVAR is based on the observed Fisher's information, not the expected information. t_value=phat./sqrt(diag(AVAR)') t_value = 33.6955 63.2456 [phat1,pci] = mle(data1,'distribution','gamma') phat1 = 0.1932 0.2882 pci = 0.1843 0.2581 0.2026 0.3219 [nlogL,AVAR1] = gamlike(phat1 ,data1) nlogL = -7.8126e+003 AVAR1 = 1.0e-003 * 0.0218 -0.0326 -0.0326 0.2636 t_value=phat1./sqrt(diag(AVAR1)') MATLAB Statistics Toolbox for Copula 運用 5 t_value = 41.3397 17.7522 %以下要給定 Copula 的 u and v u = normcdf(data,phat(1),phat(2)); v=gamcdf(data1,phat1(1),phat1(2)); scatterhist(u,v);xlabel('u');ylabel('v'); Rho = copulafit('Gaussian',[u v']) Rho = 1.0000 -0.0111 -0.0111 1.0000 [Rho,nu] = copulafit('t',[u v']) %[u v'] 是 2000*1 矩陣 Rho = 1.0000 -0.0112 -0.0112 1.0000 nu = 108.7465 MATLAB Statistics Toolbox for Copula 運用 6 函數含義 :HOHAT = copulafit('Gaussian',U) returns an estimate RHOHAT of the matrix of linear correlation parameters for a Gaussian copula, given data in U. U is an n-by-p matrix of values in the open interval (0,1) representing n points in the p-dimensional unit hypercube. 函數含義 :[RHOHAT,nuhat] = copulafit('t',U) returns an estimate RHOHAT of the matrix of linear correlation parameters for a t copula and an estimate nuhat of the degrees of freedom parameter, given data in U. U is an n-by-p matrix of values in the open interval (0,1) representing n points in the p-dimensional unit hypercube. Generate a random sample from the t copula: r = copularnd('t',Rho,nu,1000); u1 = r(:,1); v1 = r(:,2); 函數含義 :U = copularnd('t',rho,NU,N) returns N random vectors generated from a t copula with linear correlation parameters rho and degrees of freedom NU. If rho is a p-by-p correlation matrix, U is an n-by-p matrix. If rho is a scalar correlation coefficient, copularnd generates U from a bivariate t copula. Each column of U is a sample from a Uniform(0,1) marginal distribution. scatterhist(u1,v1) xlabel('u') ylabel('v') MATLAB Statistics Toolbox for Copula 運用 7 Transform the random sample back to the original scale of the data: x=norminv(u1,phat(1),phat(2)); y=gaminv(v1,phat1(1),phat1(2)); 運用上述步驟就可求一組資料是 N(3,16),另一組是 Gamma(0.2,0.3)的隨機樣本 1000 組。 二、未知邊際分配 (來源: Statistics Toolbox™ copulafit) Load and plot simulated stock return data: load stockreturns x = stocks(:,1); y = stocks(:,2); scatterhist(x,y) Transform the data to the copula scale (unit square) using a kernel estimator of the cumulative distribution function: (無母數用法) u = ksdensity(x,x,'function','cdf');%=>自動將 x 的資料轉成 CDF 資料 v = ksdensity(y,y,'function','cdf'); %=>自動將 y 的資料轉成 CDF 資料 scatterhist(u,v);xlabel('u');ylabel('v') MATLAB Statistics Toolbox for Copula 運用 8 函數含義 :[f,xi] = ksdensity(x) computes a probability density estimate of the sample in the vector x. f is the vector of density values evaluated at the points in xi. (Kernel smoothing density estimate) The function type to estimate, chosen from among 'pdf', 'cdf', 'icdf', 'survivor', or 'cumhazard' for the density, cumulative probability, inverse cumulative probability, survivor, or cumulative hazard functions, respectively. Fit a Gaussian copula: Rho = copulafit('Gaussian',[u v]) Rho = 1.0000 0.7221 0.7221 1.0000 補充:paramhat = copulafit(family,U) returns an estimate paramhat of the copula parameter for an Archimedean copula specified by family, given data in U. U is an n-by-2 matrix of values in the open interval (0,1) representing n points in the unit square. Family is one of 'Clayton', 'Frank', or 'Gumbel'. Generate a random sample from the Gaussian copula r = copularnd('t',Rho,nu,1000); u1 = r(:,1); v1 = r(:,2); scatterhist(u1,v1);xlabel('u');ylabel('v') MATLAB Statistics Toolbox for Copula 運用 9 Transform the random sample back to the original scale of the data: x1 = ksdensity(u,u1,'function','icdf'); y1 = ksdensity(v,v1,'function','icdf'); scatterhist(x1,y1) MATLAB Statistics Toolbox for Copula 運用 10