npresid.statistics: Code to compute the test statistic in (3.7) of Patra, Sen,...

Description Usage Arguments Value Examples

View source: R/Npres_Fucntions.R

Description

Code to compute the test statistic in (3.7) of Patra, Sen, and Székely (2015)

Usage

1
npresid.statistics(data.to.work, z.dim)

Arguments

data.to.work

A numeric matrix containing 'x', 'y', and 'z'. The first column is 'x', the second column is 'y', and the rest is data from 'z'. We test for conditional independence of 'x' and 'y' given 'z'

z.dim

Dimension of the random variable 'z'

Value

A numeric computing the statistic described in (3.7) of see Patra, Sen, and Székely (2015)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#data generation mechanism used in the paper
# Returns a Matrix with n rows and columns (x, y, z_1, ...z_dim)
#x and y have to dimension real valued random variables
data.gen<-function(n,sigma_alt,dim){
  Data_to_write<- NULL
  z_prime = rnorm(n,0,sigma_alt)
  z = matrix(rnorm(n*dim,0,.3),nr=n, nc=dim)
  x = rnorm(n,z[,1],.2) + z_prime
  y = rnorm(n,z[,1],.2)  + z_prime
  Data_to_write=cbind(x,y,z)
  colnames(Data_to_write)[3:(dim+2)]= paste('z_', 1:dim,sep='')
  return(Data_to_write)
}
n=50 # Sample size
sigma_alt=0 # Used for generating the random variables (see Section 4 (simulation section)).
z.dim=1 # Dimension of z
# data generated is a matrix with nrow=n and ncol=dim+2 with (x, y, z_1, ...z_dim) as columns
data.to.work<- data.gen(n,sigma_alt,z.dim)
#Evaluate the statistic
statistics<-npresid.statistics(data.to.work,z.dim)

rohitpatra/BrownCondInd documentation built on Feb. 25, 2021, 3:03 p.m.