Modification des messages
This commit is contained in:
parent
9a9dc346bd
commit
0a2c687323
3 changed files with 16 additions and 24 deletions
|
@ -1,10 +1,12 @@
|
|||
# Pearson's Chi-Squared test based on the characteristic function
|
||||
#
|
||||
# Author: François Pelletier
|
||||
#
|
||||
# LGPL 3.0
|
||||
###############################################################################
|
||||
|
||||
#' Pearson's Chi-Squared test based on the characteristic function
|
||||
#' @param DATA.hist histogram object of the data
|
||||
#' @param datahist histogram object of the data
|
||||
#' @param FUN Characteristic function (integral) or
|
||||
#' Saddlepoint distribution approximation (saddlepoint)
|
||||
#' @param ... FUN arguments
|
||||
|
@ -15,30 +17,26 @@
|
|||
#' degree of freedom, hypothesis reject boolean and p.value
|
||||
#' @export chisquare.test
|
||||
#' @author François Pelletier
|
||||
chisquare.test <- function(DATA.hist,FUN,...,alpha=0.05,method="integral")
|
||||
chisquare.test <- function(datahist,FUN,...,alpha=0.05,method="integral")
|
||||
{
|
||||
# Compute expected values for each histogram breaks using the characteristic function
|
||||
classes <- DATA.hist$breaks
|
||||
classes <- datahist$breaks
|
||||
observed <- datahist$counts
|
||||
if(method=="integral")
|
||||
{
|
||||
expected <- diff(cftocdf(classes,FUN,...)*
|
||||
sum(observed <- DATA.hist$counts))
|
||||
sum(observed))
|
||||
}
|
||||
else if(method=="saddlepoint")
|
||||
{
|
||||
expected <- diff(FUN(classes,...)*
|
||||
sum(observed <- DATA.hist$counts))
|
||||
sum(observed))
|
||||
}
|
||||
|
||||
# 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)
|
||||
# Print output
|
||||
cat("Chi-Square Test based on CF\n\nTest statistic: ",chisquare.stat,
|
||||
"\nDegree of freedom: ",df,
|
||||
"\nP-value: ",p.value,
|
||||
"\nReject H0 with confidence level ",1-alpha,"?: ",p.value<alpha)
|
||||
chisquare.stat<-sum((observed-expected)^2/expected)
|
||||
df<-length(classes)-2
|
||||
p.value <- pchisq(chisquare.stat,df,lower.tail=FALSE)
|
||||
# Create the return list
|
||||
list(chisquare.stat=chisquare.stat,df=df,reject=p.value<alpha,p.value=p.value)
|
||||
list(chisquare.stat=chisquare.stat,df=df,p.value=p.value)
|
||||
}
|
||||
|
||||
|
|
10
R/md.test.R
10
R/md.test.R
|
@ -21,17 +21,11 @@ md.test <- function(param,data,t,FUN,empFUN,alpha=0.05)
|
|||
Q <- MASS::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
|
||||
md.stat <- Re(as.vector(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)
|
||||
list(md.stat=md.stat,df=df,p.value=p.value)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
\alias{chisquare.test}
|
||||
\title{Pearson's Chi-Squared test based on the characteristic function}
|
||||
\usage{
|
||||
chisquare.test(DATA.hist, FUN, ..., alpha = 0.05, method = "integral")
|
||||
chisquare.test(datahist, FUN, ..., alpha = 0.05, method = "integral")
|
||||
}
|
||||
\arguments{
|
||||
\item{DATA.hist}{histogram object of the data}
|
||||
\item{datahist}{histogram object of the data}
|
||||
|
||||
\item{FUN}{Characteristic function (integral) or
|
||||
Saddlepoint distribution approximation (saddlepoint)}
|
||||
|
|
Loading…
Add table
Reference in a new issue