npresid.boot: Code to approximate the asymptotic distribution through a...

Description Usage Arguments Value Examples

View source: R/Npres_Fucntions.R

Description

Code to approximate the asymptotic distribution through a model based bootstrap procedure (see Section 3.2.1 of Patra, Sen, and Székely (2015)) and evaluate the p-value of the proposed test

Usage

1
npresid.boot(data.to.work, z.dim, accuracy = 500, boot.replic = 999)

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'

accuracy

It determines how precise you want to be when inverting the estimated conditional distribution function while generating the bootstrap samples. 500 is generally more than sufficient. Default is 500.

boot.replic

Number of bootstrap replicates used for p value calculations.

Value

A list containing:

statistic

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

p.value

Estimated p-value computed based on bootstrap.

method

A variable describing the method of computation. Currently we only implement only one method. Thus this is always: 'Cond Indep test: p-values by inverting F_hat to get bootstrap samples'

bandwidth.method

A variable describing the method for choosing bandwidth in estimation. In this version it always says: 'least-squares cross-validation, see "np" package',

data.desrip

A string describing the data in words

bootstrap.stat.values

A numeric vector containing the bootstrap statistics.

cond.dist.obj

A list containing estimators of FX|Z, FY|Z, and FZ evaluated at the data points (denoted by F.x_z, F.y_z, and F.z_hat) and the bandwidth used (denoted by Fbw.x_z, Fbw.y_z, and Fbw.z_z) to evaluate the conditional distribution functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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)
# bootstrap calculations to get p-values
out<-npresid.boot(data.to.work,z.dim,accuracy=500,boot.replic=5)
print(out$boot.data)
pvalue.out=out$p.value
print(pvalue)

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