ajout de la fonction md.test
This commit is contained in:
parent
01505a567b
commit
ce6ace454d
2 changed files with 69 additions and 0 deletions
38
R/md.test.R
Normal file
38
R/md.test.R
Normal file
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
31
man/md.test.Rd
Normal file
31
man/md.test.Rd
Normal file
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in a new issue