@@ -447,26 +447,26 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
447
447
if (options $ shapiroWilkTest ) { stats $ addColumnInfo(name = " Shapiro-Wilk" , title = gettext(" Shapiro-Wilk" ), type = " number" )
448
448
stats $ addColumnInfo(name = " P-value of Shapiro-Wilk" , title = gettext(" P-value of Shapiro-Wilk" ), type = " pvalue" ) }
449
449
if (options $ range ) stats $ addColumnInfo(name = " Range" , title = gettext(" Range" ), type = " number" )
450
- if (options $ minimum ) stats $ addColumnInfo(name = " Minimum" , title = gettext(" Minimum" ), type = " number " )
451
- if (options $ maximum ) stats $ addColumnInfo(name = " Maximum" , title = gettext(" Maximum" ), type = " number " )
450
+ if (options $ minimum ) stats $ addColumnInfo(name = " Minimum" , title = gettext(" Minimum" ), type = " mixed " )
451
+ if (options $ maximum ) stats $ addColumnInfo(name = " Maximum" , title = gettext(" Maximum" ), type = " mixed " )
452
452
453
453
if (options $ quartiles ) {
454
- stats $ addColumnInfo(name = " q1" , title = gettext(" 25th percentile" ), type = " number " )
455
- stats $ addColumnInfo(name = " q2" , title = gettext(" 50th percentile" ), type = " number " )
456
- stats $ addColumnInfo(name = " q3" , title = gettext(" 75th percentile" ), type = " number " )
454
+ stats $ addColumnInfo(name = " q1" , title = gettext(" 25th percentile" ), type = " mixed " )
455
+ stats $ addColumnInfo(name = " q2" , title = gettext(" 50th percentile" ), type = " mixed " )
456
+ stats $ addColumnInfo(name = " q3" , title = gettext(" 75th percentile" ), type = " mixed " )
457
457
}
458
458
459
459
if (options $ quantilesForEqualGroups ) { # I've read that there are several ways how to estimate percentiles so it should be checked if it match the SPSS way
460
460
tempPercentNames <- 1 / equalGroupsNo * 1 : (equalGroupsNo - 1 ) * 100
461
461
462
462
for (i in seq_along(tempPercentNames ))
463
- stats $ addColumnInfo(name = paste0(" eg" , i ), title = gettextf(" %gth percentile" , round(tempPercentNames [i ], 2 )), type = " number " )
463
+ stats $ addColumnInfo(name = paste0(" eg" , i ), title = gettextf(" %gth percentile" , round(tempPercentNames [i ], 2 )), type = " mixed " )
464
464
}
465
465
466
466
if (options $ percentiles ) {
467
467
for (i in percentilesPercentiles ) {
468
468
if (i > = 0 && i < = 100 ) {
469
- stats $ addColumnInfo(name = paste0(" pc" , i ), title = gettextf(" %gth percentile" , i ), type = " number " )
469
+ stats $ addColumnInfo(name = paste0(" pc" , i ), title = gettextf(" %gth percentile" , i ), type = " mixed " )
470
470
} else {
471
471
.quitAnalysis(gettext(" Error in Percentiles, all values should >=0 and <=100" ))
472
472
}
@@ -568,6 +568,12 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
568
568
rows <- length(column )
569
569
na.omitted <- na.omit(column )
570
570
571
+ # for ordinals, we show the label (a string) rather than the value
572
+ mixedRowType <- if (columnType == " scale" ) " number" else " string"
573
+ maybeToString <- if (columnType == " scale" ) identity else as.character
574
+ toMixedCol <- \(x ) jaspBase :: createMixedColumn(maybeToString(x ), mixedRowType )
575
+
576
+
571
577
shouldAddIdenticalFootnote <- all(na.omitted [1 ] == na.omitted ) && (options $ skewness || options $ kurtosis || options $ shapiroWilkTest )
572
578
573
579
valid <- length(na.omitted )
@@ -591,12 +597,13 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
591
597
resultsCol [[" Shapiro-Wilk" ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options $ shapiroWilkTest , na.omitted , function (param ) { res <- try(shapiro.test(param )$ statistic ); if (isTryError(res )) NaN else res })
592
598
resultsCol [[" P-value of Shapiro-Wilk" ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options $ shapiroWilkTest , na.omitted , function (param ) { res <- try(shapiro.test(param )$ p.value ); if (isTryError(res )) NaN else res })
593
599
resultsCol [[" Sum" ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options $ sum , na.omitted , sum )
600
+ resultsCol [[" Range" ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options $ range , na.omitted , function (param ) { range(param )[2 ] - range(param )[1 ]})
594
601
}
595
602
596
603
if (columnType == " scale" || columnType == " ordinal" ) {
597
- resultsCol [[" Range " ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker( options $ range , na.omitted , function ( param ) { range( param )[ 2 ] - range( param )[ 1 ]} )
598
- resultsCol [[" Minimum " ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker( options $ minimum , na.omitted , min )
599
- resultsCol [[ " Maximum " ]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker( options $ maximum , na.omitted , max )
604
+ if ( options $ minimum ) resultsCol [[" Minimum " ]] <- toMixedCol(min( na.omitted ) )
605
+ if ( options $ maximum ) resultsCol [[" Maximum " ]] <- toMixedCol(max( na.omitted ) )
606
+
600
607
}
601
608
# validator for meanCi, sdCi, and varianceCi
602
609
ciOptionChecker <- function (fun , na.omitted , columnType , options , jaspResults , variableName ) {
@@ -673,9 +680,10 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
673
680
# Type 3: Nearest even order statistic (SAS default till ca. 2010).
674
681
quartileType <- ifelse(columnType == " scale" , 7 , 3 )
675
682
q123 <- quantile(na.omitted , c(.25 , .5 , .75 ), names = FALSE , type = quartileType )
676
- resultsCol [[" q1" ]] <- q123 [1 ]
677
- resultsCol [[" q2" ]] <- q123 [2 ]
678
- resultsCol [[" q3" ]] <- q123 [3 ]
683
+
684
+ resultsCol [[" q1" ]] <- toMixedCol(q123 [1 ])
685
+ resultsCol [[" q2" ]] <- toMixedCol(q123 [2 ])
686
+ resultsCol [[" q3" ]] <- toMixedCol(q123 [3 ])
679
687
} else {
680
688
resultsCol [[" q1" ]] <- " "
681
689
resultsCol [[" q2" ]] <- " "
@@ -714,14 +722,14 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
714
722
if (options $ quantilesForEqualGroups ) {
715
723
716
724
for (i in seq(equalGroupsNo - 1 ))
717
- resultsCol [[paste0(" eg" , i )]] <- quantile(na.omitted , c(i / equalGroupsNo ), names = FALSE , type = quartileType )
725
+ resultsCol [[paste0(" eg" , i )]] <- toMixedCol( quantile(na.omitted , c(i / equalGroupsNo ), names = FALSE , type = quartileType ) )
718
726
719
727
}
720
728
721
729
if (options $ percentiles ) {
722
730
723
731
for (i in percentilesPercentiles )
724
- resultsCol [[paste0(" pc" , i )]] <- quantile(na.omitted , c(i / 100 ), names = FALSE , type = quartileType )
732
+ resultsCol [[paste0(" pc" , i )]] <- toMixedCol( quantile(na.omitted , c(i / 100 ), names = FALSE , type = quartileType ) )
725
733
726
734
}
727
735
} else {
0 commit comments