diff --git a/.Rbuildignore b/.Rbuildignore index 5b70fef..04a8cf7 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,4 +1,6 @@ +^.*\.Rproj$ +^\.Rproj\.user$ .gitignore .project .git -.settings \ No newline at end of file +.settings diff --git a/R/chisquare.test.R b/R/chisquare.test.R index 84f9698..d406314 100644 --- a/R/chisquare.test.R +++ b/R/chisquare.test.R @@ -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) diff --git a/man/chisquare.test.Rd b/man/chisquare.test.Rd index 997361a..109696f 100644 --- a/man/chisquare.test.Rd +++ b/man/chisquare.test.Rd @@ -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