Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: jaspDescriptives
Type: Package
Title: Descriptives Module for JASP
Version: 0.95.0
Version: 0.95.1
Date: 2022-09-12
Author: JASP Team
Website: jasp-stats.org
Expand Down
39 changes: 30 additions & 9 deletions R/descriptives.R
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
stats$addFootnote(message = gettextf("Excluded %1$i rows from the analysis that correspond to the missing values of the split-by variable %2$s", numberMissingSplitBy, options$splitBy))

stats$dependOn(c(
"splitBy", "variables", "quantilesForEqualGroupsNumber", "percentileValues", "mode", "median", "mean",
"splitBy", "variables", "quantilesForEqualGroupsNumber", "percentileValues", "mode", "median",
"meanArithmetic", "meanGeometric", "meanHarmonic",
"seMean", "sd", "coefficientOfVariation", "variance", "skewness", "kurtosis", "shapiroWilkTest",
"range", "iqr", "mad", "madRobust", "minimum", "maximum", "sum", "quartiles", "quantilesForEqualGroups",
"percentiles", "descriptivesTableTransposed", "valid", "missing", "meanCi", "meanCiLevel", "meanCiMethod",
Expand Down Expand Up @@ -414,8 +415,8 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
meanCiOvertitle <- NULL
sdCiOvertitle <- NULL
varianceCiOvertitle <- NULL
meanCiUbTitle <- gettextf("%s%% CI Mean Upper", formattedMeanCiPercent)
meanCiLbTitle <- gettextf("%s%% CI Mean Lower", formattedMeanCiPercent)
meanCiUbTitle <- gettextf("%s%% CI A. Mean Upper", formattedMeanCiPercent)
meanCiLbTitle <- gettextf("%s%% CI A. Mean Lower", formattedMeanCiPercent)
sdCiUbTitle <- gettextf("%s%% CI Std. Dev. Upper", formattedSdCiPercent)
sdCiLbTitle <- gettextf("%s%% CI Std. Dev. Lower", formattedSdCiPercent)
varianceCiUbTitle <- gettextf("%s%% CI Variance Upper", formattedVarianceCiPercent)
Expand All @@ -426,10 +427,12 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
if (options$missing) stats$addColumnInfo(name="Missing", title=gettext("Missing"), type="integer")
if (options$mode) stats$addColumnInfo(name="Mode", title=gettext("Mode"), type="mixed")
if (options$median) stats$addColumnInfo(name="Median", title=gettext("Median"), type="number")
if (options$mean) stats$addColumnInfo(name="Mean", title=gettext("Mean"), type="number")
if (options$seMean) stats$addColumnInfo(name="Std. Error of Mean", title=gettext("Std. Error of Mean"), type="number")
if (options$meanArithmetic) stats$addColumnInfo(name="MeanArithmetic", title=gettext("Mean (arithmetic)"), type="number")
if (options$seMean) stats$addColumnInfo(name="Std. Error of Mean", title=gettext("Std. Error of A. Mean"), type="number")
if (options$meanCi) { stats$addColumnInfo(name="MeanCILB", title=meanCiLbTitle, type="number", overtitle = meanCiOvertitle)
stats$addColumnInfo(name="MeanCIUB", title=meanCiUbTitle, type="number", overtitle = meanCiOvertitle)}
if (options$meanGeometric) stats$addColumnInfo(name="MeanGeometric", title=gettext("Mean (geometric)"), type="number")
if (options$meanHarmonic) stats$addColumnInfo(name="MeanHarmonic", title=gettext("Mean (harmonic)"), type="number")
if (options$sd) stats$addColumnInfo(name="Std. Deviation", title=gettext("Std. Deviation"), type="number")
if (options$sdCi) { stats$addColumnInfo(name="SdCILB", title=sdCiLbTitle, type="number", overtitle = sdCiOvertitle)
stats$addColumnInfo(name="SdCIUB", title=sdCiUbTitle, type="number", overtitle = sdCiOvertitle)}
Expand Down Expand Up @@ -581,9 +584,11 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
resultsCol[["Missing"]] <- if (options$missing) rows - length(na.omitted)

if (columnType == "scale") {
resultsCol[["Median"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$median, na.omitted, median)
resultsCol[["Mean"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$mean, na.omitted, mean)
resultsCol[["Std. Error of Mean"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$seMean, na.omitted, function(param) { sd(param)/sqrt(length(param))} )
resultsCol[["Median"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$median, na.omitted, median)
resultsCol[["MeanArithmetic"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$meanArithmetic, na.omitted, mean)
resultsCol[["Std. Error of Mean"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$seMean, na.omitted, function(param) { sd(param)/sqrt(length(param))} )
resultsCol[["MeanGeometric"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$meanGeometric, na.omitted, .geometricMean )
resultsCol[["MeanHarmonic"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$meanHarmonic, na.omitted, .harmonicMean )
resultsCol[["Std. Deviation"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$sd, na.omitted, sd)
resultsCol[["Coefficient of Variation"]]<- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$coefficientOfVariation, na.omitted, function(param) { sd(param) / mean(param)})
resultsCol[["MAD"]] <- .descriptivesDescriptivesTable_subFunction_OptionChecker(options$mad, na.omitted, function(param) { mad(param, constant = 1) } )
Expand Down Expand Up @@ -2109,7 +2114,7 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
container[[plotName]] <- jaspPlot
}

.descriptivesHeatmapAggregateData <- function(variable, groups, fun = c("identity", "mean", "median", "mode", "length")) {
.descriptivesHeatmapAggregateData <- function(variable, groups, fun = c("identity", "meanArithmetic", "median", "mode", "length")) {
fun <- match.arg(fun)
mode <- function(x) {
levels <- levels(x)
Expand Down Expand Up @@ -2523,3 +2528,19 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {

container[[plotName]] <- densPlot
}

.geometricMean <- function(x) {
if (any(x <= 0)) return(NA)

return(
exp(mean(log(x)))
)
}

.harmonicMean <- function(x) {
if (any(x <= 0)) return(NA)

return(
1 / mean(1/x)
)
}
248 changes: 127 additions & 121 deletions R/descriptivesWrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
#' @param customHistogramPosition, Options for separate bins of the histogram
#' \itemize{
#' \item \code{"identity"}: Identity: Bars are layered on top of each other, with transparency often used to distinguish overlapping data.
#' \item \code{"stack"}: Stack: Bars are stacked vertically, combining counts across categories within each bin.
#' \item \code{"dodge"}: Dodge: Bars are placed side-by-side, allowing for easy comparison of different categories within each bin.
#' \item \code{"stack"}: Stack: Bars are stacked vertically, combining counts across categories within each bin.
#' }
#' @param densityPlot, visualizes data distributions, adapting to the type of variable selected. For scale variables, it generates histograms or density plots to show continuous data distributions. For categorical variables, it creates bar plots displaying counts or proportions of each category.
#' Defaults to \code{FALSE}.
Expand Down Expand Up @@ -75,10 +75,14 @@
#' Defaults to \code{FALSE}.
#' @param maximum, Maximum value of the data points.
#' Defaults to \code{TRUE}.
#' @param mean, Arithmetic mean of the data points
#' @param meanArithmetic, Arithmetic mean of the data points.
#' Defaults to \code{TRUE}.
#' @param meanCiLevel, width of the confidence interval.
#' @param meanCiMethod, How should the confidence interval be computed? By default, we use a `T model`, which yields results identical to a one-sample t-test. Alternative options are a normal model ($\bar{x} \pm z_{95} \times SE$), or `Bootstrap`.
#' @param meanGeometric, Geometric mean of the data points; defined only for strictly positive variables.
#' Defaults to \code{FALSE}.
#' @param meanHarmonic, Harmonic mean of the data points; defined only for strictly positive variables.
#' Defaults to \code{FALSE}.
#' @param median, Median of the data points.
#' Defaults to \code{FALSE}.
#' @param minimum, Minimum value of the data points.
Expand All @@ -100,7 +104,7 @@
#' @param sdCi, a confidence interval for the standard deviation based on bootstrap samples.
#' Defaults to \code{FALSE}.
#' @param sdCiMethod, How should the confidence interval be computed? By default, we use an analytical approach (chi-square). The alternative option is `Bootstrap`
#' @param seMean, Standard error of the mean.
#' @param seMean, Standard error of the arithmetic mean.
#' Defaults to \code{FALSE}.
#' @param shapiroWilkTest, Shapiro-Wilk test
#' Defaults to \code{FALSE}.
Expand All @@ -121,126 +125,128 @@
#' Defaults to \code{FALSE}.
#' @param varianceCiMethod, How should the confidence interval be computed? By default, we use a analytical approach (chi-square). The alternative option is `Bootstrap`
Descriptives <- function(
data = NULL,
version = "0.95",
formula = NULL,
associationMatrixUse = "everything",
boxPlot = FALSE,
boxPlotBoxPlot = TRUE,
boxPlotColourPalette = FALSE,
boxPlotJitter = FALSE,
boxPlotOutlierLabel = FALSE,
boxPlotViolin = FALSE,
ciBootstrapSamples = 1000,
coefficientOfVariation = FALSE,
colorPalette = "colorblind",
correlation = FALSE,
correlationPlots = FALSE,
covariance = FALSE,
customHistogramPosition = "stack",
densityPlot = FALSE,
densityPlotCategoricalType = "count",
densityPlotSeparate = list(types = list(), value = ""),
densityPlotTransparency = 20,
densityPlotType = "density",
descriptivesTableTransposed = FALSE,
distributionAndCorrelationPlotDensity = FALSE,
distributionAndCorrelationPlotHistogramBinWidthType = "sturges",
distributionAndCorrelationPlotHistogramManualNumberOfBins = 30,
distributionAndCorrelationPlotRugMarks = FALSE,
distributionPlots = FALSE,
dotPlot = FALSE,
frequencyTables = FALSE,
frequencyTablesMaximumDistinctValues = 10,
heatmapDisplayValue = FALSE,
heatmapDisplayValueRelativeTextSize = 1,
heatmapHorizontalAxis = list(types = list(), value = ""),
heatmapLegend = FALSE,
heatmapPlot = FALSE,
heatmapStatisticContinuous = "mean",
heatmapStatisticDiscrete = "mode",
heatmapTileWidthHeightRatio = 1,
heatmapVerticalAxis = list(types = list(), value = ""),
intervalPlot = FALSE,
iqr = FALSE,
kurtosis = FALSE,
likertPlot = FALSE,
likertPlotAdjustableFontSize = "normal",
likertPlotAssumeVariablesSameLevel = FALSE,
mad = FALSE,
madRobust = FALSE,
maximum = TRUE,
mean = TRUE,
meanCi = FALSE,
meanCiLevel = 0.95,
meanCiMethod = "oneSampleTTest",
median = FALSE,
minimum = TRUE,
missing = TRUE,
mode = FALSE,
paretoPlot = FALSE,
paretoPlotRule = FALSE,
paretoPlotRuleCi = 0.95,
percentileValues = list(),
percentiles = FALSE,
pieChart = FALSE,
plotHeight = 320,
plotWidth = 480,
qqPlot = FALSE,
quantilesForEqualGroups = FALSE,
quantilesForEqualGroupsNumber = 4,
quartiles = FALSE,
range = FALSE,
scatterPlot = FALSE,
scatterPlotGraphTypeAbove = "density",
scatterPlotGraphTypeRight = "density",
scatterPlotLegend = TRUE,
scatterPlotRegressionLine = TRUE,
scatterPlotRegressionLineCi = TRUE,
scatterPlotRegressionLineCiLevel = 0.95,
scatterPlotRegressionLineType = "linear",
sd = TRUE,
sdCi = FALSE,
sdCiLevel = 0.95,
sdCiMethod = "chiSquaredModel",
seMean = FALSE,
shapiroWilkTest = FALSE,
skewness = FALSE,
splitBy = list(types = list(), value = ""),
statisticsValuesAreGroupMidpoints = FALSE,
stemAndLeaf = FALSE,
stemAndLeafScale = 1,
sum = FALSE,
valid = TRUE,
variables = list(types = list(), value = list()),
variance = FALSE,
varianceCi = FALSE,
varianceCiLevel = 0.95,
varianceCiMethod = "chiSquaredModel") {
data = NULL,
version = "0.95.1",
formula = NULL,
associationMatrixUse = "everything",
boxPlot = FALSE,
boxPlotBoxPlot = TRUE,
boxPlotColourPalette = FALSE,
boxPlotJitter = FALSE,
boxPlotOutlierLabel = FALSE,
boxPlotViolin = FALSE,
ciBootstrapSamples = 1000,
coefficientOfVariation = FALSE,
colorPalette = "colorblind",
correlation = FALSE,
correlationPlots = FALSE,
covariance = FALSE,
customHistogramPosition = "stack",
densityPlot = FALSE,
densityPlotCategoricalType = "count",
densityPlotSeparate = list(types = list(), value = ""),
densityPlotTransparency = 20,
densityPlotType = "density",
descriptivesTableTransposed = FALSE,
distributionAndCorrelationPlotDensity = FALSE,
distributionAndCorrelationPlotHistogramBinWidthType = "sturges",
distributionAndCorrelationPlotHistogramManualNumberOfBins = 30,
distributionAndCorrelationPlotRugMarks = FALSE,
distributionPlots = FALSE,
dotPlot = FALSE,
frequencyTables = FALSE,
frequencyTablesMaximumDistinctValues = 10,
heatmapDisplayValue = FALSE,
heatmapDisplayValueRelativeTextSize = 1,
heatmapHorizontalAxis = list(types = list(), value = ""),
heatmapLegend = FALSE,
heatmapPlot = FALSE,
heatmapStatisticContinuous = "mean",
heatmapStatisticDiscrete = "mode",
heatmapTileWidthHeightRatio = 1,
heatmapVerticalAxis = list(types = list(), value = ""),
intervalPlot = FALSE,
iqr = FALSE,
kurtosis = FALSE,
likertPlot = FALSE,
likertPlotAdjustableFontSize = "normal",
likertPlotAssumeVariablesSameLevel = FALSE,
mad = FALSE,
madRobust = FALSE,
maximum = TRUE,
meanArithmetic = TRUE,
meanCi = FALSE,
meanCiLevel = 0.95,
meanCiMethod = "oneSampleTTest",
meanGeometric = FALSE,
meanHarmonic = FALSE,
median = FALSE,
minimum = TRUE,
missing = TRUE,
mode = FALSE,
paretoPlot = FALSE,
paretoPlotRule = FALSE,
paretoPlotRuleCi = 0.95,
percentileValues = list(),
percentiles = FALSE,
pieChart = FALSE,
plotHeight = 320,
plotWidth = 480,
qqPlot = FALSE,
quantilesForEqualGroups = FALSE,
quantilesForEqualGroupsNumber = 4,
quartiles = FALSE,
range = FALSE,
scatterPlot = FALSE,
scatterPlotGraphTypeAbove = "density",
scatterPlotGraphTypeRight = "density",
scatterPlotLegend = TRUE,
scatterPlotRegressionLine = TRUE,
scatterPlotRegressionLineCi = TRUE,
scatterPlotRegressionLineCiLevel = 0.95,
scatterPlotRegressionLineType = "linear",
sd = TRUE,
sdCi = FALSE,
sdCiLevel = 0.95,
sdCiMethod = "chiSquaredModel",
seMean = FALSE,
shapiroWilkTest = FALSE,
skewness = FALSE,
splitBy = list(types = list(), value = ""),
statisticsValuesAreGroupMidpoints = FALSE,
stemAndLeaf = FALSE,
stemAndLeafScale = 1,
sum = FALSE,
valid = TRUE,
variables = list(types = list(), value = list()),
variance = FALSE,
varianceCi = FALSE,
varianceCiLevel = 0.95,
varianceCiMethod = "chiSquaredModel") {

defaultArgCalls <- formals(jaspDescriptives::Descriptives)
defaultArgs <- lapply(defaultArgCalls, eval)
options <- as.list(match.call())[-1L]
options <- lapply(options, eval)
defaults <- setdiff(names(defaultArgs), names(options))
options[defaults] <- defaultArgs[defaults]
options[["data"]] <- NULL
options[["version"]] <- NULL
defaultArgCalls <- formals(jaspDescriptives::Descriptives)
defaultArgs <- lapply(defaultArgCalls, eval)
options <- as.list(match.call())[-1L]
options <- lapply(options, eval)
defaults <- setdiff(names(defaultArgs), names(options))
options[defaults] <- defaultArgs[defaults]
options[["data"]] <- NULL
options[["version"]] <- NULL


if (!jaspBase::jaspResultsCalledFromJasp() && !is.null(data)) {
jaspBase::storeDataSet(data)
}
if (!jaspBase::jaspResultsCalledFromJasp() && !is.null(data)) {
jaspBase::storeDataSet(data)
}

if (!is.null(formula)) {
if (!inherits(formula, "formula")) {
formula <- as.formula(formula)
}
options$formula <- jaspBase::jaspFormula(formula, data)
}
optionsWithFormula <- c("associationMatrixUse", "colorPalette", "densityPlotSeparate", "distributionAndCorrelationPlotHistogramBinWidthType", "heatmapHorizontalAxis", "heatmapVerticalAxis", "likertPlotAdjustableFontSize", "meanCiMethod", "sdCiMethod", "splitBy", "variables", "varianceCiMethod")
for (name in optionsWithFormula) {
if ((name %in% optionsWithFormula) && inherits(options[[name]], "formula")) options[[name]] = jaspBase::jaspFormula(options[[name]], data) }
if (!is.null(formula)) {
if (!inherits(formula, "formula")) {
formula <- as.formula(formula)
}
options$formula <- jaspBase::jaspFormula(formula, data)
}
optionsWithFormula <- c("associationMatrixUse", "colorPalette", "densityPlotSeparate", "distributionAndCorrelationPlotHistogramBinWidthType", "heatmapHorizontalAxis", "heatmapVerticalAxis", "likertPlotAdjustableFontSize", "meanCiMethod", "sdCiMethod", "splitBy", "variables", "varianceCiMethod")
for (name in optionsWithFormula) {
if ((name %in% optionsWithFormula) && inherits(options[[name]], "formula")) options[[name]] = jaspBase::jaspFormula(options[[name]], data) }

return(jaspBase::runWrappedAnalysis("jaspDescriptives", "Descriptives", "Descriptives.qml", options, version, TRUE))
}
return(jaspBase::runWrappedAnalysis("jaspDescriptives", "Descriptives", "Descriptives.qml", options, version, TRUE))
}
2 changes: 1 addition & 1 deletion inst/Description.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description
name : "jaspDescriptives"
title : qsTr("Descriptives")
description : qsTr("Explore the data with tables and plots")
version : "0.95.0"
version : "0.95.1"
author : "JASP Team"
maintainer : "JASP Team <jasp-stats.org>"
website : "jasp-stats.org"
Expand Down
10 changes: 10 additions & 0 deletions inst/Upgrades.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,14 @@ Upgrades
from: "heatmapDisplayLegend"; to: "heatmapLegend"
}
}

Upgrade
{
functionName: "Descriptives"
fromVersion: "0.95.0"
toVersion: "0.95.1"

// this resulted from adding geometric and harmonic means
ChangeRename { from: "mean"; to: "meanArithmetic" }
}
}
Loading
Loading