Ajout chisquare.test

This commit is contained in:
François Pelletier 2014-02-22 13:27:24 -05:00
parent 3b7ae2a6bc
commit 0e4349d974
3 changed files with 27 additions and 9 deletions

View file

@ -1,4 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
.gitignore
.project
.git
.settings
.settings

View file

@ -5,18 +5,30 @@
#' Pearson's Chi-Squared test based on the characteristic function
#' @param DATA.hist histogram object of the data
#' @param char.fun Characteristic function
#' @param ... Characteristic function arguments
#' @param FUN Characteristic function (integral) or
#' Saddlepoint distribution approximation (saddlepoint)
#' @param ... FUN arguments
#' @param alpha tolerance level
#' @param method Method to approximate the distribution function. "integral" or "saddlepoint"
#'
#' @return A list containing the chi-square statistic,
#' degree of freedom, hypothesis reject boolean and p.value
#' @author François Pelletier
chisquare.test <- function(DATA.hist,char.fun,...,alpha=0.05)
chisquare.test <- function(DATA.hist,FUN,...,alpha=0.05,method="integral")
{
# Compute expected values for each histogram breaks using the characteristic function
expected <- diff(cftocdf(classes <- DATA.hist$breaks,char.fun,...)*
sum(observed <- DATA.hist$counts))
classes <- DATA.hist$breaks
if(method=="integral")
{
expected <- diff(cftocdf(classes,FUN,...)*
sum(observed <- DATA.hist$counts))
}
else if(method=="saddlepoint")
{
expected <- diff(FUN(classes,...)*
sum(observed <- DATA.hist$counts))
}
# Compute the test statistic using chi-square distribution
p.value <- pchisq(chisquare.stat<-sum((observed-expected)^2/expected),
df<-length(classes)-2,lower.tail=FALSE)

View file

@ -2,16 +2,20 @@
\alias{chisquare.test}
\title{Pearson's Chi-Squared test based on the characteristic function}
\usage{
chisquare.test(DATA.hist, char.fun, ..., alpha = 0.05)
chisquare.test(DATA.hist, FUN, ..., alpha = 0.05, method = "integral")
}
\arguments{
\item{DATA.hist}{histogram object of the data}
\item{char.fun}{Characteristic function}
\item{FUN}{Characteristic function (integral) or
Saddlepoint distribution approximation (saddlepoint)}
\item{...}{Characteristic function arguments}
\item{...}{FUN arguments}
\item{alpha}{tolerance level}
\item{method}{Method to approximate the distribution
function. "integral" or "saddlepoint"}
}
\value{
A list containing the chi-square statistic, degree of