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.
fan.test(x, fun.den, par = NULL, lower = -Inf, upper = Inf, kernel = "normal",
bw=NULL)
a numeric vector of data values for which the null hypothesis is tested.
an actual density distribution function, such as dnorm
. Only continuous
densities are valid.
list of (additional) parameters of the density function under the null hypothesis, default NULL.
lower end point of the support of the random variable defined by fun.den
,
default -Inf.
upper end point of the support of the random variable defined by fun.den
,
default -Inf.
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".
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
.
The output is an object of the class htest
exactly like for the Kolmogorov-Smirnov
test, ks.test
.
A list containing the following components:
the value of the test statistic.
the p-value of the test.
the character string "Geometric test".
a character string giving the name of the data.
fan.test
calls the dpik
function of KernSmooth
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.
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.
dgeometric.test
, integrate
and dpik
.
# NOT RUN {
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")
# }
Run the code above in your browser using DataLab