Skip to content

Commit 17ea3e4

Browse files
authored
Shapiro-Francia test of normality (#200)
* fix test triangular dist * add shapiro-francia as a separate option (for normal dist)
1 parent d90b06f commit 17ea3e4

File tree

9 files changed

+413
-394
lines changed

9 files changed

+413
-394
lines changed

R/commonDiscoverDistributions.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@
417417
isTRUE(options[["andersonDarling"]]) ||
418418
isTRUE(options[["lillienfors"]]) ||
419419
isTRUE(options[["shapiroWilk"]]) ||
420+
isTRUE(options[["shapiroFrancia"]]) ||
420421
isTRUE(options[["chiSquare"]]) ||
421422
isTRUE(options[["estPDF"]]) ||
422423
isTRUE(options[["estPMF"]]) ||
@@ -522,7 +523,7 @@
522523
.ldFitStatisticsTable <- function(fitContainer, options, method){
523524
if(!is.null(fitContainer[['fitStatisticsTable']])) return()
524525

525-
allTests <- c("kolmogorovSmirnov", "cramerVonMisses", "andersonDarling", "lillienfors", "shapiroWilk", "chiSquare")
526+
allTests <- c("kolmogorovSmirnov", "cramerVonMisses", "andersonDarling", "lillienfors", "shapiroWilk", "shapiroFrancia", "chiSquare")
526527
optionsTests <- allTests %in% names(options)
527528
whichTests <- unlist(options[allTests[optionsTests]])
528529

@@ -550,7 +551,7 @@
550551
if(is.null(fit)) return()
551552
if(!is.null(fitContainer[['fitStatisticsResults']])) return(fitContainer[['fitStatisticsResults']]$object)
552553

553-
allTests <- c("kolmogorovSmirnov", "cramerVonMisses", "andersonDarling", "lillienfors", "shapiroWilk", "chiSquare")
554+
allTests <- c("kolmogorovSmirnov", "cramerVonMisses", "andersonDarling", "lillienfors", "shapiroWilk", "shapiroFrancia", "chiSquare")
554555
tests <- allTests[allTests %in% names(options)]
555556

556557
res <- data.frame(test = tests, statistic = numeric(length = length(tests)), p.value = numeric(length = length(tests)))
@@ -562,6 +563,7 @@
562563
"kolmogorovSmirnov" = c(list(x = variable, y = options$cdfFun), pars),
563564
"lillienfors" = list(x = variable),
564565
"shapiroWilk" = list(x = variable),
566+
"shapiroFrancia" = list(x = variable),
565567
"chiSquare" = list(x = as.numeric(table(variable)),
566568
p = do.call(options[['pdfFun']],
567569
utils::modifyList(pars,
@@ -577,7 +579,8 @@
577579
"cramerVonMisses" = goftest::cvm.test,
578580
"andersonDarling" = goftest::ad.test,
579581
"lillienfors" = nortest::lillie.test,
580-
"shapiroWilk" = nortest::sf.test,
582+
"shapiroWilk" = stats::shapiro.test,
583+
"shapiroFrancia" = nortest::sf.test,
581584
"chiSquare" = stats::chisq.test
582585
)
583586

@@ -593,13 +596,9 @@
593596
fun <- function(x) {
594597
return(list(statistic = NA, p.value = NA))
595598
}
596-
} else if (test == "shapiroWilk" && (length(variable) < 5 || length(variable) > 5000)) {
597-
fun <- stats::shapiro.test
598599
}
599600
} else {
600-
if (test == "shapiroWilk") {
601-
fun <- stats::shapiro.test
602-
} else if (test=="lillienfors") {
601+
if (test=="lillienfors") {
603602
fun <- function(x) {
604603
return(list(statistic = NA, p.value = NA))
605604
}
@@ -622,13 +621,14 @@
622621
if(is.null(table)) return()
623622

624623

625-
allTests <- c("kolmogorovSmirnov", "cramerVonMisses", "andersonDarling", "lillienfors", "shapiroWilk", "chiSquare")
624+
allTests <- c("kolmogorovSmirnov", "cramerVonMisses", "andersonDarling", "lillienfors", "shapiroWilk", "shapiroFrancia", "chiSquare")
626625
tests <- allTests[allTests %in% names(options)]
627626
testNames <- c(gettext("Kolmogorov-Smirnov"),
628627
gettext("Cramér-von Mises"),
629628
gettext("Anderson-Darling"),
630629
gettext("Lillienfors"),
631630
gettext("Shapiro-Wilk"),
631+
gettext("Shapiro-Francia"),
632632
gettext("Chi-square"))[allTests %in% names(options)]
633633

634634
whichTests <- unlist(options[tests])

inst/qml/LDgaussianunivariate.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,5 @@ Form
107107

108108
LD.LDEstimateParameters { enabled: dataSetInfo.dataAvailable; includeUnbiased: true }
109109

110-
LD.LDAssessFit{ enabled: dataSetInfo.dataAvailable; includeShapiroWilk: true; includeLillienfors: true}
110+
LD.LDAssessFit{ enabled: dataSetInfo.dataAvailable; includeShapiro: true; includeLillienfors: true}
111111
}

inst/qml/common/LDAssessFit.qml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Section
2424
{
2525
property string distributionType : "continuous" // "counts" or "categorical"
2626
property bool includeLillienfors : false
27-
property bool includeShapiroWilk : false
27+
property bool includeShapiro : false
2828
property bool isDistributionContinuous : distributionType === "continuous"
2929

3030
title: enabled ? qsTr("Assess Fit") : qsTr("Assess Fit") + " - " + qsTr("[requires a loaded data set]")
@@ -86,8 +86,9 @@ Section
8686
CheckBox{ name: "kolmogorovSmirnov"; label: qsTr("Kolmogorov-Smirnov"); info: qsTr("Displays the Kolmogorov-Smirnov test") }
8787
CheckBox{ name: "cramerVonMisses"; label: qsTr("Cramér–von Mises"); info: qsTr("Displays the Cramér-von Mises test") }
8888
CheckBox{ name: "andersonDarling"; label: qsTr("Anderson-Darling"); info: qsTr("Displays the Anderson-Darling test") }
89-
CheckBox{ name: "lillienfors"; label: qsTr("Lillienfors"); info: qsTr("Displays the Lillienfors test"); visible: includeLillienfors }
90-
CheckBox{ name: "shapiroWilk"; label: qsTr("Shapiro-Wilk"); info: qsTr("Displays the Shapiro-Wilk test of normality"); visible: includeShapiroWilk }
89+
CheckBox{ name: "lillienfors"; label: qsTr("Lillienfors"); info: qsTr("Displays the Lillienfors test"); visible: includeLillienfors }
90+
CheckBox{ name: "shapiroWilk"; label: qsTr("Shapiro-Wilk"); info: qsTr("Displays the Shapiro-Wilk test of normality"); visible: includeShapiro }
91+
CheckBox{ name: "shapiroFrancia"; label: qsTr("Shapiro-Francia"); info: qsTr("Displays the Shapiro-Francia test of normality"); visible: includeShapiro }
9192
}
9293
}
9394

tests/testthat/_snaps/ldtriangular/empirical-vs-theoretical-cdf.svg

Lines changed: 14 additions & 10 deletions
Loading

0 commit comments

Comments
 (0)