From ce6ace454d61bf023f94612dac0be038297f6f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Thu, 20 Feb 2014 23:54:23 -0500 Subject: [PATCH] ajout de la fonction md.test --- R/md.test.R | 38 ++++++++++++++++++++++++++++++++++++++ man/md.test.Rd | 31 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 R/md.test.R create mode 100644 man/md.test.Rd diff --git a/R/md.test.R b/R/md.test.R new file mode 100644 index 0000000..94f4d7e --- /dev/null +++ b/R/md.test.R @@ -0,0 +1,38 @@ +# 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 +#' +#' @author François Pelletier +md.test <- function(param,data,t,FUN,empFUN,alpha=0.05) +{ + n <- length(data) + # Weight matrix + Q <- ginv(outer(t,t,function(j,k) FUN(j+k,param)-FUN(j,param)*FUN(k,param))) + # Vector of differences + v <- sqrt(n) * (empFUN(t,data)-FUN(t,param)) + md.stat <- t(v) %*% Q %*% v + # Compute the test statistic using chi-square distribution + p.value <- pchisq(md.stat,df<-length(t)) + reject <- p.value >= alpha + # Print output + cat("Minimum distance test based on a transform\n\nTest statistic: ",md.stat, + "\nDegree of freedom: ",df, + "\nP-value: ",p.value, + "\nReject H0 with confidence level ",1-alpha,"?: ",reject) + # Create the return list + list(md.stat=md.stat,df=df,reject=reject,p.value=p.value) +} + + + diff --git a/man/md.test.Rd b/man/md.test.Rd new file mode 100644 index 0000000..9641bb6 --- /dev/null +++ b/man/md.test.Rd @@ -0,0 +1,31 @@ +\name{md.test} +\alias{md.test} +\title{Minimum distance test based on a transform function of a random variable} +\usage{ +md.test(param, data, t, FUN, empFUN, alpha = 0.05) +} +\arguments{ + \item{param}{Set of parameters to test} + + \item{data}{Individual data vector} + + \item{t}{Transform variate} + + \item{FUN}{Transform function (analytical)} + + \item{empFUN}{Transform function (empirical)} + + \item{alpha}{tolerance level} +} +\value{ +A list containing the chi-square statistic, degree of +freedom, hypothesis reject boolean and p.value +} +\description{ +Minimum distance test based on a transform function of a +random variable +} +\author{ +François Pelletier +} +