fan.test: Univariate implementation of the test of Fan (1994) in the...

Description Usage Arguments Details Value Warning Note Author(s) References See Also Examples

View source: R/GoFKernel.r

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.

Usage

1
2
fan.test(x, fun.den, par = NULL, lower = -Inf, upper = Inf, kernel = "normal",
         bw=NULL)

Arguments

x

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

1
2
3
4
5
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")

GoFKernel documentation built on May 2, 2019, 11:41 a.m.