Skip to contents

'Wrapper Function for ggstatsplot::gghistostats and ggstatsplot::grouped_gghistostats to generate Histogram.'

Usage

jjhistostats(
  data,
  dep,
  grvar,
  typestatistics = "parametric",
  centralityline = TRUE,
  changebinwidth = FALSE,
  binwidth = 1.1,
  resultssubtitle = TRUE,
  normalcurve = FALSE
)

Arguments

data

The data as a data frame.

dep

One or more continuous numeric variables for which histograms will be created. Multiple variables will be displayed in separate panels.

grvar

Optional grouping variable to create separate histograms for each level of this variable (grouped analysis).

typestatistics

Type of statistical test for normality assessment. 'parametric' uses Shapiro-Wilk test, 'nonparametric' uses Anderson-Darling test, 'robust' uses robust normality tests, 'bayes' provides Bayesian analysis.

centralityline

Whether to display a vertical line indicating the measure of central tendency (mean for parametric, median for nonparametric).

changebinwidth

Whether to manually specify the bin width. If FALSE, automatic bin width calculation will be used.

binwidth

Manual bin width for histogram. Only used when changebinwidth is TRUE. Smaller values create more bins, larger values create fewer bins.

resultssubtitle

Whether to display statistical test results as subtitle in the plot, including normality test results and descriptive statistics.

normalcurve

Whether to overlay a normal distribution curve on the histogram for comparison with the theoretical normal distribution.

Value

A results object containing:

results$todoa html
results$plot2an image
results$plotan image

Examples

# \donttest{
# Load test data
data(jjhistostats_test_data)
#> Warning: data set ‘jjhistostats_test_data’ not found

# Basic histogram
jjhistostats(
  data = jjhistostats_test_data,
  dep = "age_years",
  typestatistics = "parametric",
  normalcurve = TRUE
)
#> Error in jjhistostats(data = jjhistostats_test_data, dep = "age_years",     typestatistics = "parametric", normalcurve = TRUE): argument "grvar" is missing, with no default

# Multiple histograms
jjhistostats(
  data = jjhistostats_test_data,
  dep = c("age_years", "tumor_size_mm", "bmi"),
  centralityline = TRUE,
  resultssubtitle = TRUE
)
#> Error in jjhistostats(data = jjhistostats_test_data, dep = c("age_years",     "tumor_size_mm", "bmi"), centralityline = TRUE, resultssubtitle = TRUE): argument "grvar" is missing, with no default

# Grouped histogram by disease stage
jjhistostats(
  data = jjhistostats_test_data,
  dep = "psa_level",
  grvar = "disease_stage",
  typestatistics = "nonparametric",
  changebinwidth = TRUE,
  binwidth = 2.0
)
#> Error: object 'jjhistostats_test_data' not found
# }