R: Univariate implementation of the test of Fan (1994) in the...
fan.test
R Documentation
Univariate implementation of the test of Fan (1994) in the form proposed by Li and Racine (2007).
Description
Given a sample of a continuous univariate random variable and a density
function fun.den with support in the interval (lower, upper)),
fan.test considers the test whose null hypothesis is that the sample has fun.den as density function
and the test statistic and the corresponding p-value of the test based on the integral of the squared difference between
the null hypothesis density function and a kernel smoothing approximation.
To properly run, the KernSmooth package needs to be
installed, as in its default option it depends on the dpik function to estimate the bandwidth.
a numeric vector of data values for which the null hypothesis is tested.
fun.den
an actual density distribution function, such as dnorm. Only continuous
densities are valid.
par
list of (additional) parameters of the density function under the null hypothesis, default NULL.
lower
lower end point of the support of the random variable defined by fun.den,
default -Inf.
upper
upper end point of the support of the random variable defined by fun.den,
default -Inf.
kernel
a character string with the kernel to be used, either "normal" (a N(0,1) density),
"box" (a uniform in -1 to 1) or "epanech" (a Epanechnikov quadratic kernel), default "normal".
bw
a number indicating the bandwidth to be used in the empirical kernel estimate of the data,
default NULL. In its default option, the bandwidth is estimated using the dpik function
included in the package KernSmooth.
Details
The Fan's test is based on a normal approximation of the integral of the squared difference between
the null hypothesis density function and a kernel smoothing approximation. In Li and Racine's form it is
obtained as the aggregation of (i) a sampling component, (ii) the integrate of the square of the kernel
convolution of the density null function and (iii) the sum of the convolution of the density in the sampled values,
see Li and Racine (2007, pp.380-1) for details.
Value
The output is an object of the class htest exactly like for the Kolmogorov-Smirnov
test, ks.test.
A list containing the following components:
statistic
the value of the test statistic.
p.value
the p-value of the test.
method
the character string "Geometric test".
data.name
a character string giving the name of the data.
Warning
fan.test calls the dpik function of KernSmooth
Note
To properly run the function requires the package KernSmooth
to be installed to estimate the bandwidth.
Author(s)
Jose M. Pavia
References
Fan, Y (1994) "Testing the goodness-of-fit of a parametric density function by kernel method", Econometric Theory, 10, 316–356.
Li, O. and Racine, J.F. (2007) "Nonparametric Econometrics", Princeton niversity Press, New Jersey.
See Also
dgeometric.test, integrate and dpik.
Examples
fan.test(runif(100), dunif, lower=0, upper=1)
f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
## testing if risk76.1929 follows the distribution characterized by f0
fan.test(risk76.1929, f0, lower=0, upper=1, kernel="epanech")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(GoFKernel)
Loading required package: KernSmooth
KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GoFKernel/fan.test.Rd_%03d_medium.png", width=480, height=480)
> ### Name: fan.test
> ### Title: Univariate implementation of the test of Fan (1994) in the form
> ### proposed by Li and Racine (2007).
> ### Aliases: fan.test
> ### Keywords: htest
>
> ### ** Examples
>
> fan.test(runif(100), dunif, lower=0, upper=1)
Fan's test
data: runif(100)
Ig = -2.7549, p-value = 0.9971
>
> f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
> ## testing if risk76.1929 follows the distribution characterized by f0
> fan.test(risk76.1929, f0, lower=0, upper=1, kernel="epanech")
Fan's test
data: risk76.1929
Ig = -3.8156, p-value = 0.9999
>
>
>
>
>
>
> dev.off()
null device
1
>