Implementation of the goodness-of-fit test based on assessing the size of the area
between the null hypothesis density function and a kernel density estimate of a sample.
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.
n.sim
number of iterations performed to calculate the p.value of the test, default 101.
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 varies in each simulated dataset and is the one
estimated by default by density with a Gaussian kernel.
Details
dgeometric.test uses numerical integration and Monte Carlo simulation to implement
the test based on assessing the extend of the area between a null hypothesis density function
and a density kernel estimation. It works as follows. After computing by numerical integration the area
between the density function under the null hypothesis and its sample empirical kernel estimate obtained using
density.reflected, the p-value of the test is obtained by simulation as follows:
(i) drawing n.sim samples from fun.den with the same size length(x) of our actual
sample x; (ii) estimating the kernel density function for each of these new samples;
(iii) computing the area between the theoretical density and each of the estimates obtained in (ii);
and, (iv) calculating the p-value as the proportion of times the sample n.sim
areas computed in (iii) exceed the value of the area computed from the observed sample.
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.
Note
dgeometric.test calls density.reflected and area.between
(and, in some circunstances, also inverse, random.function and support.facto),
which are (internal) functions of the package GoFKernel.
Author(s)
Jose M. Pavia
References
Pavia, JM (2015) "Testing Goodness-of-fit with the Kernel Density Estimator: GoFKernel", Journal of Statistical Software, Code Snippets, 66(1), 1–27.
See Also
area.between, density.reflected, inverserandom.function, support.facto and fan.test.
Examples
set.seed(12)
x <- rlnorm(50, meanlog=1, sdlog=1)
## test if x follows a Gamma distribution with shape .6 and rate .1
dgeometric.test(x, dgamma, par=list(shape=0.6, rate=0.1), lower=0, upper=Inf, n.sim=100)
f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
## test if risk76.1929 follows the distribution characterized by f0
dgeometric.test(risk76.1929, f0, lower=0, upper=1, n.sim=31)
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/dgeometric.test.Rd_%03d_medium.png", width=480, height=480)
> ### Name: dgeometric.test
> ### Title: Geometric Goodness-of-fit Test
> ### Aliases: dgeometric.test
> ### Keywords: htest
>
> ### ** Examples
>
>
> set.seed(12)
> x <- rlnorm(50, meanlog=1, sdlog=1)
> ## test if x follows a Gamma distribution with shape .6 and rate .1
> dgeometric.test(x, dgamma, par=list(shape=0.6, rate=0.1), lower=0, upper=Inf, n.sim=100)
Geometric test
data: x
Tn = 0.58399, p-value < 2.2e-16
>
> f0 <- function(x) ifelse(x>=0 & x<=1, 2-2*x, 0)
> ## test if risk76.1929 follows the distribution characterized by f0
> dgeometric.test(risk76.1929, f0, lower=0, upper=1, n.sim=31)
Geometric test
data: risk76.1929
Tn = 0.11434, p-value < 2.2e-16
>
>
>
>
>
>
> dev.off()
null device
1
>