FourierStuff/R/md.test.R

33 lines
1.1 KiB
R
Raw Normal View History

2014-02-21 04:54:23 +00:00
# Minimum distance test based on a transform
#
# Author: François Pelletier
###############################################################################
#' Minimum distance test based on a transform function of a random variable
#' @param param Set of parameters to test
#' @param data Individual data vector
#' @param t Transform variate
#' @param FUN Transform function (analytical)
#' @param empFUN Transform function (empirical)
#' @param alpha tolerance level
#' @return A list containing the chi-square statistic,
#' degree of freedom, hypothesis reject boolean and p.value
#' @export md.test
2014-02-21 04:54:23 +00:00
#' @author François Pelletier
md.test <- function(param,data,t,FUN,empFUN,alpha=0.05)
{
n <- length(data)
# Weight matrix
Q <- MASS::ginv(outer(t,t,function(j,k) FUN(j+k,param)-FUN(j,param)*FUN(k,param)))
2014-02-21 04:54:23 +00:00
# Vector of differences
v <- sqrt(n) * (empFUN(t,data)-FUN(t,param))
2014-03-15 15:41:07 +00:00
md.stat <- Re(as.vector(t(v) %*% Q %*% v))
2014-02-21 04:54:23 +00:00
# Compute the test statistic using chi-square distribution
p.value <- pchisq(md.stat,df<-length(t))
# Create the return list
2014-03-15 15:41:07 +00:00
list(md.stat=md.stat,df=df,p.value=p.value)
2014-02-21 04:54:23 +00:00
}