From noreply at r-forge.r-project.org Tue Apr 22 15:49:05 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 22 Apr 2014 15:49:05 +0200 (CEST) Subject: [Vinecopula-commits] r64 - pkg/src Message-ID: <20140422134905.727C0186DE8@r-forge.r-project.org> Author: ulf Date: 2014-04-22 15:49:04 +0200 (Tue, 22 Apr 2014) New Revision: 64 Modified: pkg/src/deriv.c pkg/src/deriv2.c pkg/src/hfunc.c pkg/src/hfuncderiv.c pkg/src/hfuncderiv2.c pkg/src/likelihood.c Log: Kleine Warnings behoben in den C-files. Gefunden durch neuen Kompiler Modified: pkg/src/deriv.c =================================================================== --- pkg/src/deriv.c 2014-03-26 15:18:51 UTC (rev 63) +++ pkg/src/deriv.c 2014-04-22 13:49:04 UTC (rev 64) @@ -1,513 +1,513 @@ -/* -** deriv.c - C code of the package CDRVine -** -** by Ulf Schepsmeier -** -** -** -*/ - -#include "include/vine.h" -#include "include/deriv.h" -#include "include/tcopuladeriv.h" -#include "include/tcopuladeriv_new.h" - -#define UMAX 1-1e-10 - -#define UMIN 1e-10 - -#define XEPS 1e-4 - - - -///////////////////////////////////////////////////////////// -// -// Ableitung der Copula nach dem Parameter -// -///////////////////////////////////////////////////////////// - -void diffPDF_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - int ncopula; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - int i; - -if((*copula==43)) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diffPDF(u, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=out[i]*2/pow(1-param[0],2);} - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF(u, negv, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i]*2/pow(1+param[0],2); } - } - }else if((*copula==44)) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diffPDF(u, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=out[i]/pow(1-param[0],2);} - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF(u, negv, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i]/pow(1+param[0],2); } - } - }else{ - - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90° rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF(u, negv, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270° rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diffPDF(negu, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180° rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diffPDF(negu, negv, n, param, &ncopula, out); - } - else - { - diffPDF(u, v, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); -} - - - - -void diffPDF(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - int j; - double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t24, t26, t27, t28, t29, t30, t32, t33, t34, t35, t36; - t3=0; - t4=0; - - double theta = param[0]; - //double delta = param[1]; - - for(j=0;j<*n;j++) - { - if(*copula==0) - { - out[j]=0; - } - else if(*copula==1) - { - t1 = qnorm(u[j],0.0,1.0,1,0); - t2 = qnorm(v[j],0.0,1.0,1,0); - t4 = t1*t1; - t5 = t2*t2; - t3 = t4+t5; - t7 = theta*theta; - t8 = 1.0-t7; - t9 = 1/t8/2.0; - t15 = t7*t3-2.0*theta*t1*t2; - t22 = exp(-t15*t9); - t24 = sqrt(t8); - out[j] = (-2.0*(theta*t3-t1*t2)*t9-t15/(t8*t8)*theta)*t22/t24+t22/t24/t8*theta; - } - else if(*copula==3) - { - t1 = u[j]*v[j]; - t2 = -theta-1.0; - t3 = pow(t1,1.0*t2); - t4 = pow(u[j],-1.0*theta); - t5 = pow(v[j],-1.0*theta); - t6 = t4+t5-1.0; - t7 = -2.0-1/theta; - t8 = pow(t6,1.0*t7); - t9 = -t2*t3; - t10 = log(t1); - t11 = theta*theta; - t12 = log(t6); - t13 = log(u[j]); - t14 = log(v[j]); - out[j] = t3*t8-t9*t10*t8+t9*t8*(1/t11*t12+t7*(-t4*t13-t5*t14)/t6); - } - else if(*copula==4) - { - t3 = log(u[j]); - t4 = pow(-t3,1.0*theta); - t5 = log(v[j]); - t6 = pow(-t5,1.0*theta); - t7 = t4+t6; - t8 = 1/theta; - t9 = pow(t7,1.0*t8); - t10 = theta*theta; - t12 = log(t7); - t13 = 1/t10*t12; - t14 = log(-t3); - t16 = log(-t5); - t18 = t4*t14+t6*t16; - t20 = 1/t7; - t22 = -t13+t8*t18*t20; - t24 = exp(-t9); - t26 = t24/u[j]; - t28 = 1/v[j]; - t29 = -1.0+t8; - t30 = pow(t7,2.0*t29); - t32 = t3*t5; - t33 = theta-1.0; - t34 = pow(t32,1.0*t33); - t35 = pow(t7,-1.0*t8); - t36 = t33*t35; - t17 = 1.0+t36; - t15 = t34*t17; - t11 = t26*t28; - t2 = t30*t34; - t1 = log(t32); - out[j] = -t9*t22*t26*t28*t30*t15+t11*t30*(-2.0*t13+2.0*t29*t18*t20)*t15+t11* - t2*t1*t17+t11*t2*(t35-t36*t22); - - } - else if(*copula==5) - { - t2 = exp(theta); - t3 = t2-1.0; - t4 = theta*v[j]; - t5 = theta*u[j]; - t7 = exp(t4+t5+theta); - t10 = exp(t4+t5); - t12 = exp(t4+theta); - t14 = exp(t5+theta); - t15 = t10-t12-t14+t2; - t16 = t15*t15; - t17 = 1/t16; - t21 = theta*t3; - out[j] = t3*t7*t17+theta*t2*t7*t17+t21*(v[j]+u[j]+1.0)*t7*t17-2.0*t21*t7/t15/t16*((v[j]+u[j])*t10-(v[j]+1.0)*t12-(u[j]+1.0)*t14+t2); - } - else if(*copula==6) - { - t1 = 1.0-u[j]; - t2 = pow(t1,1.0*theta); - t3 = 1.0-v[j]; - t4 = pow(t3,1.0*theta); - t5 = t2*t4; - t6 = t2+t4-t5; - t8 = 1/theta-2.0; - t9 = pow(t6,1.0*t8); - t10 = theta*theta; - t11 = log(t6); - t12 = log(t1); - t13 = t2*t12; - t14 = log(t3); - t15 = t4*t14; - t16 = t13*t4; - t19 = t5*t14; - t21 = theta-1.0; - t27 = pow(t1,1.0*t21); - t28 = pow(t3,1.0*t21); - t30 = theta-1.0+t2+t4-t5; - t33 = t9*t27; - out[j] = t9*(-1/t10*t11+t8*(t13+t15-t16-t19)/t6)*t27*t28*t30+t33*t12*t28*t30 - +t33*t28*t14*t30+t33*t28*(1.0+t13+t15-t16-t19); - } - - } - -} - - -//////////////////////////////////////////////////////////////////// -// -// 1. Ableitung von c nach u -// -//////////////////////////////////////////////////////////////////// - -void diffPDF_u_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - int ncopula, i; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - -if((*copula==43)) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diffPDF_u(u, v, n, nparam, &ncopula, out); - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else if((*copula==44)) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diffPDF_u(u, v, n, nparam, &ncopula, out); - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else{ - - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90° rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270° rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diffPDF_u(negu, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180° rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diffPDF_u(negu, negv, n, param, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else - { - diffPDF_u(u, v, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); -} - -void diffPDF_u(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - int j, k=1; - double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t18, t19, t20, t21, t22, t23, t24, t25, t27, t28, t29; - double t30, t33, t36; - - double theta = param[0]; - //double delta = param[1]; - - for(j=0;j<*n;j++) - { - if(*copula==0) - { - out[j]=0; - } - else if(*copula==1) - { - t1 = qnorm(u[j],0.0,1.0,1,0); - t2 = qnorm(v[j],0.0,1.0,1,0); - t3 = theta*theta; - t4 = 1.0-t3; - t5 = sqrt(t4); - t6 = pow(t1,2.0); - t7 = pow(t2,2.0); - t8 = t3*(t6+t7)-(2.0*theta*t1*t2); - t9 = exp(-t8/t4/2.0); - t10 = t9/t5; - t11 = sqrt(2.0*pi); - t12 = exp(-t6/2.0); - t13 = t11/t12; - out[j] = -t10*(theta*t13/t4)*(theta*t1-t2); - } - else if(*copula==2) - { - diffPDF_u_tCopula_new(&u[j], &v[j], &k, param, copula, &out[j]); - } - else if(*copula==3) - { - t1 = 1.0+theta; - t3 = pow(u[j]*v[j],-1.0*t1); - t4 = t1*t3; - t5 = 1/u[j]; - t7 = pow(u[j],-1.0*theta); - t8 = pow(v[j],-1.0*theta); - t9 = t7+t8-1.0; - t11 = -2.0-1/theta; - t12 = pow(t9,1.0*t11); - out[j] = -t4*t1*t5*t12-t4*t12*t11*t7*theta*t5/t9; - } - else if(*copula==4) - { - t3 = log(u[j]); - t4 = pow(-t3,1.0*theta); - t5 = log(v[j]); - t6 = pow(-t5,1.0*theta); - t7 = t4+t6; - t8 = 1/theta; - t9 = pow(t7,1.0*t8); - t11 = u[j]*u[j]; - t12 = 1/t11; - t13 = 1/t3; - t15 = 1/t7; - t18 = exp(-t9); - t19 = 1/v[j]; - t21 = -1.0+t8; - t22 = pow(t7,2.0*t21); - t24 = theta-1.0; - t25 = pow(t3*t5,1.0*t24); - t27 = pow(t7,-1.0*t8); - t28 = t24*t27; - t29 = 1.0+t28; - t30 = t22*t25*t29; - t33 = t18*t12; - t36 = t19*t22; - out[j] = -t9*t4*t12*t13*t15*t18*t19*t30-t33*t19*t30+2.0*t33*t36*t21*t4*theta - *t13*t15*t25*t29+t33*t36*t25*t24*t13*t29-t33*t36*t25*t28*t4*t13*t15; - } - else if(*copula==5) - { - t1 = theta*theta; - t2 = exp(theta); - t3 = t2-1.0; - t5 = theta*v[j]; - t6 = theta*u[j]; - t8 = exp(t5+t6+theta); - t10 = exp(t5+t6); - t12 = exp(t5+theta); - t14 = exp(t6+theta); - t15 = t10-t12-t14+t2; - t16 = t15*t15; - out[j] = t1*t3*t8/t16-2.0*theta*t3*t8/t16/t15*(theta*t10-theta*t14); - } - else if(*copula==6) - { - t1 = 1.0-u[j]; - t2 = pow(t1,1.0*theta); - t3 = 1.0-v[j]; - t4 = pow(t3,1.0*theta); - t5 = t2*t4; - t6 = t2+t4-t5; - t8 = 1/theta-2.0; - t9 = pow(t6,1.0*t8); - t11 = t2*theta; - t12 = 1/t1; - t16 = -t11*t12+t11*t12*t4; - t19 = theta-1.0; - t20 = pow(t1,1.0*t19); - t22 = pow(t3,1.0*t19); - t23 = theta-1.0+t2+t4-t5; - t27 = t9*t20; - out[j] = t9*t8*t16/t6*t20*t22*t23-t27*t19*t12*t22*t23+t27*t22*t16; - } - } - -} - - -//////////////////////////////////////////////////////////////////// -// -// 1. Ableitung von c nach v -// -//////////////////////////////////////////////////////////////////// - -void diffPDF_v_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - int ncopula, i; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - -if((*copula==43)) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diffPDF_u(v, u, n, nparam, &ncopula, out); - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(negv, u, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else if((*copula==44)) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diffPDF_u(v, u, n, nparam, &ncopula, out); - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(negv, u, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else{ - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90° rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(negv, u, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270° rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diffPDF_u(v, negu, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180° rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diffPDF_u(negv, negu, n, param, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else - { - diffPDF_u(v, u, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); -} - +/* +** deriv.c - C code of the package CDRVine +** +** by Ulf Schepsmeier +** +** +** +*/ + +#include "include/vine.h" +#include "include/deriv.h" +#include "include/tcopuladeriv.h" +#include "include/tcopuladeriv_new.h" + +#define UMAX 1-1e-10 + +#define UMIN 1e-10 + +#define XEPS 1e-4 + + + +///////////////////////////////////////////////////////////// +// +// Ableitung der Copula nach dem Parameter +// +///////////////////////////////////////////////////////////// + +void diffPDF_mod(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + double* negv; + double* negu; + double* nparam; + negv = (double *) malloc(*n*sizeof(double)); + negu = (double *) malloc(*n*sizeof(double)); + nparam = (double *) malloc(2*sizeof(double)); + int ncopula; + nparam[0]=-param[0]; + nparam[1]=-param[1]; + int i; + +if((*copula)==43) + { + ncopula=3; + if(param[0] > 0){ + nparam[0]=2*(param[0])/(1-param[0]); + diffPDF(u, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=out[i]*2/pow(1-param[0],2);} + }else{ + nparam[0]=-2*(param[0])/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF(u, negv, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i]*2/pow(1+param[0],2); } + } + }else if((*copula)==44) + { + ncopula=4; + if(param[0] > 0){ + nparam[0]=1/(1-param[0]); + diffPDF(u, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=out[i]/pow(1-param[0],2);} + }else{ + nparam[0]=1/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF(u, negv, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i]/pow(1+param[0],2); } + } + }else{ + + if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas + { + ncopula = (*copula)-20; + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF(u, negv, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas + { + ncopula = (*copula)-30; + for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} + diffPDF(negu, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas + { + ncopula = (*copula)-10; + for (i = 0; i < *n; ++i) + { + negv[i] = 1 - v[i]; + negu[i] = 1 - u[i]; + } + diffPDF(negu, negv, n, param, &ncopula, out); + } + else + { + diffPDF(u, v, n, param, copula, out); + } + } + free(negv); + free(negu); + free(nparam); +} + + + + +void diffPDF(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + int j; + double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t24, t26, t27, t28, t29, t30, t32, t33, t34, t35, t36; + t3=0; + t4=0; + + double theta = param[0]; + //double delta = param[1]; + + for(j=0;j<*n;j++) + { + if(*copula==0) + { + out[j]=0; + } + else if(*copula==1) + { + t1 = qnorm(u[j],0.0,1.0,1,0); + t2 = qnorm(v[j],0.0,1.0,1,0); + t4 = t1*t1; + t5 = t2*t2; + t3 = t4+t5; + t7 = theta*theta; + t8 = 1.0-t7; + t9 = 1/t8/2.0; + t15 = t7*t3-2.0*theta*t1*t2; + t22 = exp(-t15*t9); + t24 = sqrt(t8); + out[j] = (-2.0*(theta*t3-t1*t2)*t9-t15/(t8*t8)*theta)*t22/t24+t22/t24/t8*theta; + } + else if(*copula==3) + { + t1 = u[j]*v[j]; + t2 = -theta-1.0; + t3 = pow(t1,1.0*t2); + t4 = pow(u[j],-1.0*theta); + t5 = pow(v[j],-1.0*theta); + t6 = t4+t5-1.0; + t7 = -2.0-1/theta; + t8 = pow(t6,1.0*t7); + t9 = -t2*t3; + t10 = log(t1); + t11 = theta*theta; + t12 = log(t6); + t13 = log(u[j]); + t14 = log(v[j]); + out[j] = t3*t8-t9*t10*t8+t9*t8*(1/t11*t12+t7*(-t4*t13-t5*t14)/t6); + } + else if(*copula==4) + { + t3 = log(u[j]); + t4 = pow(-t3,1.0*theta); + t5 = log(v[j]); + t6 = pow(-t5,1.0*theta); + t7 = t4+t6; + t8 = 1/theta; + t9 = pow(t7,1.0*t8); + t10 = theta*theta; + t12 = log(t7); + t13 = 1/t10*t12; + t14 = log(-t3); + t16 = log(-t5); + t18 = t4*t14+t6*t16; + t20 = 1/t7; + t22 = -t13+t8*t18*t20; + t24 = exp(-t9); + t26 = t24/u[j]; + t28 = 1/v[j]; + t29 = -1.0+t8; + t30 = pow(t7,2.0*t29); + t32 = t3*t5; + t33 = theta-1.0; + t34 = pow(t32,1.0*t33); + t35 = pow(t7,-1.0*t8); + t36 = t33*t35; + t17 = 1.0+t36; + t15 = t34*t17; + t11 = t26*t28; + t2 = t30*t34; + t1 = log(t32); + out[j] = -t9*t22*t26*t28*t30*t15+t11*t30*(-2.0*t13+2.0*t29*t18*t20)*t15+t11* + t2*t1*t17+t11*t2*(t35-t36*t22); + + } + else if(*copula==5) + { + t2 = exp(theta); + t3 = t2-1.0; + t4 = theta*v[j]; + t5 = theta*u[j]; + t7 = exp(t4+t5+theta); + t10 = exp(t4+t5); + t12 = exp(t4+theta); + t14 = exp(t5+theta); + t15 = t10-t12-t14+t2; + t16 = t15*t15; + t17 = 1/t16; + t21 = theta*t3; + out[j] = t3*t7*t17+theta*t2*t7*t17+t21*(v[j]+u[j]+1.0)*t7*t17-2.0*t21*t7/t15/t16*((v[j]+u[j])*t10-(v[j]+1.0)*t12-(u[j]+1.0)*t14+t2); + } + else if(*copula==6) + { + t1 = 1.0-u[j]; + t2 = pow(t1,1.0*theta); + t3 = 1.0-v[j]; + t4 = pow(t3,1.0*theta); + t5 = t2*t4; + t6 = t2+t4-t5; + t8 = 1/theta-2.0; + t9 = pow(t6,1.0*t8); + t10 = theta*theta; + t11 = log(t6); + t12 = log(t1); + t13 = t2*t12; + t14 = log(t3); + t15 = t4*t14; + t16 = t13*t4; + t19 = t5*t14; + t21 = theta-1.0; + t27 = pow(t1,1.0*t21); + t28 = pow(t3,1.0*t21); + t30 = theta-1.0+t2+t4-t5; + t33 = t9*t27; + out[j] = t9*(-1/t10*t11+t8*(t13+t15-t16-t19)/t6)*t27*t28*t30+t33*t12*t28*t30 + +t33*t28*t14*t30+t33*t28*(1.0+t13+t15-t16-t19); + } + + } + +} + + +//////////////////////////////////////////////////////////////////// +// +// 1. Ableitung von c nach u +// +//////////////////////////////////////////////////////////////////// + +void diffPDF_u_mod(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + double* negv; + double* negu; + double* nparam; + negv = (double *) malloc(*n*sizeof(double)); + negu = (double *) malloc(*n*sizeof(double)); + nparam = (double *) malloc(2*sizeof(double)); + int ncopula, i; + nparam[0]=-param[0]; + nparam[1]=-param[1]; + +if((*copula)==43) + { + ncopula=3; + if(param[0] > 0){ + nparam[0]=2*(param[0])/(1-param[0]); + diffPDF_u(u, v, n, nparam, &ncopula, out); + }else{ + nparam[0]=-2*(param[0])/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(u, negv, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else if((*copula)==44) + { + ncopula=4; + if(param[0] > 0){ + nparam[0]=1/(1-param[0]); + diffPDF_u(u, v, n, nparam, &ncopula, out); + }else{ + nparam[0]=1/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(u, negv, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else{ + + if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas + { + ncopula = (*copula)-20; + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(u, negv, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas + { + ncopula = (*copula)-30; + for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} + diffPDF_u(negu, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas + { + ncopula = (*copula)-10; + for (i = 0; i < *n; ++i) + { + negv[i] = 1 - v[i]; + negu[i] = 1 - u[i]; + } + diffPDF_u(negu, negv, n, param, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else + { + diffPDF_u(u, v, n, param, copula, out); + } + } + free(negv); + free(negu); + free(nparam); +} + +void diffPDF_u(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + int j, k=1; + double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t18, t19, t20, t21, t22, t23, t24, t25, t27, t28, t29; + double t30, t33, t36; + + double theta = param[0]; + //double delta = param[1]; + + for(j=0;j<*n;j++) + { + if(*copula==0) + { + out[j]=0; + } + else if(*copula==1) + { + t1 = qnorm(u[j],0.0,1.0,1,0); + t2 = qnorm(v[j],0.0,1.0,1,0); + t3 = theta*theta; + t4 = 1.0-t3; + t5 = sqrt(t4); + t6 = pow(t1,2.0); + t7 = pow(t2,2.0); + t8 = t3*(t6+t7)-(2.0*theta*t1*t2); + t9 = exp(-t8/t4/2.0); + t10 = t9/t5; + t11 = sqrt(2.0*pi); + t12 = exp(-t6/2.0); + t13 = t11/t12; + out[j] = -t10*(theta*t13/t4)*(theta*t1-t2); + } + else if(*copula==2) + { + diffPDF_u_tCopula_new(&u[j], &v[j], &k, param, copula, &out[j]); + } + else if(*copula==3) + { + t1 = 1.0+theta; + t3 = pow(u[j]*v[j],-1.0*t1); + t4 = t1*t3; + t5 = 1/u[j]; + t7 = pow(u[j],-1.0*theta); + t8 = pow(v[j],-1.0*theta); + t9 = t7+t8-1.0; + t11 = -2.0-1/theta; + t12 = pow(t9,1.0*t11); + out[j] = -t4*t1*t5*t12-t4*t12*t11*t7*theta*t5/t9; + } + else if(*copula==4) + { + t3 = log(u[j]); + t4 = pow(-t3,1.0*theta); + t5 = log(v[j]); + t6 = pow(-t5,1.0*theta); + t7 = t4+t6; + t8 = 1/theta; + t9 = pow(t7,1.0*t8); + t11 = u[j]*u[j]; + t12 = 1/t11; + t13 = 1/t3; + t15 = 1/t7; + t18 = exp(-t9); + t19 = 1/v[j]; + t21 = -1.0+t8; + t22 = pow(t7,2.0*t21); + t24 = theta-1.0; + t25 = pow(t3*t5,1.0*t24); + t27 = pow(t7,-1.0*t8); + t28 = t24*t27; + t29 = 1.0+t28; + t30 = t22*t25*t29; + t33 = t18*t12; + t36 = t19*t22; + out[j] = -t9*t4*t12*t13*t15*t18*t19*t30-t33*t19*t30+2.0*t33*t36*t21*t4*theta + *t13*t15*t25*t29+t33*t36*t25*t24*t13*t29-t33*t36*t25*t28*t4*t13*t15; + } + else if(*copula==5) + { + t1 = theta*theta; + t2 = exp(theta); + t3 = t2-1.0; + t5 = theta*v[j]; + t6 = theta*u[j]; + t8 = exp(t5+t6+theta); + t10 = exp(t5+t6); + t12 = exp(t5+theta); + t14 = exp(t6+theta); + t15 = t10-t12-t14+t2; + t16 = t15*t15; + out[j] = t1*t3*t8/t16-2.0*theta*t3*t8/t16/t15*(theta*t10-theta*t14); + } + else if(*copula==6) + { + t1 = 1.0-u[j]; + t2 = pow(t1,1.0*theta); + t3 = 1.0-v[j]; + t4 = pow(t3,1.0*theta); + t5 = t2*t4; + t6 = t2+t4-t5; + t8 = 1/theta-2.0; + t9 = pow(t6,1.0*t8); + t11 = t2*theta; + t12 = 1/t1; + t16 = -t11*t12+t11*t12*t4; + t19 = theta-1.0; + t20 = pow(t1,1.0*t19); + t22 = pow(t3,1.0*t19); + t23 = theta-1.0+t2+t4-t5; + t27 = t9*t20; + out[j] = t9*t8*t16/t6*t20*t22*t23-t27*t19*t12*t22*t23+t27*t22*t16; + } + } + +} + + +//////////////////////////////////////////////////////////////////// +// +// 1. Ableitung von c nach v +// +//////////////////////////////////////////////////////////////////// + +void diffPDF_v_mod(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + double* negv; + double* negu; + double* nparam; + negv = (double *) malloc(*n*sizeof(double)); + negu = (double *) malloc(*n*sizeof(double)); + nparam = (double *) malloc(2*sizeof(double)); + int ncopula, i; + nparam[0]=-param[0]; + nparam[1]=-param[1]; + +if((*copula)==43) + { + ncopula=3; + if(param[0] > 0){ + nparam[0]=2*(param[0])/(1-param[0]); + diffPDF_u(v, u, n, nparam, &ncopula, out); + }else{ + nparam[0]=-2*(param[0])/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(negv, u, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else if((*copula)==44) + { + ncopula=4; + if(param[0] > 0){ + nparam[0]=1/(1-param[0]); + diffPDF_u(v, u, n, nparam, &ncopula, out); + }else{ + nparam[0]=1/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(negv, u, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else{ + if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas + { + ncopula = (*copula)-20; + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(negv, u, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas + { + ncopula = (*copula)-30; + for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} + diffPDF_u(v, negu, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas + { + ncopula = (*copula)-10; + for (i = 0; i < *n; ++i) + { + negv[i] = 1 - v[i]; + negu[i] = 1 - u[i]; + } + diffPDF_u(negv, negu, n, param, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else + { + diffPDF_u(v, u, n, param, copula, out); + } + } + free(negv); + free(negu); + free(nparam); +} + Modified: pkg/src/deriv2.c =================================================================== --- pkg/src/deriv2.c 2014-03-26 15:18:51 UTC (rev 63) +++ pkg/src/deriv2.c 2014-04-22 13:49:04 UTC (rev 64) @@ -1,1341 +1,1341 @@ -/* -** deriv2.c - C code of the package CDRVine -** -** by Ulf Schepsmeier -** -** Second derivatives of c (density) -** -*/ - -#include "include/vine.h" -#include "include/likelihood.h" -#include "include/deriv.h" -#include "include/deriv2.h" -#include "include/tcopuladeriv.h" -#include "include/tcopuladeriv_new.h" - -#define UMAX 1-1e-10 - -#define UMIN 1e-10 - -#define XEPS 1e-4 - - -//////////////////////////////////////////////////////////////////// -// -// 2. Ableitung von c nach dem Parameter -// -//////////////////////////////////////////////////////////////////// - -void diff2PDF_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - double* out2; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - out2 = (double *) malloc(*n*sizeof(double)); - int ncopula, i; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - -if((*copula==43)) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diff2PDF(u, v, n, nparam, &ncopula, out); - diffPDF(u, v, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]*4/pow(1-param[0],4)+out2[i]*4/pow(1-param[0],3);} - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diff2PDF(u, negv, n, nparam, &ncopula, out); - diffPDF(u, negv, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]*4/pow(1+param[0],4)+out2[i]*4/pow(1+param[0],3);} - } - }else if((*copula==44)) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diff2PDF(u, v, n, nparam, &ncopula, out); - diffPDF(u, v, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]/pow(1-param[0],4)+out2[i]*2/pow(1-param[0],3);} - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diff2PDF(u, negv, n, nparam, &ncopula, out); - diffPDF(u, negv, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]/pow(1+param[0],4)+out2[i]*2/pow(1+param[0],3);} - } - }else{ - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90° rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diff2PDF(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270° rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diff2PDF(negu, v, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180° rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diff2PDF(negu, negv, n, param, &ncopula, out); - } - else - { - diff2PDF(u, v, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); - free(out2); -} - - -void diff2PDF(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - int j; - double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29; - double t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t47, t48, t49, t51, t53, t56, t58, t59, t60, t61, t62, t65, t66; - double t67, t70, t74, t75, t80, t87, t88; - - double theta = param[0]; - //double delta = param[1]; - - for(j=0;j<*n;j++) - { - if(*copula==0) - { - out[j]=0; - } - else if(*copula==1) - { - t6 = qnorm(u[j],0.0,1.0,1,0); - t7 = qnorm(v[j],0.0,1.0,1,0); - t1 = t6*t7; - t2 = theta*theta; - t3 = 1.0-t2; - t4 = 4.0*t3*t3; - t5 = 1/t4; - t12 = t6*t6; - t13 = t7*t7; - t14 = 2.0*theta*t6*t7-t12-t13; - t21 = t14*t5; - t26 = 1/t3/2.0; - t29 = exp(t12/2.0+t13/2.0+t14*t26); - t31 = sqrt(t3); - t32 = 1/t31; - t38 = 2.0*t1*t26+4.0*t21*theta; - t39 = t38*t38; - t44 = 1/t31/t3; - t48 = t3*t3; - out[j] = (16.0*t1*t5*theta+16.0*t14/t4/t3*t2+4.0*t21)*t29*t32+t39*t29*t32+2.0* - t38*t29*t44*theta+3.0*t29/t31/t48*t2+t29*t44; - } - else if(*copula==3) - { - t1 = u[j]*v[j]; - t2 = -theta-1.0; - t3 = pow(t1,1.0*t2); - t4 = log(t1); - t6 = pow(u[j],-1.0*theta); - t7 = pow(v[j],-1.0*theta); - t8 = t6+t7-1.0; - t10 = -2.0-1/theta; - t11 = pow(t8,1.0*t10); - t15 = theta*theta; - t16 = 1/t15; - t17 = log(t8); - t19 = log(u[j]); - t21 = log(v[j]); - t24 = -t6*t19-t7*t21; - t26 = 1/t8; - t27 = t16*t17+t10*t24*t26; - t30 = -t2*t3; - t32 = t4*t4; - t14 = t27*t27; - t13 = t19*t19; - t12 = t21*t21; - t9 = t24*t24; - t5 = t8*t8; - out[j] = -2.0*t3*t4*t11+2.0*t3*t11*t27+t30*t32*t11-2.0*t30*t4*t11*t27+t30* - t11*t14+t30*t11*(-2.0/t15/theta*t17+2.0*t16*t24*t26+t10*(t6*t13+t7*t12)*t26-t10*t9/t5); - } - else if(*copula==4) - { - t3 = log(u[j]); - t4 = pow(-t3,1.0*theta); - t5 = log(v[j]); - t6 = pow(-t5,1.0*theta); - t7 = t4+t6; - t8 = 1/theta; - t9 = pow(t7,1.0*t8); - t10 = theta*theta; - t11 = 1/t10; - t12 = log(t7); - t13 = t11*t12; - t14 = log(-t3); - t16 = log(-t5); - t18 = t4*t14+t6*t16; - t20 = 1/t7; - t22 = -t13+t8*t18*t20; - t23 = t22*t22; - t25 = exp(-t9); - t27 = t25/u[j]; - t29 = 1/v[j]; - t30 = -1.0+t8; - t31 = pow(t7,2.0*t30); - t32 = t29*t31; - t33 = t3*t5; - t34 = theta-1.0; - t35 = pow(t33,1.0*t34); - t36 = pow(t7,-1.0*t8); - t37 = t34*t36; - t38 = 1.0+t37; - t39 = t35*t38; - t40 = t32*t39; - t44 = 1/t10/theta*t12; - t47 = t11*t18*t20; - t49 = t14*t14; - t51 = t16*t16; - t53 = t4*t49+t6*t51; - t56 = t18*t18; - t58 = t7*t7; - t59 = 1/t58; - t61 = 2.0*t44-2.0*t47+t8*t53*t20-t8*t56*t59; - t65 = t9*t9; - t70 = t9*t22*t27; - t74 = -2.0*t13+2.0*t30*t18*t20; - t75 = t74*t35; - t80 = log(t33); - t87 = t36-t37*t22; - t88 = t35*t87; - t17 = t27*t29; - t15 = t74*t74; - t2 = t31*t35; - t1 = t80*t80; - out[j] = -t9*t23*t27*t40-t9*t61*t27*t40+t65*t23*t27*t40-2.0*t70*t32*t75*t38 - -2.0*t70*t32*t35*t80*t38-2.0*t70*t32*t88+t17*t31*t15*t39+t17*t31*(4.0*t44-4.0* - t47+2.0*t30*t53*t20-2.0*t30*t56*t59)*t39+2.0*t27*t32*t75*t80*t38+2.0*t17*t31* - t74*t88+t17*t2*t1*t38+2.0*t17*t2*t80*t87+t17*t2*(-2.0*t36*t22+t37*t23- - t37*t61); - - } - else if(*copula==5) - { - t1 = exp(theta); - t2 = theta*v[j]; - t3 = theta*u[j]; - t5 = exp(t2+t3+theta); - t8 = exp(t2+t3); - t10 = exp(t2+theta); - t12 = exp(t3+theta); - t13 = t8-t10-t12+t1; - t14 = t13*t13; - t15 = 1/t14; - t18 = t1-1.0; - t19 = v[j]+u[j]+1.0; - t21 = t5*t15; - t26 = 1/t14/t13; - t27 = v[j]+u[j]; - t29 = v[j]+1.0; [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/vinecopula -r 64 From noreply at r-forge.r-project.org Tue Apr 22 17:23:47 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 22 Apr 2014 17:23:47 +0200 (CEST) Subject: [Vinecopula-commits] r65 - in pkg: man tests/Examples Message-ID: <20140422152347.4E5C0186694@r-forge.r-project.org> Author: etobi Date: 2014-04-22 17:23:46 +0200 (Tue, 22 Apr 2014) New Revision: 65 Modified: pkg/man/RVineStructureSelect.Rd pkg/man/RVineTreePlot.Rd pkg/tests/Examples/VineCopula-Ex.Rout.save Log: Examples f?\195?\188r RVineStructureSelect und RVineTreePlot angepasst. Modified: pkg/man/RVineStructureSelect.Rd =================================================================== --- pkg/man/RVineStructureSelect.Rd 2014-04-22 13:49:04 UTC (rev 64) +++ pkg/man/RVineStructureSelect.Rd 2014-04-22 15:23:46 UTC (rev 65) @@ -118,9 +118,7 @@ data(daxreturns) # select the R-vine structure, families and parameters -\dontrun{ -RVM = RVineStructureSelect(daxreturns,c(1:6),progress=TRUE) -} +RVM = RVineStructureSelect(daxreturns[,1:4],c(1:6),progress=TRUE) # specify a C-vine copula model with only Clayton, Gumbel and Frank copulas \dontrun{ Modified: pkg/man/RVineTreePlot.Rd =================================================================== --- pkg/man/RVineTreePlot.Rd 2014-04-22 13:49:04 UTC (rev 64) +++ pkg/man/RVineTreePlot.Rd 2014-04-22 15:23:46 UTC (rev 65) @@ -89,6 +89,6 @@ # re-set random seed for testing set.seed(666) # plot only the first tree with new coordinates -RVineTreePlot(data=NULL,RVM=RVM,tree=1,edge.labels=FALSE,P=P) +P = RVineTreePlot(data=NULL,RVM=RVM,tree=1,edge.labels=FALSE,P=P) } Modified: pkg/tests/Examples/VineCopula-Ex.Rout.save =================================================================== --- pkg/tests/Examples/VineCopula-Ex.Rout.save 2014-04-22 13:49:04 UTC (rev 64) +++ pkg/tests/Examples/VineCopula-Ex.Rout.save 2014-04-22 15:23:46 UTC (rev 65) @@ -1,7 +1,7 @@ -R version 3.1.0 alpha (2014-03-13 r65184) -- "Unsuffered Consequences" +R version 3.0.3 (2014-03-06) -- "Warm Puppy" Copyright (C) 2014 The R Foundation for Statistical Computing -Platform: x86_64-w64-mingw32/x64 (64-bit) +Platform: i386-w64-mingw32/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -22,3355 +22,3330 @@ > options(warn = 1) > options(pager = "console") > library('VineCopula') -> -> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') -> cleanEx() -> nameEx("BB1Copula-class") -> ### * BB1Copula-class -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB1Copula-class -> ### Title: Classes '"BB1Copula"', '"surBB1Copula"', '"r90BB1Copula"' and -> ### '"r270BB1Copula"' -> ### Aliases: BB1Copula-class dduCopula,numeric,BB1Copula-method -> ### ddvCopula,numeric,BB1Copula-method dduCopula,matrix,BB1Copula-method -> ### ddvCopula,matrix,BB1Copula-method getKendallDistr,BB1Copula-method -> ### kendallDistribution,BB1Copula-method surBB1Copula-class -> ### dduCopula,numeric,surBB1Copula-method -> ### ddvCopula,numeric,surBB1Copula-method -> ### dduCopula,matrix,surBB1Copula-method -> ### ddvCopula,matrix,surBB1Copula-method r90BB1Copula-class -> ### dduCopula,numeric,r90BB1Copula-method -> ### ddvCopula,numeric,r90BB1Copula-method -> ### dduCopula,matrix,r90BB1Copula-method -> ### ddvCopula,matrix,r90BB1Copula-method r270BB1Copula-class -> ### dduCopula,numeric,r270BB1Copula-method -> ### ddvCopula,numeric,r270BB1Copula-method -> ### dduCopula,matrix,r270BB1Copula-method -> ### ddvCopula,matrix,r270BB1Copula-method -> ### Keywords: classes -> -> ### ** Examples -> -> showClass("BB1Copula") -Class "BB1Copula" [package "VineCopula"] - -Slots: - -Name: family dimension parameters param.names param.lowbnd -Class: numeric integer numeric character numeric - -Name: param.upbnd fullname -Class: numeric character - -Extends: -Class "copula", directly -Class "twoParamBiCop", directly -Class "Copula", by class "copula", distance 2 -> -> -> -> cleanEx() -> nameEx("BB1Copula") -> ### * BB1Copula -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB1Copula -> ### Title: Constructor of the BB1 family and rotated versions thereof -> ### Aliases: BB1Copula surBB1Copula r90BB1Copula r270BB1Copula -> ### Keywords: distribution copula -> -> ### ** Examples -> -> library(copula) - -Attaching package: 'copula' - -The following object is masked from 'package:VineCopula': - - fitCopula - -> -> persp(BB1Copula(c(1,1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(surBB1Copula(c(1,1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(r90BB1Copula(c(-1,-1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(r270BB1Copula(c(-1,-1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> -> -> -> cleanEx() - -detaching 'package:copula' - -> nameEx("BB6Copula-class") -> ### * BB6Copula-class -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB6Copula-class -> ### Title: Classes '"BB6Copula"', '"surBB6Copula"', '"r90BB6Copula"' and -> ### '"r270BB6Copula"' -> ### Aliases: BB6Copula-class dduCopula,numeric,BB6Copula-method -> ### ddvCopula,numeric,BB6Copula-method dduCopula,matrix,BB6Copula-method -> ### ddvCopula,matrix,BB6Copula-method getKendallDistr,BB6Copula-method -> ### kendallDistribution,BB6Copula-method surBB6Copula-class -> ### dduCopula,numeric,surBB6Copula-method -> ### ddvCopula,numeric,surBB6Copula-method -> ### dduCopula,matrix,surBB6Copula-method -> ### ddvCopula,matrix,surBB6Copula-method r90BB6Copula-class -> ### dduCopula,numeric,r90BB6Copula-method -> ### ddvCopula,numeric,r90BB6Copula-method -> ### dduCopula,matrix,r90BB6Copula-method -> ### ddvCopula,matrix,r90BB6Copula-method r270BB6Copula-class -> ### dduCopula,numeric,r270BB6Copula-method -> ### ddvCopula,numeric,r270BB6Copula-method -> ### dduCopula,matrix,r270BB6Copula-method -> ### ddvCopula,matrix,r270BB6Copula-method -> ### Keywords: classes -> -> ### ** Examples -> -> showClass("BB6Copula") -Class "BB6Copula" [package "VineCopula"] - -Slots: - -Name: family dimension parameters param.names param.lowbnd -Class: numeric integer numeric character numeric - -Name: param.upbnd fullname -Class: numeric character - -Extends: -Class "copula", directly -Class "twoParamBiCop", directly -Class "Copula", by class "copula", distance 2 -> -> -> -> cleanEx() -> nameEx("BB6Copula") -> ### * BB6Copula -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB6Copula -> ### Title: Constructor of the BB6 family and its derivatives -> ### Aliases: BB6Copula surBB6Copula r90BB6Copula r270BB6Copula -> -> ### ** Examples -> -> library(copula) - -Attaching package: 'copula' - -The following object is masked from 'package:VineCopula': - - fitCopula - -> -> persp(BB6Copula(c(1,1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(surBB6Copula(c(1,1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(r90BB6Copula(c(-1,-1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(r270BB6Copula(c(-1,-1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> -> -> -> cleanEx() - -detaching 'package:copula' - -> nameEx("BB7Copula-class") -> ### * BB7Copula-class -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB7Copula-class -> ### Title: Classes '"BB7Copula"', '"surBB7Copula"', '"r90BB7Copula"' and -> ### '"r270BB7Copula"' -> ### Aliases: BB7Copula-class dduCopula,numeric,BB7Copula-method -> ### ddvCopula,numeric,BB7Copula-method dduCopula,matrix,BB7Copula-method -> ### ddvCopula,matrix,BB7Copula-method getKendallDistr,BB7Copula-method -> ### kendallDistribution,BB7Copula-method surBB7Copula-class -> ### dduCopula,numeric,surBB7Copula-method -> ### ddvCopula,numeric,surBB7Copula-method -> ### dduCopula,matrix,surBB7Copula-method -> ### ddvCopula,matrix,surBB7Copula-method r90BB7Copula-class -> ### dduCopula,numeric,r90BB7Copula-method -> ### ddvCopula,numeric,r90BB7Copula-method -> ### dduCopula,matrix,r90BB7Copula-method -> ### ddvCopula,matrix,r90BB7Copula-method r270BB7Copula-class -> ### dduCopula,numeric,r270BB7Copula-method -> ### ddvCopula,numeric,r270BB7Copula-method -> ### dduCopula,matrix,r270BB7Copula-method -> ### ddvCopula,matrix,r270BB7Copula-method -> ### Keywords: classes -> -> ### ** Examples -> -> showClass("BB7Copula") -Class "BB7Copula" [package "VineCopula"] - -Slots: - -Name: family dimension parameters param.names param.lowbnd -Class: numeric integer numeric character numeric - -Name: param.upbnd fullname -Class: numeric character - -Extends: -Class "copula", directly -Class "twoParamBiCop", directly -Class "Copula", by class "copula", distance 2 -> -> -> -> cleanEx() -> nameEx("BB7Copula") -> ### * BB7Copula -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB7Copula -> ### Title: Constructor of the BB7 family and its derivatives -> ### Aliases: BB7Copula surBB7Copula r90BB7Copula r270BB7Copula -> -> ### ** Examples -> -> library(copula) - -Attaching package: 'copula' - -The following object is masked from 'package:VineCopula': - - fitCopula - -> -> persp(BB7Copula(c(1,1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(surBB7Copula(c(1,1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(r90BB7Copula(c(-1,-1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> persp(r270BB7Copula(c(-1,-1.5)),dCopula, zlim=c(0,10)) -Warning in persp.default(xis, yis, zmat, theta = theta, phi = phi, expand = expand, : - surface extends beyond the box -> -> -> -> cleanEx() - -detaching 'package:copula' - -> nameEx("BB8Copula-class") -> ### * BB8Copula-class -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB8Copula-class -> ### Title: Classes '"BB8Copula"', '"surBB8Copula"', '"r90BB8Copula"' and -> ### '"r270BB8Copula"' -> ### Aliases: BB8Copula-class dduCopula,numeric,BB8Copula-method -> ### ddvCopula,numeric,BB8Copula-method dduCopula,matrix,BB8Copula-method -> ### ddvCopula,matrix,BB8Copula-method getKendallDistr,BB8Copula-method -> ### kendallDistribution,BB8Copula-method surBB8Copula-class -> ### dduCopula,numeric,surBB8Copula-method -> ### ddvCopula,numeric,surBB8Copula-method -> ### dduCopula,matrix,surBB8Copula-method -> ### ddvCopula,matrix,surBB8Copula-method r90BB8Copula-class -> ### dduCopula,numeric,r90BB8Copula-method -> ### ddvCopula,numeric,r90BB8Copula-method -> ### dduCopula,matrix,r90BB8Copula-method -> ### ddvCopula,matrix,r90BB8Copula-method r270BB8Copula-class -> ### dduCopula,numeric,r270BB8Copula-method -> ### ddvCopula,numeric,r270BB8Copula-method -> ### dduCopula,matrix,r270BB8Copula-method -> ### ddvCopula,matrix,r270BB8Copula-method fitCopula,twoParamBiCop-method -> ### Keywords: classes -> -> ### ** Examples -> -> showClass("BB8Copula") -Class "BB8Copula" [package "VineCopula"] - -Slots: - -Name: family dimension parameters param.names param.lowbnd -Class: numeric integer numeric character numeric - -Name: param.upbnd fullname -Class: numeric character - -Extends: -Class "copula", directly -Class "twoParamBiCop", directly -Class "Copula", by class "copula", distance 2 -> -> -> -> cleanEx() -> nameEx("BB8Copula") -> ### * BB8Copula -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BB8Copula -> ### Title: Constructor of the BB8 family and its derivatives -> ### Aliases: BB8Copula surBB8Copula r90BB8Copula r270BB8Copula -> -> ### ** Examples -> -> library(copula) - -Attaching package: 'copula' - -The following object is masked from 'package:VineCopula': - - fitCopula - -> -> persp(BB8Copula(c(1,0.5)),dCopula, zlim=c(0,10)) -> persp(surBB8Copula(c(1,0.5)),dCopula, zlim=c(0,10)) -> persp(r90BB8Copula(c(-1,-0.5)),dCopula, zlim=c(0,10)) -> persp(r270BB8Copula(c(-1,-0.5)),dCopula, zlim=c(0,10)) -> -> -> -> cleanEx() - -detaching 'package:copula' - -> nameEx("BetaMatrix") -> ### * BetaMatrix -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BetaMatrix -> ### Title: Matrix of empirical Blomqvist's beta values -> ### Aliases: BetaMatrix -> -> ### ** Examples -> -> data(daxreturns) -> Data = as.matrix(daxreturns) -> -> # compute the empirical Blomqvist's betas -> beta = BetaMatrix(Data) -> -> -> -> cleanEx() -> nameEx("BiCopCDF") -> ### * BiCopCDF -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopCDF -> ### Title: Distribution function of a bivariate copula -> ### Aliases: BiCopCDF -> -> ### ** Examples -> -> # simulate from a bivariate Clayton -> simdata = BiCopSim(300,3,3.4) -> -> # evaluate the distribution function of the bivariate t-copula -> u1 = simdata[,1] -> u2 = simdata[,2] -> BiCopCDF(u1,u2,3,3.4) - [1] 0.212083894 0.560454175 0.196829776 0.859783373 0.334142797 0.138883599 - [7] 0.552748610 0.656946696 0.716294284 0.358902123 0.657106132 0.406649144 - [13] 0.215249319 0.010762322 0.680744432 0.429168263 0.336836485 0.754999947 - [19] 0.478876720 0.591381592 0.743614123 0.684320242 0.501994536 0.019720627 - [25] 0.673692866 0.461672664 0.318172610 0.041830170 0.272430716 0.539624409 - [31] 0.690952756 0.357404390 0.478385703 0.450454976 0.081735412 0.325850276 - [37] 0.270163818 0.464160879 0.697817469 0.770254930 0.402432651 0.309902564 - [43] 0.526755239 0.440604149 0.157859951 0.125915290 0.623294168 0.739830600 - [49] 0.371783278 0.723334913 0.516814728 0.269809505 0.445858863 0.109397786 - [55] 0.822399359 0.909295094 0.294693765 0.055312093 0.427042357 0.403252652 - [61] 0.845573559 0.325266686 0.630782109 0.357571974 0.203263111 0.321058009 - [67] 0.032144353 0.826230667 0.484706552 0.844421805 0.608301620 0.175590037 - [73] 0.609058333 0.163878464 0.101571465 0.538136460 0.274644551 0.339289595 - [79] 0.294216757 0.195381304 0.277706814 0.421733480 0.720333595 0.049782599 - [85] 0.565454106 0.606022665 0.691741950 0.371062856 0.601897391 0.591440556 - [91] 0.201688601 0.758395667 0.600742911 0.704561061 0.823026172 0.574257107 - [97] 0.099157544 0.251281107 0.106087540 0.300755602 0.189355553 0.383442247 -[103] 0.156051138 0.353445260 0.237769014 0.569868697 0.754009708 0.626534957 -[109] 0.642565610 0.746343146 0.174386590 0.276468326 0.793197597 0.128246949 -[115] 0.403133907 0.218942785 0.337329582 0.358487519 0.603040975 0.358813218 -[121] 0.270584669 0.584756888 0.291400991 0.270925282 0.453995540 0.750041775 -[127] 0.419655276 0.292947806 0.211477158 0.367187001 0.403616732 0.263279705 -[133] 0.466439291 0.060463864 0.414509798 0.037596575 0.254942295 0.205299452 -[139] 0.174436459 0.449884240 0.024025747 0.703587274 0.030608188 0.210400866 -[145] 0.093855295 0.142735752 0.761364232 0.464621321 0.061121298 0.049605515 -[151] 0.394449212 0.413216316 0.374454880 0.168265886 0.055593257 0.097151257 -[157] 0.780802798 0.227744822 0.065636001 0.870926086 0.510225526 0.405327388 -[163] 0.845888486 0.768194100 0.251842178 0.746537224 0.380903910 0.061307470 -[169] 0.290451789 0.578210814 0.667105491 0.436226140 0.501831663 0.314446545 -[175] 0.343212498 0.260100773 0.643573510 0.736279214 0.480576518 0.747377388 -[181] 0.084991510 0.625430254 0.563728676 0.065672797 0.586906305 0.383323904 -[187] 0.665138618 0.182143650 0.322690699 0.150906032 0.377309335 0.652937289 -[193] 0.167981587 0.764145834 0.112547545 0.094783549 0.792890037 0.121846529 -[199] 0.506278225 0.227685925 0.449045336 0.931289729 0.876824814 0.350126804 -[205] 0.010994635 0.786543245 0.709228011 0.596225473 0.378512582 0.664875538 -[211] 0.373815801 0.426252115 0.280636713 0.083968169 0.814257670 0.515317294 -[217] 0.328967379 0.099903254 0.377995332 0.473178827 0.031442176 0.447588371 -[223] 0.217327056 0.361663573 0.067611532 0.801212727 0.247607998 0.049270220 -[229] 0.576458572 0.324353916 0.136902467 0.001605048 0.257187329 0.474040408 -[235] 0.437713533 0.456113202 0.577646467 0.085121494 0.715134572 0.457893436 -[241] 0.498003300 0.838971972 0.503169431 0.045336633 0.555881808 0.022418980 -[247] 0.194331580 0.334462487 0.373599846 0.438035879 0.509068595 0.599445606 -[253] 0.468924572 0.387566042 0.655708457 0.735283578 0.007562104 0.489784093 -[259] 0.562107349 0.302752252 0.766853423 0.218580395 0.381560134 0.755457200 -[265] 0.955922687 0.272025101 0.251443038 0.057390884 0.289182961 0.155876041 -[271] 0.393765386 0.507388247 0.120671623 0.799010545 0.523637750 0.767031675 -[277] 0.010792082 0.619446682 0.047529687 0.786968380 0.413820169 0.318351521 -[283] 0.835610923 0.218595381 0.278001748 0.129935495 0.147382642 0.715055153 -[289] 0.544744934 0.786205589 0.344101052 0.302395620 0.488473797 0.066509090 -[295] 0.889908357 0.401278597 0.705956499 0.752430964 0.408975709 0.316904963 -> -> -> -> cleanEx() -> nameEx("BiCopChiPlot") -> ### * BiCopChiPlot -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopChiPlot -> ### Title: Chi-plot for bivariate copula data -> ### Aliases: BiCopChiPlot -> -> ### ** Examples -> -> ## Not run: -> ##D # chi-plots for bivariate Gaussian copula data -> ##D n = 500 -> ##D tau = 0.5 -> ##D -> ##D # simulate copula data -> ##D fam = 1 -> ##D theta = BiCopTau2Par(fam,tau) -> ##D dat = BiCopSim(n,fam,theta) -> ##D -> ##D # create chi-plots -> ##D dev.new(width=16,height=5) -> ##D par(mfrow=c(1,3)) -> ##D BiCopChiPlot(dat[,1],dat[,2],xlim=c(-1,1),ylim=c(-1,1), -> ##D main="General chi-plot") -> ##D BiCopChiPlot(dat[,1],dat[,2],mode="lower",xlim=c(-1,1), -> ##D ylim=c(-1,1),main="Lower chi-plot") -> ##D BiCopChiPlot(dat[,1],dat[,2],mode="upper",xlim=c(-1,1), -> ##D ylim=c(-1,1),main="Upper chi-plot") -> ## End(Not run) -> -> -> -> cleanEx() -> nameEx("BiCopDeriv") -> ### * BiCopDeriv -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopDeriv -> ### Title: Derivatives of a bivariate copula density -> ### Aliases: BiCopDeriv -> -> ### ** Examples -> -> # simulate from a bivariate t-copula -> simdata = BiCopSim(300,2,-0.7,par2=4) -> -> # derivative of the bivariate t-copula with respect to the first parameter -> u1 = simdata[,1] -> u2 = simdata[,2] -> BiCopDeriv(u1,u2,2,-0.7,par2=4, deriv="par") - [1] -1.118981963 1.240853696 -1.001064211 0.126342186 1.175103086 - [6] 1.125284074 -2.660900650 -2.472195467 1.023015475 -1.226835099 - [11] -10.758312703 -0.060805698 -1.275771122 -0.874257992 -5.229438212 - [16] -1.996785307 -0.024314703 -0.340297829 -1.124279340 -2.830928257 - [21] -0.644128690 -1.902583339 -0.198026426 -5.534636646 -0.399781564 - [26] 0.435400718 -0.424885018 1.472901008 -2.384264853 -2.524411180 - [31] -7.785438426 -1.363561693 -1.835639592 -0.722528253 -6.472291697 - [36] -0.716665042 -0.964105867 0.829886233 -4.540361690 1.351436336 - [41] -1.503828622 -1.074008721 -2.420782826 -0.457655215 1.239990732 - [46] 1.451559193 1.125103668 0.869236569 -1.879796413 -1.231228404 - [51] -2.424107089 1.829094173 -1.221019510 -2.559081446 -1.233727812 - [56] 1.872628051 -1.838289517 0.971594798 -0.096706898 -1.937842204 - [61] -15.237257119 0.172804942 -2.778179365 -0.368238987 -3.191034202 - [66] 1.081925107 -13.105195405 -1.253692526 -2.123195334 -8.688276102 - [71] -1.503515318 0.256531438 -2.674138975 -4.198369584 -5.259632795 - [76] -1.944954160 -1.969911957 0.006893071 1.207272916 0.571959168 - [81] -0.132434126 -0.754275953 -4.565334109 0.127084068 -2.903169549 - [86] 0.771316852 -4.357864429 0.489405734 -0.218840978 1.257765042 - [91] 0.720810321 -3.023537238 -5.465362366 0.055533560 -2.703654480 - [96] -2.809374993 -2.368171453 -2.796443300 -5.602431270 -1.693541846 -[101] 0.551536277 -1.064635971 -2.851261121 0.383686061 -2.937039105 -[106] -13.728663798 1.428865348 -4.156683579 1.475522589 -11.428897046 -[111] 1.042581628 -2.329817184 -3.371593709 1.422863380 0.041637025 -[116] 1.087794501 -2.304816570 -1.944080252 -1.899435223 -2.039960766 -[121] -2.645050409 -6.650555229 0.050104775 0.851039002 1.383789144 -[126] 1.465850488 -2.014890698 0.938868515 -2.392303876 1.122254766 -[131] -1.525108901 -2.071212850 -1.173020644 -10.741866594 -0.542828355 -[136] 1.515200988 0.630401901 0.694797858 0.931185696 -0.680191222 -[141] -7.933722404 -5.163276704 1.664827305 0.960737875 1.063045879 -[146] 1.342918851 -25.249465414 -1.393407553 1.532198588 -6.911077681 -[151] 0.376116964 -2.132593253 1.552339321 -3.505820153 -1.224401790 -[156] 1.227776973 0.353972461 -2.323316239 -0.313598837 -0.566267188 -[161] -2.330830899 1.274204534 1.293889346 0.860444774 -2.469578460 -[166] -37.208160647 -0.658022946 -0.468399340 0.542603267 1.471761927 -[171] -62.570186831 -2.007473905 -2.147550775 0.259715654 -1.822814641 -[176] 1.381625780 -3.213788742 -28.991603753 -1.229075644 -3.627148879 -[181] -0.101623278 -4.587179691 0.581309497 -9.140049046 -2.507966161 -[186] -2.212019166 -9.855455970 -1.589138378 -0.337898112 -2.553649116 -[191] -2.226506883 1.333901700 0.465082093 1.189110937 0.796068401 -[196] 1.443132908 -3.501076181 -0.501800492 -2.291129850 0.935368493 -[201] -1.064749466 1.467016724 1.082767823 -1.259347011 -35.328425259 -[206] -54.951284051 0.718174055 -2.464860924 -1.312713214 0.813159659 -[211] -2.210898561 -0.448716041 -1.620526551 -2.795506995 1.473304529 -[216] -5.057278714 -2.325488643 -6.612891371 1.047891665 1.184335554 -[221] 1.067936715 -1.893917726 -1.660850454 1.235448817 1.395848509 -[226] -8.352631627 0.661067847 -10.045949778 1.301830099 1.184362514 -[231] -2.365111887 -19.375622882 0.787353636 -1.284525224 -1.465763628 -[236] 1.487875678 -2.800629638 0.974747012 -3.893986259 -1.347791384 -[241] -1.715161311 1.344923130 -2.191660590 0.729214728 -4.251170941 -[246] -15.846996489 0.963319101 -2.045913223 -2.214253517 0.123732841 -[251] -1.130187683 -0.976720057 1.550396563 -0.114614937 -2.106725798 -[256] -3.543205014 -64.153096610 -1.674467836 -2.013424285 -2.506361843 -[261] 0.171864835 1.109748552 1.058702426 0.607026838 0.841762192 -[266] 1.600486017 -0.341279447 1.218882366 -1.075804146 -3.976274166 -[271] 1.462331510 -2.327053523 1.443964144 -70.883566817 -0.662165420 -[276] -1.690102935 -50.916636504 -3.285496238 1.214680711 1.243536650 -[281] -0.209042356 -1.987493543 0.412999360 -3.236351739 1.359980628 -[286] -1.527350949 1.444523027 -2.321816594 -2.549388281 0.552707478 -[291] 1.307238920 1.553288676 -2.277551572 -4.393119872 1.180012547 -[296] -1.006935254 -0.716277972 -0.594563456 -2.172846043 -1.984262894 -> -> -> -> cleanEx() -> nameEx("BiCopDeriv2") -> ### * BiCopDeriv2 -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopDeriv2 -> ### Title: Second derivatives of a bivariate copula density -> ### Aliases: BiCopDeriv2 -> -> ### ** Examples -> -> # simulate from a bivariate t-copula -> simdata = BiCopSim(300,2,-0.7,par2=4) -> -> # second derivative of the bivariate t-copula with respect to the first parameter -> u1 = simdata[,1] -> u2 = simdata[,2] -> BiCopDeriv2(u1,u2,2,-0.7,par2=4, deriv="par") - [1] 2.4126542 -6.6825108 -6.3560370 -13.7227857 -9.1816929 - [6] -7.0908205 13.7290309 10.7473379 1.2577657 2.6630769 - [11] 45.1413216 -5.6405356 3.4557714 -38.1175487 23.8842516 - [16] 10.4429381 -3.4900896 -4.0350153 -5.2822373 14.4093322 - [21] -2.3705610 6.3865847 -2.3729617 -8.3403632 -1.7953292 - [26] -5.9126744 -0.8925703 -2.7198451 12.1687196 13.2898122 - [31] 34.8767633 5.5283219 6.8140897 0.5179240 12.8722339 - [36] -1.9694262 2.3857559 -7.1967954 19.9757800 -0.8634186 - [41] 5.8194993 3.3938077 7.1423000 -5.1528390 -6.5129152 - [46] -2.6078043 -6.5350832 -6.9423348 9.5969194 1.2028442 - [51] 12.2097919 -5.3415160 2.3088684 6.2549771 -6.3055972 - [56] -20.6839367 8.6985442 1.8900924 -7.2938766 9.6259884 - [61] -15.8136161 -4.4191251 13.3567417 -1.6699869 15.6181921 - [66] -8.2228638 49.6433734 -6.8637577 11.5149595 -10.1757433 - [71] 5.7891358 -5.1789980 13.2930910 17.9367741 11.1038423 - [76] 9.7799834 9.3298570 -3.7109533 -7.6361988 -5.8621277 - [81] -7.0977482 0.3699164 18.6443999 -12.3991863 14.2560643 - [86] -6.1678671 19.3905631 -7.4826160 -2.0968065 -6.4709585 - [91] -6.1599241 7.7973748 19.3468978 -4.3365165 -3.1372378 - [96] 14.3722621 -12.2920083 14.3064742 16.3602446 4.6174577 -[101] -5.8752261 2.9774240 11.4235543 -6.1721458 13.0711948 -[106] 24.5566247 -2.0566903 19.3946357 -3.4040873 46.5514372 -[111] -6.6975421 11.8752549 4.8264870 -1.9410271 -4.8470163 -[116] -6.5319545 11.8388787 8.7842751 8.5351932 10.8108849 -[121] 13.7383533 17.5443858 -3.4835638 -6.5227577 -7.3817498 -[126] -3.1497797 10.5288361 -7.0505394 10.7116425 -9.1255948 -[131] 6.4561544 6.1147706 -0.1415321 47.2160109 -2.1404643 -[136] -3.2675803 -5.8061782 -6.0783318 -6.6882969 0.2205718 -[141] 9.2056534 22.6513172 -5.4130890 -6.4797445 -8.6119575 -[146] -6.1626208 99.0525948 5.6320135 -4.5034060 -10.8423355 -[151] -8.2161180 11.7010068 -3.1354411 10.6979666 -7.4363695 -[156] -7.9862145 -7.0399481 10.7286487 -9.0056350 -19.8533850 -[161] 10.9014112 -0.7675042 -0.2967231 -7.3862615 9.1439497 -[166] 155.9358951 -1.0080337 -9.1237377 -5.7171014 -2.9464925 -[171] 269.9285276 10.3593989 8.7543815 -4.7214883 7.2427847 -[176] -6.7186224 15.3700517 124.6436795 -9.6978141 11.7143732 -[181] -7.6979536 20.5984504 -5.7257439 40.5312907 12.7734411 -[186] 12.0655708 42.4723521 4.4524000 -4.4733160 9.1906767 -[191] 12.1270553 -0.8568985 -5.9649734 -7.0021920 -23.9452815 -[196] -6.2800218 5.3513165 -3.9053336 10.6781184 -6.4459971 -[201] 0.4934674 -2.4424125 -13.7947217 2.6918629 -15.0437654 -[206] 179.5492436 -6.4095059 12.3367635 5.0010992 -6.3084576 -[211] 12.1575256 -3.7222823 6.9552673 -14.7678286 -5.2660209 -[216] -11.0043502 12.5483203 25.2705550 -12.1320323 -7.5170928 -[221] -16.7607915 9.6529562 5.9831467 -9.2588542 -1.5943981 -[226] 19.2252029 -5.8827620 41.3950758 -0.7504865 -8.7125535 -[231] 7.1471377 -182.3423219 -11.5964015 0.1386318 5.9833540 -[236] -6.7067508 14.3516973 -9.2066813 15.6816459 5.2243435 -[241] 1.1197675 -0.8486390 11.8796392 2.1755199 7.3798075 -[246] -19.7251148 -6.5430234 10.6690874 12.1767844 -16.2087793 -[251] 3.8184437 2.4339272 -5.1251428 -4.2674313 8.5722830 -[256] 12.3852346 276.5338339 3.0855253 9.9835689 12.7594328 -[261] -6.1429545 -6.5277846 -8.7959204 -6.8613633 3.2834040 -[266] -6.8909722 -1.5026474 0.2997642 3.2883771 18.6179306 -[271] -8.1021536 11.2468036 -5.3373429 195.6539596 0.6054940 -[276] 0.9947356 122.5599083 16.1741216 0.2079989 -7.1625500 -[281] -4.9097796 7.9203020 -10.0926920 15.9586637 -11.5061335 -[286] 1.7095188 -4.9261936 7.3923584 13.3974394 -7.5603040 -[291] -9.6068616 -8.6709300 12.2354089 11.2373337 -17.6110050 -[296] 2.1594059 -0.8513871 -2.9233828 12.0301834 10.0336656 -> -> -> -> cleanEx() -> nameEx("BiCopEst") -> ### * BiCopEst -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopEst -> ### Title: Parameter estimation for bivariate copula data using inversion -> ### of Kendall's tau or maximum likelihood estimation -> ### Aliases: BiCopEst -> -> ### ** Examples -> -> ## Example 1: bivariate Gaussian copula -> dat = BiCopSim(500,1,0.7) -> u1 = dat[,1] -> v1 = dat[,2] -> -> # empirical Kendall's tau -> tau1 = cor(u1,v1,method="kendall") -> -> # inversion of empirical Kendall's tau -> BiCopTau2Par(1,tau1) -[1] 0.7045111 -> BiCopEst(u1,v1,family=1,method="itau")$par -[1] 0.7045111 -> -> # maximum likelihood estimate for comparison -> BiCopEst(u1,v1,family=1,method="mle")$par -[1] 0.703239 -> -> -> ## Example 2: bivariate Clayton and survival Gumbel copulas -> # simulate from a Clayton copula -> dat = BiCopSim(500,3,2.5) -> u2 = dat[,1] -> v2 = dat[,2] -> -> # empirical Kendall's tau -> tau2 = cor(u2,v2,method="kendall") -> -> # inversion of empirical Kendall's tau for the Clayton copula -> BiCopTau2Par(3,tau2) -[1] 2.480802 -> BiCopEst(u2,v2,family=3,method="itau",se=TRUE) -$par -[1] 2.480802 - -$par2 -[1] 0 - -$se -[1] 0.2366735 - -$se2 -[1] 0 - -> -> # inversion of empirical Kendall's tau for the survival Gumbel copula -> BiCopTau2Par(14,tau2) -[1] 2.240401 -> BiCopEst(u2,v2,family=14,method="itau",se=TRUE) -$par -[1] 2.240401 - -$par2 -[1] 0 - -$se -[1] 0.1183367 - -$se2 -[1] 0 - -> -> # maximum likelihood estimates for comparison -> BiCopEst(u2,v2,family=3,method="mle",se=TRUE) -$par -[1] 2.370793 - -$par2 -[1] 0 - -$se -[1] 0.1337379 - -$se2 -[1] 0 - -> BiCopEst(u2,v2,family=14,method="mle",se=TRUE) -$par -[1] 2.244569 - -$par2 -[1] 0 - -$se -[1] 0.08094233 - -$se2 -[1] 0 - -> -> -> -> -> cleanEx() -> nameEx("BiCopGofTest") -> ### * BiCopGofTest -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopGofTest -> ### Title: Goodness-of-fit test for bivariate copulas -> ### Aliases: BiCopGofTest -> -> ### ** Examples -> -> # simulate from a bivariate Clayton copula -> simdata = BiCopSim(300,3,2) -> u1 = simdata[,1] -> u2 = simdata[,2] -> -> # perform White's goodness-of-fit test for the true copula -> BiCopGofTest(u1,u2,family=3) -$p.value - [,1] -[1,] 0.174567 - -$statistic - [,1] -[1,] 1.84328 - -> -> # perform Kendall's goodness-of-fit test for the Frank copula -> BiCopGofTest(u1,u2,family=5) -$p.value - [,1] -[1,] 0.499615 - -$statistic - [,1] -[1,] 0.4557542 - -> -> ## Not run: -> ##D # perform Kendall's goodness-of-fit test for the true copula -> ##D gof = BiCopGofTest(u1,u2,family=3,method="kendall") -> ##D gof$p.value.CvM -> ##D gof$p.value.KS -> ##D -> ##D # perform Kendall's goodness-of-fit test for the Frank copula -> ##D gof = BiCopGofTest(u1,u2,family=5,method="kendall") -> ##D gof$p.value.CvM -> ##D gof$p.value.KS -> ## End(Not run) -> -> -> -> cleanEx() -> nameEx("BiCopHfunc") -> ### * BiCopHfunc -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopHfunc -> ### Title: Conditional distribution function (h-function) of a bivariate -> ### copula -> ### Aliases: BiCopHfunc -> -> ### ** Examples -> -> # load data set -> data(daxreturns) -> -> # h-functions of the Gaussian copula -> h1 = BiCopHfunc(daxreturns[,2],daxreturns[,1],1,0.5) -> -> -> -> cleanEx() -> nameEx("BiCopHfuncDeriv") -> ### * BiCopHfuncDeriv -> -> flush(stderr()); flush(stdout()) -> -> ### Name: BiCopHfuncDeriv -> ### Title: Derivatives of the h-function of a bivariate copula -> ### Aliases: BiCopHfuncDeriv -> -> ### ** Examples -> -> # simulate from a bivariate t-copula -> simdata = BiCopSim(300,2,-0.7,par2=4) -> -> # derivative of the conditional bivariate t-copula -> # with respect to the first parameter -> u1 = simdata[,1] -> u2 = simdata[,2] -> BiCopHfuncDeriv(u1,u2,2,-0.7,par2=4, deriv="par") - [1] 0.188249864 -0.529552481 -0.873071979 -0.088028377 0.764465081 - [6] 0.268742673 0.225414839 0.003745044 -0.250411287 -0.552223280 - [11] 0.542208002 0.733893277 0.171342121 0.040807295 0.271432180 - [16] -0.194478681 0.539020302 -0.179847959 0.857056553 0.165863800 - [21] -0.167799319 -0.078433467 -0.493630542 0.014446390 -0.259425789 - [26] -0.611885828 0.430828031 0.081037733 -0.034159823 0.180985090 - [31] 0.348575968 0.309101636 0.490238920 -0.491592260 -0.833857762 - [36] -0.683462885 0.269070347 -0.635325777 0.174910232 -0.232964155 - [41] -0.415391436 0.301526190 0.625251401 0.781396939 0.315011241 - [46] 0.272627317 -0.447754453 -0.281985372 0.171307540 -0.133608127 - [51] 0.291907921 -0.739724153 0.574547234 0.027070515 -0.078697407 - [56] -0.055992298 0.122430683 0.125977620 0.815021190 -0.275509931 - [61] 0.002381546 0.545961005 0.080450266 0.523905668 -0.172254706 - [66] 0.701785048 -0.172723789 -0.075921055 -0.050254540 -0.004517698 - [71] -0.168177303 0.276160659 0.085267141 -0.493157648 -0.803393801 [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/vinecopula -r 65 From noreply at r-forge.r-project.org Tue Apr 22 18:55:08 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 22 Apr 2014 18:55:08 +0200 (CEST) Subject: [Vinecopula-commits] r66 - in pkg: man src tests tests/Examples Message-ID: <20140422165508.BB6711872A4@r-forge.r-project.org> Author: ulf Date: 2014-04-22 18:55:08 +0200 (Tue, 22 Apr 2014) New Revision: 66 Modified: pkg/man/RVineStructureSelect.Rd pkg/src/deriv.c pkg/src/deriv2.c pkg/src/hfunc.c pkg/src/hfuncderiv.c pkg/src/hfuncderiv2.c pkg/src/likelihood.c pkg/tests/Examples/VineCopula-Ex.Rout.save pkg/tests/additonalExampleRuns.Rout.save Log: in diesem Setting l?\195?\164uft bei mir der check ohne Probleme durch (unter R.3.0.2) Modified: pkg/man/RVineStructureSelect.Rd =================================================================== --- pkg/man/RVineStructureSelect.Rd 2014-04-22 15:23:46 UTC (rev 65) +++ pkg/man/RVineStructureSelect.Rd 2014-04-22 16:55:08 UTC (rev 66) @@ -118,7 +118,9 @@ data(daxreturns) # select the R-vine structure, families and parameters -RVM = RVineStructureSelect(daxreturns[,1:4],c(1:6),progress=TRUE) +# using only the first 4 variables and the first 750 observations +# we allow for the copula families: Gauss, t, Clayton, Gumbel, Frank and Joe +RVM = RVineStructureSelect(daxreturns[1:750,1:4],c(1:6),progress=TRUE) # specify a C-vine copula model with only Clayton, Gumbel and Frank copulas \dontrun{ Modified: pkg/src/deriv.c =================================================================== --- pkg/src/deriv.c 2014-04-22 15:23:46 UTC (rev 65) +++ pkg/src/deriv.c 2014-04-22 16:55:08 UTC (rev 66) @@ -1,513 +1,513 @@ -/* -** deriv.c - C code of the package CDRVine -** -** by Ulf Schepsmeier -** -** -** -*/ - -#include "include/vine.h" -#include "include/deriv.h" -#include "include/tcopuladeriv.h" -#include "include/tcopuladeriv_new.h" - -#define UMAX 1-1e-10 - -#define UMIN 1e-10 - -#define XEPS 1e-4 - - - -///////////////////////////////////////////////////////////// -// -// Ableitung der Copula nach dem Parameter -// -///////////////////////////////////////////////////////////// - -void diffPDF_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - int ncopula; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - int i; - -if((*copula)==43) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diffPDF(u, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=out[i]*2/pow(1-param[0],2);} - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF(u, negv, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i]*2/pow(1+param[0],2); } - } - }else if((*copula)==44) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diffPDF(u, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=out[i]/pow(1-param[0],2);} - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF(u, negv, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i]/pow(1+param[0],2); } - } - }else{ - - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF(u, negv, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diffPDF(negu, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diffPDF(negu, negv, n, param, &ncopula, out); - } - else - { - diffPDF(u, v, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); -} - - - - -void diffPDF(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - int j; - double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t24, t26, t27, t28, t29, t30, t32, t33, t34, t35, t36; - t3=0; - t4=0; - - double theta = param[0]; - //double delta = param[1]; - - for(j=0;j<*n;j++) - { - if(*copula==0) - { - out[j]=0; - } - else if(*copula==1) - { - t1 = qnorm(u[j],0.0,1.0,1,0); - t2 = qnorm(v[j],0.0,1.0,1,0); - t4 = t1*t1; - t5 = t2*t2; - t3 = t4+t5; - t7 = theta*theta; - t8 = 1.0-t7; - t9 = 1/t8/2.0; - t15 = t7*t3-2.0*theta*t1*t2; - t22 = exp(-t15*t9); - t24 = sqrt(t8); - out[j] = (-2.0*(theta*t3-t1*t2)*t9-t15/(t8*t8)*theta)*t22/t24+t22/t24/t8*theta; - } - else if(*copula==3) - { - t1 = u[j]*v[j]; - t2 = -theta-1.0; - t3 = pow(t1,1.0*t2); - t4 = pow(u[j],-1.0*theta); - t5 = pow(v[j],-1.0*theta); - t6 = t4+t5-1.0; - t7 = -2.0-1/theta; - t8 = pow(t6,1.0*t7); - t9 = -t2*t3; - t10 = log(t1); - t11 = theta*theta; - t12 = log(t6); - t13 = log(u[j]); - t14 = log(v[j]); - out[j] = t3*t8-t9*t10*t8+t9*t8*(1/t11*t12+t7*(-t4*t13-t5*t14)/t6); - } - else if(*copula==4) - { - t3 = log(u[j]); - t4 = pow(-t3,1.0*theta); - t5 = log(v[j]); - t6 = pow(-t5,1.0*theta); - t7 = t4+t6; - t8 = 1/theta; - t9 = pow(t7,1.0*t8); - t10 = theta*theta; - t12 = log(t7); - t13 = 1/t10*t12; - t14 = log(-t3); - t16 = log(-t5); - t18 = t4*t14+t6*t16; - t20 = 1/t7; - t22 = -t13+t8*t18*t20; - t24 = exp(-t9); - t26 = t24/u[j]; - t28 = 1/v[j]; - t29 = -1.0+t8; - t30 = pow(t7,2.0*t29); - t32 = t3*t5; - t33 = theta-1.0; - t34 = pow(t32,1.0*t33); - t35 = pow(t7,-1.0*t8); - t36 = t33*t35; - t17 = 1.0+t36; - t15 = t34*t17; - t11 = t26*t28; - t2 = t30*t34; - t1 = log(t32); - out[j] = -t9*t22*t26*t28*t30*t15+t11*t30*(-2.0*t13+2.0*t29*t18*t20)*t15+t11* - t2*t1*t17+t11*t2*(t35-t36*t22); - - } - else if(*copula==5) - { - t2 = exp(theta); - t3 = t2-1.0; - t4 = theta*v[j]; - t5 = theta*u[j]; - t7 = exp(t4+t5+theta); - t10 = exp(t4+t5); - t12 = exp(t4+theta); - t14 = exp(t5+theta); - t15 = t10-t12-t14+t2; - t16 = t15*t15; - t17 = 1/t16; - t21 = theta*t3; - out[j] = t3*t7*t17+theta*t2*t7*t17+t21*(v[j]+u[j]+1.0)*t7*t17-2.0*t21*t7/t15/t16*((v[j]+u[j])*t10-(v[j]+1.0)*t12-(u[j]+1.0)*t14+t2); - } - else if(*copula==6) - { - t1 = 1.0-u[j]; - t2 = pow(t1,1.0*theta); - t3 = 1.0-v[j]; - t4 = pow(t3,1.0*theta); - t5 = t2*t4; - t6 = t2+t4-t5; - t8 = 1/theta-2.0; - t9 = pow(t6,1.0*t8); - t10 = theta*theta; - t11 = log(t6); - t12 = log(t1); - t13 = t2*t12; - t14 = log(t3); - t15 = t4*t14; - t16 = t13*t4; - t19 = t5*t14; - t21 = theta-1.0; - t27 = pow(t1,1.0*t21); - t28 = pow(t3,1.0*t21); - t30 = theta-1.0+t2+t4-t5; - t33 = t9*t27; - out[j] = t9*(-1/t10*t11+t8*(t13+t15-t16-t19)/t6)*t27*t28*t30+t33*t12*t28*t30 - +t33*t28*t14*t30+t33*t28*(1.0+t13+t15-t16-t19); - } - - } - -} - - -//////////////////////////////////////////////////////////////////// -// -// 1. Ableitung von c nach u -// -//////////////////////////////////////////////////////////////////// - -void diffPDF_u_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - int ncopula, i; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - -if((*copula)==43) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diffPDF_u(u, v, n, nparam, &ncopula, out); - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else if((*copula)==44) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diffPDF_u(u, v, n, nparam, &ncopula, out); - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else{ - - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diffPDF_u(negu, v, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diffPDF_u(negu, negv, n, param, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else - { - diffPDF_u(u, v, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); -} - -void diffPDF_u(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - int j, k=1; - double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t18, t19, t20, t21, t22, t23, t24, t25, t27, t28, t29; - double t30, t33, t36; - - double theta = param[0]; - //double delta = param[1]; - - for(j=0;j<*n;j++) - { - if(*copula==0) - { - out[j]=0; - } - else if(*copula==1) - { - t1 = qnorm(u[j],0.0,1.0,1,0); - t2 = qnorm(v[j],0.0,1.0,1,0); - t3 = theta*theta; - t4 = 1.0-t3; - t5 = sqrt(t4); - t6 = pow(t1,2.0); - t7 = pow(t2,2.0); - t8 = t3*(t6+t7)-(2.0*theta*t1*t2); - t9 = exp(-t8/t4/2.0); - t10 = t9/t5; - t11 = sqrt(2.0*pi); - t12 = exp(-t6/2.0); - t13 = t11/t12; - out[j] = -t10*(theta*t13/t4)*(theta*t1-t2); - } - else if(*copula==2) - { - diffPDF_u_tCopula_new(&u[j], &v[j], &k, param, copula, &out[j]); - } - else if(*copula==3) - { - t1 = 1.0+theta; - t3 = pow(u[j]*v[j],-1.0*t1); - t4 = t1*t3; - t5 = 1/u[j]; - t7 = pow(u[j],-1.0*theta); - t8 = pow(v[j],-1.0*theta); - t9 = t7+t8-1.0; - t11 = -2.0-1/theta; - t12 = pow(t9,1.0*t11); - out[j] = -t4*t1*t5*t12-t4*t12*t11*t7*theta*t5/t9; - } - else if(*copula==4) - { - t3 = log(u[j]); - t4 = pow(-t3,1.0*theta); - t5 = log(v[j]); - t6 = pow(-t5,1.0*theta); - t7 = t4+t6; - t8 = 1/theta; - t9 = pow(t7,1.0*t8); - t11 = u[j]*u[j]; - t12 = 1/t11; - t13 = 1/t3; - t15 = 1/t7; - t18 = exp(-t9); - t19 = 1/v[j]; - t21 = -1.0+t8; - t22 = pow(t7,2.0*t21); - t24 = theta-1.0; - t25 = pow(t3*t5,1.0*t24); - t27 = pow(t7,-1.0*t8); - t28 = t24*t27; - t29 = 1.0+t28; - t30 = t22*t25*t29; - t33 = t18*t12; - t36 = t19*t22; - out[j] = -t9*t4*t12*t13*t15*t18*t19*t30-t33*t19*t30+2.0*t33*t36*t21*t4*theta - *t13*t15*t25*t29+t33*t36*t25*t24*t13*t29-t33*t36*t25*t28*t4*t13*t15; - } - else if(*copula==5) - { - t1 = theta*theta; - t2 = exp(theta); - t3 = t2-1.0; - t5 = theta*v[j]; - t6 = theta*u[j]; - t8 = exp(t5+t6+theta); - t10 = exp(t5+t6); - t12 = exp(t5+theta); - t14 = exp(t6+theta); - t15 = t10-t12-t14+t2; - t16 = t15*t15; - out[j] = t1*t3*t8/t16-2.0*theta*t3*t8/t16/t15*(theta*t10-theta*t14); - } - else if(*copula==6) - { - t1 = 1.0-u[j]; - t2 = pow(t1,1.0*theta); - t3 = 1.0-v[j]; - t4 = pow(t3,1.0*theta); - t5 = t2*t4; - t6 = t2+t4-t5; - t8 = 1/theta-2.0; - t9 = pow(t6,1.0*t8); - t11 = t2*theta; - t12 = 1/t1; - t16 = -t11*t12+t11*t12*t4; - t19 = theta-1.0; - t20 = pow(t1,1.0*t19); - t22 = pow(t3,1.0*t19); - t23 = theta-1.0+t2+t4-t5; - t27 = t9*t20; - out[j] = t9*t8*t16/t6*t20*t22*t23-t27*t19*t12*t22*t23+t27*t22*t16; - } - } - -} - - -//////////////////////////////////////////////////////////////////// -// -// 1. Ableitung von c nach v -// -//////////////////////////////////////////////////////////////////// - -void diffPDF_v_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - int ncopula, i; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - -if((*copula)==43) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diffPDF_u(v, u, n, nparam, &ncopula, out); - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(negv, u, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else if((*copula)==44) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diffPDF_u(v, u, n, nparam, &ncopula, out); - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(negv, u, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - }else{ - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diffPDF_u(negv, u, n, nparam, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diffPDF_u(v, negu, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diffPDF_u(negv, negu, n, param, &ncopula, out); - for(i=0;i<*n;i++){out[i]=-out[i];} - } - else - { - diffPDF_u(v, u, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); -} - +/* +** deriv.c - C code of the package CDRVine +** +** by Ulf Schepsmeier +** +** +** +*/ + +#include "include/vine.h" +#include "include/deriv.h" +#include "include/tcopuladeriv.h" +#include "include/tcopuladeriv_new.h" + +#define UMAX 1-1e-10 + +#define UMIN 1e-10 + +#define XEPS 1e-4 + + + +///////////////////////////////////////////////////////////// +// +// Ableitung der Copula nach dem Parameter +// +///////////////////////////////////////////////////////////// + +void diffPDF_mod(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + double* negv; + double* negu; + double* nparam; + negv = (double *) malloc(*n*sizeof(double)); + negu = (double *) malloc(*n*sizeof(double)); + nparam = (double *) malloc(2*sizeof(double)); + int ncopula; + nparam[0]=-param[0]; + nparam[1]=-param[1]; + int i; + +if((*copula)==43) + { + ncopula=3; + if(param[0] > 0){ + nparam[0]=2*(param[0])/(1-param[0]); + diffPDF(u, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=out[i]*2/pow(1-param[0],2);} + }else{ + nparam[0]=-2*(param[0])/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF(u, negv, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i]*2/pow(1+param[0],2); } + } + }else if((*copula)==44) + { + ncopula=4; + if(param[0] > 0){ + nparam[0]=1/(1-param[0]); + diffPDF(u, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=out[i]/pow(1-param[0],2);} + }else{ + nparam[0]=1/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF(u, negv, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i]/pow(1+param[0],2); } + } + }else{ + + if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas + { + ncopula = (*copula)-20; + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF(u, negv, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas + { + ncopula = (*copula)-30; + for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} + diffPDF(negu, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas + { + ncopula = (*copula)-10; + for (i = 0; i < *n; ++i) + { + negv[i] = 1 - v[i]; + negu[i] = 1 - u[i]; + } + diffPDF(negu, negv, n, param, &ncopula, out); + } + else + { + diffPDF(u, v, n, param, copula, out); + } + } + free(negv); + free(negu); + free(nparam); +} + + + + +void diffPDF(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + int j; + double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t24, t26, t27, t28, t29, t30, t32, t33, t34, t35, t36; + t3=0; + t4=0; + + double theta = param[0]; + //double delta = param[1]; + + for(j=0;j<*n;j++) + { + if(*copula==0) + { + out[j]=0; + } + else if(*copula==1) + { + t1 = qnorm(u[j],0.0,1.0,1,0); + t2 = qnorm(v[j],0.0,1.0,1,0); + t4 = t1*t1; + t5 = t2*t2; + t3 = t4+t5; + t7 = theta*theta; + t8 = 1.0-t7; + t9 = 1/t8/2.0; + t15 = t7*t3-2.0*theta*t1*t2; + t22 = exp(-t15*t9); + t24 = sqrt(t8); + out[j] = (-2.0*(theta*t3-t1*t2)*t9-t15/(t8*t8)*theta)*t22/t24+t22/t24/t8*theta; + } + else if(*copula==3) + { + t1 = u[j]*v[j]; + t2 = -theta-1.0; + t3 = pow(t1,1.0*t2); + t4 = pow(u[j],-1.0*theta); + t5 = pow(v[j],-1.0*theta); + t6 = t4+t5-1.0; + t7 = -2.0-1/theta; + t8 = pow(t6,1.0*t7); + t9 = -t2*t3; + t10 = log(t1); + t11 = theta*theta; + t12 = log(t6); + t13 = log(u[j]); + t14 = log(v[j]); + out[j] = t3*t8-t9*t10*t8+t9*t8*(1/t11*t12+t7*(-t4*t13-t5*t14)/t6); + } + else if(*copula==4) + { + t3 = log(u[j]); + t4 = pow(-t3,1.0*theta); + t5 = log(v[j]); + t6 = pow(-t5,1.0*theta); + t7 = t4+t6; + t8 = 1/theta; + t9 = pow(t7,1.0*t8); + t10 = theta*theta; + t12 = log(t7); + t13 = 1/t10*t12; + t14 = log(-t3); + t16 = log(-t5); + t18 = t4*t14+t6*t16; + t20 = 1/t7; + t22 = -t13+t8*t18*t20; + t24 = exp(-t9); + t26 = t24/u[j]; + t28 = 1/v[j]; + t29 = -1.0+t8; + t30 = pow(t7,2.0*t29); + t32 = t3*t5; + t33 = theta-1.0; + t34 = pow(t32,1.0*t33); + t35 = pow(t7,-1.0*t8); + t36 = t33*t35; + t17 = 1.0+t36; + t15 = t34*t17; + t11 = t26*t28; + t2 = t30*t34; + t1 = log(t32); + out[j] = -t9*t22*t26*t28*t30*t15+t11*t30*(-2.0*t13+2.0*t29*t18*t20)*t15+t11* + t2*t1*t17+t11*t2*(t35-t36*t22); + + } + else if(*copula==5) + { + t2 = exp(theta); + t3 = t2-1.0; + t4 = theta*v[j]; + t5 = theta*u[j]; + t7 = exp(t4+t5+theta); + t10 = exp(t4+t5); + t12 = exp(t4+theta); + t14 = exp(t5+theta); + t15 = t10-t12-t14+t2; + t16 = t15*t15; + t17 = 1/t16; + t21 = theta*t3; + out[j] = t3*t7*t17+theta*t2*t7*t17+t21*(v[j]+u[j]+1.0)*t7*t17-2.0*t21*t7/t15/t16*((v[j]+u[j])*t10-(v[j]+1.0)*t12-(u[j]+1.0)*t14+t2); + } + else if(*copula==6) + { + t1 = 1.0-u[j]; + t2 = pow(t1,1.0*theta); + t3 = 1.0-v[j]; + t4 = pow(t3,1.0*theta); + t5 = t2*t4; + t6 = t2+t4-t5; + t8 = 1/theta-2.0; + t9 = pow(t6,1.0*t8); + t10 = theta*theta; + t11 = log(t6); + t12 = log(t1); + t13 = t2*t12; + t14 = log(t3); + t15 = t4*t14; + t16 = t13*t4; + t19 = t5*t14; + t21 = theta-1.0; + t27 = pow(t1,1.0*t21); + t28 = pow(t3,1.0*t21); + t30 = theta-1.0+t2+t4-t5; + t33 = t9*t27; + out[j] = t9*(-1/t10*t11+t8*(t13+t15-t16-t19)/t6)*t27*t28*t30+t33*t12*t28*t30 + +t33*t28*t14*t30+t33*t28*(1.0+t13+t15-t16-t19); + } + + } + +} + + +//////////////////////////////////////////////////////////////////// +// +// 1. Ableitung von c nach u +// +//////////////////////////////////////////////////////////////////// + +void diffPDF_u_mod(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + double* negv; + double* negu; + double* nparam; + negv = (double *) malloc(*n*sizeof(double)); + negu = (double *) malloc(*n*sizeof(double)); + nparam = (double *) malloc(2*sizeof(double)); + int ncopula, i; + nparam[0]=-param[0]; + nparam[1]=-param[1]; + +if((*copula)==43) + { + ncopula=3; + if(param[0] > 0){ + nparam[0]=2*(param[0])/(1-param[0]); + diffPDF_u(u, v, n, nparam, &ncopula, out); + }else{ + nparam[0]=-2*(param[0])/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(u, negv, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else if((*copula)==44) + { + ncopula=4; + if(param[0] > 0){ + nparam[0]=1/(1-param[0]); + diffPDF_u(u, v, n, nparam, &ncopula, out); + }else{ + nparam[0]=1/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(u, negv, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else{ + + if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas + { + ncopula = (*copula)-20; + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(u, negv, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas + { + ncopula = (*copula)-30; + for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} + diffPDF_u(negu, v, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas + { + ncopula = (*copula)-10; + for (i = 0; i < *n; ++i) + { + negv[i] = 1 - v[i]; + negu[i] = 1 - u[i]; + } + diffPDF_u(negu, negv, n, param, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else + { + diffPDF_u(u, v, n, param, copula, out); + } + } + free(negv); + free(negu); + free(nparam); +} + +void diffPDF_u(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + int j, k=1; + double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t18, t19, t20, t21, t22, t23, t24, t25, t27, t28, t29; + double t30, t33, t36; + + double theta = param[0]; + //double delta = param[1]; + + for(j=0;j<*n;j++) + { + if(*copula==0) + { + out[j]=0; + } + else if(*copula==1) + { + t1 = qnorm(u[j],0.0,1.0,1,0); + t2 = qnorm(v[j],0.0,1.0,1,0); + t3 = theta*theta; + t4 = 1.0-t3; + t5 = sqrt(t4); + t6 = pow(t1,2.0); + t7 = pow(t2,2.0); + t8 = t3*(t6+t7)-(2.0*theta*t1*t2); + t9 = exp(-t8/t4/2.0); + t10 = t9/t5; + t11 = sqrt(2.0*pi); + t12 = exp(-t6/2.0); + t13 = t11/t12; + out[j] = -t10*(theta*t13/t4)*(theta*t1-t2); + } + else if(*copula==2) + { + diffPDF_u_tCopula_new(&u[j], &v[j], &k, param, copula, &out[j]); + } + else if(*copula==3) + { + t1 = 1.0+theta; + t3 = pow(u[j]*v[j],-1.0*t1); + t4 = t1*t3; + t5 = 1/u[j]; + t7 = pow(u[j],-1.0*theta); + t8 = pow(v[j],-1.0*theta); + t9 = t7+t8-1.0; + t11 = -2.0-1/theta; + t12 = pow(t9,1.0*t11); + out[j] = -t4*t1*t5*t12-t4*t12*t11*t7*theta*t5/t9; + } + else if(*copula==4) + { + t3 = log(u[j]); + t4 = pow(-t3,1.0*theta); + t5 = log(v[j]); + t6 = pow(-t5,1.0*theta); + t7 = t4+t6; + t8 = 1/theta; + t9 = pow(t7,1.0*t8); + t11 = u[j]*u[j]; + t12 = 1/t11; + t13 = 1/t3; + t15 = 1/t7; + t18 = exp(-t9); + t19 = 1/v[j]; + t21 = -1.0+t8; + t22 = pow(t7,2.0*t21); + t24 = theta-1.0; + t25 = pow(t3*t5,1.0*t24); + t27 = pow(t7,-1.0*t8); + t28 = t24*t27; + t29 = 1.0+t28; + t30 = t22*t25*t29; + t33 = t18*t12; + t36 = t19*t22; + out[j] = -t9*t4*t12*t13*t15*t18*t19*t30-t33*t19*t30+2.0*t33*t36*t21*t4*theta + *t13*t15*t25*t29+t33*t36*t25*t24*t13*t29-t33*t36*t25*t28*t4*t13*t15; + } + else if(*copula==5) + { + t1 = theta*theta; + t2 = exp(theta); + t3 = t2-1.0; + t5 = theta*v[j]; + t6 = theta*u[j]; + t8 = exp(t5+t6+theta); + t10 = exp(t5+t6); + t12 = exp(t5+theta); + t14 = exp(t6+theta); + t15 = t10-t12-t14+t2; + t16 = t15*t15; + out[j] = t1*t3*t8/t16-2.0*theta*t3*t8/t16/t15*(theta*t10-theta*t14); + } + else if(*copula==6) + { + t1 = 1.0-u[j]; + t2 = pow(t1,1.0*theta); + t3 = 1.0-v[j]; + t4 = pow(t3,1.0*theta); + t5 = t2*t4; + t6 = t2+t4-t5; + t8 = 1/theta-2.0; + t9 = pow(t6,1.0*t8); + t11 = t2*theta; + t12 = 1/t1; + t16 = -t11*t12+t11*t12*t4; + t19 = theta-1.0; + t20 = pow(t1,1.0*t19); + t22 = pow(t3,1.0*t19); + t23 = theta-1.0+t2+t4-t5; + t27 = t9*t20; + out[j] = t9*t8*t16/t6*t20*t22*t23-t27*t19*t12*t22*t23+t27*t22*t16; + } + } + +} + + +//////////////////////////////////////////////////////////////////// +// +// 1. Ableitung von c nach v +// +//////////////////////////////////////////////////////////////////// + +void diffPDF_v_mod(double* u, double* v, int* n, double* param, int* copula, double* out) +{ + double* negv; + double* negu; + double* nparam; + negv = (double *) malloc(*n*sizeof(double)); + negu = (double *) malloc(*n*sizeof(double)); + nparam = (double *) malloc(2*sizeof(double)); + int ncopula, i; + nparam[0]=-param[0]; + nparam[1]=-param[1]; + +if((*copula)==43) + { + ncopula=3; + if(param[0] > 0){ + nparam[0]=2*(param[0])/(1-param[0]); + diffPDF_u(v, u, n, nparam, &ncopula, out); + }else{ + nparam[0]=-2*(param[0])/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(negv, u, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else if((*copula)==44) + { + ncopula=4; + if(param[0] > 0){ + nparam[0]=1/(1-param[0]); + diffPDF_u(v, u, n, nparam, &ncopula, out); + }else{ + nparam[0]=1/(1+param[0]); + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(negv, u, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + }else{ + if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas + { + ncopula = (*copula)-20; + for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} + diffPDF_u(negv, u, n, nparam, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas + { + ncopula = (*copula)-30; + for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} + diffPDF_u(v, negu, n, nparam, &ncopula, out); + //for(i=0;i<*n;i++){out[i]=-out[i];} + } + else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas + { + ncopula = (*copula)-10; + for (i = 0; i < *n; ++i) + { + negv[i] = 1 - v[i]; + negu[i] = 1 - u[i]; + } + diffPDF_u(negv, negu, n, param, &ncopula, out); + for(i=0;i<*n;i++){out[i]=-out[i];} + } + else + { + diffPDF_u(v, u, n, param, copula, out); + } + } + free(negv); + free(negu); + free(nparam); +} + Modified: pkg/src/deriv2.c =================================================================== --- pkg/src/deriv2.c 2014-04-22 15:23:46 UTC (rev 65) +++ pkg/src/deriv2.c 2014-04-22 16:55:08 UTC (rev 66) @@ -1,1341 +1,1341 @@ -/* -** deriv2.c - C code of the package CDRVine -** -** by Ulf Schepsmeier -** -** Second derivatives of c (density) -** -*/ - -#include "include/vine.h" -#include "include/likelihood.h" -#include "include/deriv.h" -#include "include/deriv2.h" -#include "include/tcopuladeriv.h" -#include "include/tcopuladeriv_new.h" - -#define UMAX 1-1e-10 - -#define UMIN 1e-10 - -#define XEPS 1e-4 - - -//////////////////////////////////////////////////////////////////// -// -// 2. Ableitung von c nach dem Parameter -// -//////////////////////////////////////////////////////////////////// - -void diff2PDF_mod(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - double* negv; - double* negu; - double* nparam; - double* out2; - negv = (double *) malloc(*n*sizeof(double)); - negu = (double *) malloc(*n*sizeof(double)); - nparam = (double *) malloc(2*sizeof(double)); - out2 = (double *) malloc(*n*sizeof(double)); - int ncopula, i; - nparam[0]=-param[0]; - nparam[1]=-param[1]; - -if((*copula)==43) - { - ncopula=3; - if(param[0] > 0){ - nparam[0]=2*(param[0])/(1-param[0]); - diff2PDF(u, v, n, nparam, &ncopula, out); - diffPDF(u, v, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]*4/pow(1-param[0],4)+out2[i]*4/pow(1-param[0],3);} - }else{ - nparam[0]=-2*(param[0])/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diff2PDF(u, negv, n, nparam, &ncopula, out); - diffPDF(u, negv, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]*4/pow(1+param[0],4)+out2[i]*4/pow(1+param[0],3);} - } - }else if((*copula)==44) - { - ncopula=4; - if(param[0] > 0){ - nparam[0]=1/(1-param[0]); - diff2PDF(u, v, n, nparam, &ncopula, out); - diffPDF(u, v, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]/pow(1-param[0],4)+out2[i]*2/pow(1-param[0],3);} - }else{ - nparam[0]=1/(1+param[0]); - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diff2PDF(u, negv, n, nparam, &ncopula, out); - diffPDF(u, negv, n, nparam, &ncopula, out2); - for(i=0;i<*n;i++){out[i]=out[i]/pow(1+param[0],4)+out2[i]*2/pow(1+param[0],3);} - } - }else{ - if(((*copula==23) | (*copula==24) | (*copula==26) | (*copula==27) | (*copula==28) | (*copula==29) | (*copula==30))) // 90? rotated copulas - { - ncopula = (*copula)-20; - for (i = 0; i < *n; ++i) {negv[i] = 1 - v[i];} - diff2PDF(u, negv, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==33) | (*copula==34) | (*copula==36) | (*copula==37) | (*copula==38) | (*copula==39) | (*copula==40))) // 270? rotated copulas - { - ncopula = (*copula)-30; - for (i = 0; i < *n; ++i) {negu[i] = 1 - u[i];} - diff2PDF(negu, v, n, nparam, &ncopula, out); - //for(i=0;i<*n;i++){out[i]=-out[i];} - } - else if(((*copula==13) | (*copula==14) | (*copula==16) | (*copula==17) | (*copula==18) | (*copula==19) | (*copula==20))) // 180? rotated copulas - { - ncopula = (*copula)-10; - for (i = 0; i < *n; ++i) - { - negv[i] = 1 - v[i]; - negu[i] = 1 - u[i]; - } - diff2PDF(negu, negv, n, param, &ncopula, out); - } - else - { - diff2PDF(u, v, n, param, copula, out); - } - } - free(negv); - free(negu); - free(nparam); - free(out2); -} - - -void diff2PDF(double* u, double* v, int* n, double* param, int* copula, double* out) -{ - int j; - double t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29; - double t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t47, t48, t49, t51, t53, t56, t58, t59, t60, t61, t62, t65, t66; - double t67, t70, t74, t75, t80, t87, t88; - - double theta = param[0]; - //double delta = param[1]; - - for(j=0;j<*n;j++) - { - if(*copula==0) - { - out[j]=0; - } - else if(*copula==1) - { - t6 = qnorm(u[j],0.0,1.0,1,0); - t7 = qnorm(v[j],0.0,1.0,1,0); - t1 = t6*t7; - t2 = theta*theta; - t3 = 1.0-t2; - t4 = 4.0*t3*t3; - t5 = 1/t4; - t12 = t6*t6; - t13 = t7*t7; - t14 = 2.0*theta*t6*t7-t12-t13; - t21 = t14*t5; - t26 = 1/t3/2.0; - t29 = exp(t12/2.0+t13/2.0+t14*t26); - t31 = sqrt(t3); - t32 = 1/t31; - t38 = 2.0*t1*t26+4.0*t21*theta; - t39 = t38*t38; - t44 = 1/t31/t3; - t48 = t3*t3; - out[j] = (16.0*t1*t5*theta+16.0*t14/t4/t3*t2+4.0*t21)*t29*t32+t39*t29*t32+2.0* - t38*t29*t44*theta+3.0*t29/t31/t48*t2+t29*t44; - } - else if(*copula==3) - { - t1 = u[j]*v[j]; - t2 = -theta-1.0; - t3 = pow(t1,1.0*t2); - t4 = log(t1); - t6 = pow(u[j],-1.0*theta); - t7 = pow(v[j],-1.0*theta); - t8 = t6+t7-1.0; - t10 = -2.0-1/theta; - t11 = pow(t8,1.0*t10); - t15 = theta*theta; - t16 = 1/t15; - t17 = log(t8); - t19 = log(u[j]); - t21 = log(v[j]); - t24 = -t6*t19-t7*t21; - t26 = 1/t8; - t27 = t16*t17+t10*t24*t26; - t30 = -t2*t3; - t32 = t4*t4; - t14 = t27*t27; - t13 = t19*t19; - t12 = t21*t21; - t9 = t24*t24; - t5 = t8*t8; - out[j] = -2.0*t3*t4*t11+2.0*t3*t11*t27+t30*t32*t11-2.0*t30*t4*t11*t27+t30* - t11*t14+t30*t11*(-2.0/t15/theta*t17+2.0*t16*t24*t26+t10*(t6*t13+t7*t12)*t26-t10*t9/t5); - } - else if(*copula==4) - { - t3 = log(u[j]); - t4 = pow(-t3,1.0*theta); - t5 = log(v[j]); - t6 = pow(-t5,1.0*theta); - t7 = t4+t6; - t8 = 1/theta; - t9 = pow(t7,1.0*t8); - t10 = theta*theta; - t11 = 1/t10; - t12 = log(t7); - t13 = t11*t12; - t14 = log(-t3); - t16 = log(-t5); - t18 = t4*t14+t6*t16; - t20 = 1/t7; - t22 = -t13+t8*t18*t20; - t23 = t22*t22; - t25 = exp(-t9); - t27 = t25/u[j]; - t29 = 1/v[j]; - t30 = -1.0+t8; - t31 = pow(t7,2.0*t30); - t32 = t29*t31; - t33 = t3*t5; - t34 = theta-1.0; - t35 = pow(t33,1.0*t34); - t36 = pow(t7,-1.0*t8); - t37 = t34*t36; - t38 = 1.0+t37; - t39 = t35*t38; - t40 = t32*t39; - t44 = 1/t10/theta*t12; - t47 = t11*t18*t20; - t49 = t14*t14; - t51 = t16*t16; - t53 = t4*t49+t6*t51; - t56 = t18*t18; - t58 = t7*t7; - t59 = 1/t58; - t61 = 2.0*t44-2.0*t47+t8*t53*t20-t8*t56*t59; - t65 = t9*t9; - t70 = t9*t22*t27; - t74 = -2.0*t13+2.0*t30*t18*t20; - t75 = t74*t35; - t80 = log(t33); - t87 = t36-t37*t22; - t88 = t35*t87; - t17 = t27*t29; - t15 = t74*t74; - t2 = t31*t35; [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/vinecopula -r 66