From noreply at r-forge.r-project.org Wed Sep 10 11:42:58 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 10 Sep 2014 11:42:58 +0200 (CEST) Subject: [Vinecopula-commits] r67 - in pkg: . R inst man src Message-ID: <20140910094258.85C0B1855E9@r-forge.r-project.org> Author: ulf Date: 2014-09-10 11:42:57 +0200 (Wed, 10 Sep 2014) New Revision: 67 Modified: pkg/DESCRIPTION pkg/R/gof_White.r pkg/inst/ChangeLog pkg/man/VineCopula-package.Rd pkg/src/gof.c Log: Bug fix for the bootstrapped p-values in RVineGofTest (see ChangeLog) Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2014-04-22 16:55:08 UTC (rev 66) +++ pkg/DESCRIPTION 2014-09-10 09:42:57 UTC (rev 67) @@ -1,8 +1,8 @@ Package: VineCopula Type: Package Title: Statistical inference of vine copulas -Version: 1.3 -Date: 2014-03-26 +Version: 1.3-1 +Date: 2014-09-10 Author: Ulf Schepsmeier, Jakob Stoeber, Eike Christian Brechmann, Benedikt Graeler Maintainer: Tobias Erhardt Depends: R (>= 2.11.0) Modified: pkg/R/gof_White.r =================================================================== --- pkg/R/gof_White.r 2014-04-22 16:55:08 UTC (rev 66) +++ pkg/R/gof_White.r 2014-09-10 09:42:57 UTC (rev 67) @@ -63,6 +63,8 @@ pvalue=0 for(i in 1:B) { + D=rep(0,(dd+tt)*(dd+tt+1)/2) + V0=matrix(0,(dd+tt)*(dd+tt+1)/2,(dd+tt)*(dd+tt+1)/2) f=sample(T) out <- .C("White", as.integer(T), @@ -80,7 +82,7 @@ PACKAGE = 'VineCopula') D=out[[11]] - V0=V0=matrix(out[[12]],(dd+tt)*(dd+tt+1)/2,(dd+tt)*(dd+tt+1)/2) + V0=matrix(out[[12]],(dd+tt)*(dd+tt+1)/2,(dd+tt)*(dd+tt+1)/2) handle2=try(solve(V0,D), TRUE) if(is.null(dim(handle2))) handle2=ginv(V0)%*%D Modified: pkg/inst/ChangeLog =================================================================== --- pkg/inst/ChangeLog 2014-04-22 16:55:08 UTC (rev 66) +++ pkg/inst/ChangeLog 2014-09-10 09:42:57 UTC (rev 67) @@ -4,6 +4,15 @@ Former authors: Eike Brechmann and Jakob Stoeber Maintainer: Tobias Erhardt + +Version 1.3-1 (September 10, 2014) + +- Bug fix: + * Bootstrap procedure for the White test (RVineGofTest, gof_White) was incorrect. (Reported by Piotr Zuraniewski and Daniel Worm. Thanks!) + * Bootstrap procedure for the PIT based and the ECP based test were incorrect. + First, C starts to count at 0 not 1. This could result in zero entries in the bootstrapped data matrix. + Second, forget to permute vdirect and vindirect according to the permutation of data. + Version 1.3 (March 26, 2014) - Maintainer changed from Ulf Schepsmeier to Tobias Erhardt (tobias.erhardt at tum.de) Modified: pkg/man/VineCopula-package.Rd =================================================================== --- pkg/man/VineCopula-package.Rd 2014-04-22 16:55:08 UTC (rev 66) +++ pkg/man/VineCopula-package.Rd 2014-09-10 09:42:57 UTC (rev 67) @@ -80,17 +80,18 @@ \tabular{ll}{ Package: \tab VineCopula\cr Type: \tab Package\cr -Version: \tab 1.2\cr -Date: \tab 2013-11-11\cr +Version: \tab 1.3-1\cr +Date: \tab 2013-09-10\cr License: \tab GPL (>=2)\cr -Depends: \tab R (\eqn{\geq 2.11.0}{>= 2.11.0}), MASS, mvtnorm, igraph \cr +Depends: \tab R (\eqn{\geq 2.11.0}{>= 2.11.0}) +Imports: MASS, mvtnorm, igraph, methods, copula \cr Suggests: \tab CDVine, TSP, ADGofTest \cr LazyLoad: \tab yes } } \author{ -Ulf Schepsmeier, Jakob Stoeber, Eike Christian Brechmann, Benedikt Graeler +Ulf Schepsmeier, Jakob Stoeber, Eike Christian Brechmann, Benedikt Graeler } \references{ Modified: pkg/src/gof.c =================================================================== --- pkg/src/gof.c 2014-04-22 16:55:08 UTC (rev 66) +++ pkg/src/gof.c 2014-09-10 09:42:57 UTC (rev 67) @@ -1,667 +1,689 @@ -#include "include/vine.h" -#include "include/memoryhandling.h" -#include "include/gof.h" -#include "include/rvinederiv2.h" -#include "include/pit.h" -#include "include/rvine.h" - -///////////////////////////////////////////////////////////////////// -// Code form Daniel Berg, R-package copulaGOF -// AD: Anderson-Darling GOF test -// (Cumulative distribution function test) -// INPUT: -// cdf CDF for which to compute the test -// n Length of cdf -///////////////////////////////////////////////////////////////////// -void ADtest(double* cdf, int* n, double* out) -{ - int j; - double sum=0.0; - for(j=0;j<*n;j++) sum += (2.0*((double)j+1.0)-1.0)*(log(cdf[j])+log(1.0-cdf[*n-1-j])); - *out = -(double)*n-(1.0/(double)*n)*sum; -} - - -/////////////////////////////////////////////////////////////////////////////// -// Code form Daniel Berg, R-package copulaGOF -// Function to compute cumulative distribution function of a uniform vector x ($\hat F(x)$) -/////////////////////////////////////////////////////////////////////////////// -void CumDist(double* x, int* i_n, int* i_m, double* out) -{ - int i,j,n,m; - double *y; - n=*i_n; m=*i_m; - y = malloc(m*sizeof(double)); - for(i=0;imaxdist) maxdist = tmp; - } - *out = sqrt((double)*n)*maxdist; -} - - - -//////////////////////////////////////////////////////// -// Goodness-of-fit test based on White's information equality -// by U. Schepsmeier -/////////////////////////////////////////////////////////// - -void White(int* T, int* d, int* family, int* maxmat, int* matrix, int* condirect, int* conindirect, double* par, double* par2, double* data, double* D, double* V) -{ - int i=0, dd=0, tt=0, k=1, j=0, kk=0, t=0, mm=0, dd2=0; - double *Dprime, *hess, *subhess, *der, *subder, *dat, *hess_red, *der_red; - - for(i=0; i<(*d*(*d));i++) - { - if(family[i]!=0) dd++; - if(family[i]==2) tt++; - } - mm=(dd+tt)*(dd+tt+1)/2; - dd2=*d*(*d-1)/2; - - //Allocate memory - //V = create_matrix((dd+tt)*(dd+tt+1)/2,(dd+tt)*(dd+tt+1)/2); - //D = malloc((dd+tt)*(dd+tt+1)/2*sizeof(double)); - Dprime = malloc((dd+tt)*(dd+tt+1)/2*sizeof(double)); - hess = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); - subhess = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); - der = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); - subder = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); - hess_red = malloc((dd+tt)*(dd+tt)*sizeof(double)); - der_red = malloc((dd+tt)*(dd+tt)*sizeof(double)); - dat = malloc(*d*sizeof(double)); - - // initialisieren - for(i=0;i=*statistic) - *pvalue+=1.0/(*B); - } - - free(f); - free(bdata); -} - - - -/* Equal probability sampling; with-replacement case */ - -void MySample(int *k, int *n, int *y) -{ - int i; - - GetRNGstate(); - for (i = 0; i < *k; i++) - { - y[i] = (int) *n * unif_rand() + 1; - } - PutRNGstate(); -} - - -//////////////////////////////////////////////////////////////// - -// gof-test based on empirical copula process - -void gofECP(int* T, int* d, int* family, int* maxmat, int* matrix, int* conindirect, double* par, double* par2, double* data, double* statistic, int* statisticName) -{ - double *znull, *Chat1, *Chat2, U=0; - int T2=1000, i=0, t=0, takeU=0; - znull = malloc(*d*1000*sizeof(double)); - Chat1 = malloc(*T*sizeof(double)); - Chat2 = malloc(*T*sizeof(double)); - - for(t=0;t=*statistic) - *pvalue+=1.0/(*B); - } - - free(f); - free(bdata); -} - - -// n = dim(u)[1] -// m = dim(data)[1] -// Chat vector of length n - -void ChatZj(double* data, double* u, int* n, int* d, int* m, double* Chat) -{ - int i,j,k; - double *helpvar; - helpvar=malloc(*m*sizeof(double)); - - for(j=0;j<*n;j++) - { - Chat[j]=0; - for(k=0;k<*m;k++) - { - helpvar[k]=0; - for(i=0;i<*d;i++) - { - if(data[k+1+(*m*i)-1]<=u[j+1+(*n*i)-1]) - helpvar[k]++; - } - if(helpvar[k]==*d) - Chat[j]++; - } - Chat[j]/=(*m+1); - } - - free(helpvar); -} - -void C_ind(double* data, int* n, int* d, double* C) -{ - int t=0, i=0; - - for(t=0;t<*n;t++) - { - for(i=0;i<*d;i++) - { - if(i==0) - C[t]=data[t+1+(*n*i)-1]; - else - C[t]=C[t] * data[t+1+(*n*i)-1]; - } - - } -} - - - -void gofECP2(int* T, int* d, int* family, int* maxmat, int* matrix, int* condirect, int* conindirect, double* par, double* par2, double* data, - double* vv, double* vv2, int* calcupdate, double* statistic, int* statisticName) -{ - double *udata, *Chat1, *Chat2; - int i=0, t=0; - udata = malloc(*d*(*T)*sizeof(double)); - Chat1 = malloc(*T*sizeof(double)); - Chat2 = malloc(*T*sizeof(double)); - - for(t=0;t<*T;t++) - { - for(i=0;i<*d;i++) - { - udata[t+1+(*T*i)-1]=0; - } - } - for(t=0;t<*T;t++) - { - Chat1[t]=0; - Chat2[t]=1; - } - - RvinePIT(T, d, family, maxmat, matrix, condirect, conindirect, par, par2, data, udata, vv, vv2, calcupdate); - ChatZj(udata, udata, T, d, T, Chat1); - - C_ind(udata,T,d,Chat2); - - *statistic=0; - if(*statisticName==3) //Cramer-von Mises test statistic - { - for(i=0;i<*T;i++) - { - *statistic+=pow(Chat1[i]-Chat2[i],2); - } - } - else if(*statisticName==2) // KS - { - for(i=0;i<*T;i++) - { - *statistic=MAX(fabs(Chat1[i]-Chat2[i]),*statistic); - } - *statistic=*statistic*sqrt(*T); - } - - free(udata); - free(Chat1); - free(Chat2); -} - -void gofECP2_pvalue(int* T, int* d, int* family, int* maxmat, int* matrix, int* condirect, int* conindirect, double* par, double* par2, double* data, - double* vv, double* vv2, int* calcupdate, double* statistic, double* pvalue, int* statisticName, int* B) -{ - int i=0, m=0, t=0, *f; - double *bdata, bstat=0; - - f = malloc(*T*sizeof(int)); - bdata = malloc(*d*(*T)*sizeof(double)); - //Rprintf("%f\n",*statistic); - for(m=0;m<*B;m++) - { - MySample(T, T, f); - for(t=0;t<*T;t++) - { - for(i=0;i<*d;i++) - { - bdata[(t+1)+(*T*i)-1]=data[(f[t]+1)+(*T*i)-1]; - } - } - bstat=0; - gofECP2(T, d, family, maxmat, matrix, condirect, conindirect, par, par2, bdata, vv, vv2, calcupdate, &bstat, statisticName); - //Rprintf("%f ",bstat); - if(bstat>=*statistic) - *pvalue+=1.0/(*B); - } - - free(f); - free(bdata); -} +#include "include/vine.h" +#include "include/memoryhandling.h" +#include "include/gof.h" +#include "include/rvinederiv2.h" +#include "include/pit.h" +#include "include/rvine.h" + +///////////////////////////////////////////////////////////////////// +// Code form Daniel Berg, R-package copulaGOF +// AD: Anderson-Darling GOF test +// (Cumulative distribution function test) +// INPUT: +// cdf CDF for which to compute the test +// n Length of cdf +///////////////////////////////////////////////////////////////////// +void ADtest(double* cdf, int* n, double* out) +{ + int j; + double sum=0.0; + for(j=0;j<*n;j++) sum += (2.0*((double)j+1.0)-1.0)*(log(cdf[j])+log(1.0-cdf[*n-1-j])); + *out = -(double)*n-(1.0/(double)*n)*sum; +} + + +/////////////////////////////////////////////////////////////////////////////// +// Code form Daniel Berg, R-package copulaGOF +// Function to compute cumulative distribution function of a uniform vector x ($\hat F(x)$) +/////////////////////////////////////////////////////////////////////////////// +void CumDist(double* x, int* i_n, int* i_m, double* out) +{ + int i,j,n,m; + double *y; + n=*i_n; m=*i_m; + y = malloc(m*sizeof(double)); + for(i=0;imaxdist) maxdist = tmp; + } + *out = sqrt((double)*n)*maxdist; +} + + + +//////////////////////////////////////////////////////// +// Goodness-of-fit test based on White's information equality +// by U. Schepsmeier +/////////////////////////////////////////////////////////// + +void White(int* T, int* d, int* family, int* maxmat, int* matrix, int* condirect, int* conindirect, double* par, double* par2, double* data, double* D, double* V) +{ + int i=0, dd=0, tt=0, k=1, j=0, kk=0, t=0, mm=0, dd2=0; + double *Dprime, *hess, *subhess, *der, *subder, *dat, *hess_red, *der_red; + + for(i=0; i<(*d*(*d));i++) + { + if(family[i]!=0) dd++; + if(family[i]==2) tt++; + } + mm=(dd+tt)*(dd+tt+1)/2; + dd2=*d*(*d-1)/2; + + //Allocate memory + //V = create_matrix((dd+tt)*(dd+tt+1)/2,(dd+tt)*(dd+tt+1)/2); + //D = malloc((dd+tt)*(dd+tt+1)/2*sizeof(double)); + Dprime = malloc((dd+tt)*(dd+tt+1)/2*sizeof(double)); + hess = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); + subhess = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); + der = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); + subder = malloc((dd2+tt)*(dd2+tt)*sizeof(double)); + hess_red = malloc((dd+tt)*(dd+tt)*sizeof(double)); + der_red = malloc((dd+tt)*(dd+tt)*sizeof(double)); + dat = malloc(*d*sizeof(double)); + + // initialisieren + for(i=0;i=*statistic) + *pvalue+=1.0/(*B); + } + + free(f); + free(bdata); + free(bvv); + free(bvv2); +} + + + +/* Equal probability sampling; with-replacement case */ + +void MySample(int *k, int *n, int *y) +{ + int i; + + GetRNGstate(); + for (i = 0; i < *k; i++) + { + y[i] = (int) *n * unif_rand() + 1; + } + PutRNGstate(); +} + + +//////////////////////////////////////////////////////////////// + +// gof-test based on empirical copula process + +void gofECP(int* T, int* d, int* family, int* maxmat, int* matrix, int* conindirect, double* par, double* par2, double* data, double* statistic, int* statisticName) +{ + double *znull, *Chat1, *Chat2, U=0; + int T2=1000, i=0, t=0, takeU=0; + znull = malloc(*d*1000*sizeof(double)); + Chat1 = malloc(*T*sizeof(double)); + Chat2 = malloc(*T*sizeof(double)); + + for(t=0;t=*statistic) + *pvalue+=1.0/(*B); + } + + free(f); + free(bdata); +} + + +// n = dim(u)[1] +// m = dim(data)[1] +// Chat vector of length n + +void ChatZj(double* data, double* u, int* n, int* d, int* m, double* Chat) +{ + int i,j,k; + double *helpvar; + helpvar=malloc(*m*sizeof(double)); + + for(j=0;j<*n;j++) + { + Chat[j]=0; + for(k=0;k<*m;k++) + { + helpvar[k]=0; + for(i=0;i<*d;i++) + { + if(data[k+1+(*m*i)-1]<=u[j+1+(*n*i)-1]) + helpvar[k]++; + } + if(helpvar[k]==*d) + Chat[j]++; + } + Chat[j]/=(*m+1); + } + + free(helpvar); +} + +void C_ind(double* data, int* n, int* d, double* C) +{ + int t=0, i=0; + + for(t=0;t<*n;t++) + { + for(i=0;i<*d;i++) + { + if(i==0) + C[t]=data[t+1+(*n*i)-1]; + else [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/vinecopula -r 67 From noreply at r-forge.r-project.org Wed Sep 10 14:05:26 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 10 Sep 2014 14:05:26 +0200 (CEST) Subject: [Vinecopula-commits] r68 - / Message-ID: <20140910120526.A7C9018692C@r-forge.r-project.org> Author: etobi Date: 2014-09-10 14:05:26 +0200 (Wed, 10 Sep 2014) New Revision: 68 Added: .Rprofile Log: .Rprofile added with 'options(repos = c(CRAN="http://cran.r-project.org"))' to get rid of NOTE in check Added: .Rprofile =================================================================== --- .Rprofile (rev 0) +++ .Rprofile 2014-09-10 12:05:26 UTC (rev 68) @@ -0,0 +1 @@ +options(repos = c(CRAN="http://cran.r-project.org"))