Learn R Programming

trendtestR (version 1.0.1)

compare_distribution_by_granularity: Compare Normality across Granularity Levels / Vergleich der Normalverteilung je Granularitaet

Description

This function compares Shapiro-Wilk normality results between two granularity levels (e.g., daily vs. weekly data). It extracts diagnostics from test result objects (from [run_paired_tests()], [run_group_tests()] or [run_multi_group_tests()]) and displays them side-by-side. Optionally, QQ plots are generated to visualize distributional properties.

Usage

compare_distribution_by_granularity(
  res_day,
  res_week,
  plot = TRUE,
  save_plot = FALSE,
  save_path = "."
)

Value

A data frame with normality diagnostics for each granularity level.

factor

Group name(s)

granularity

Data granularity ("day" or "week")

shapiro_W

Shapiro-Wilk W statistic

shapiro_p

p-value of Shapiro-Wilk test

normal

Whether data are considered normal ("ja"/"nein")

levene_p

Levene's test p-value (if available)

bartlett_p

Bartlett's test p-value (if available)

Arguments

res_day

Result object from daily-level analysis. / Ergebnisobjekt der Tagesebene

res_week

Result object from weekly-level analysis. / Ergebnisobjekt der Wochenebene

plot

Logical. Whether to display QQ plots. / QQ-Plots anzeigen?

save_plot

Logical. Whether to save the plot as PNG. / Soll der Plot gespeichert werden?

save_path

Folder to save plot. Default is ".". / Speicherpfad fuer den Plot

Details

Diese Funktion vergleicht die Shapiro-Wilk-Ergebnisse der Normalverteilung zwischen zwei Granularitaetsebenen (z.B. Tages- vs. Wochen-Daten). Diagnosen aus Testergebnissen (z.B. von [run_paired_tests()], [run_group_tests()] oder [run_multi_group_tests()]) werden extrahiert und nebeneinander dargestellt. Optional werden QQ-Plots erzeugt, um Verteilungen zu visualisieren.

See Also

[run_paired_tests()], [run_group_tests()], [run_multi_group_tests()], [compare_monthly_cases]

Examples

Run this code
df <- data.frame(
  datum = seq.Date(from = as.Date("2024-01-01"), by = "day", length.out = 400),
  neue_faelle = rpois(400, lambda = 20)
)
res_day <- compare_monthly_cases(
  df = df,
  datum_col = "datum",
  value_col = "neue_faelle",
  years = c(2024,2025),
  months = 1:2,
  granularity = "day",
  shift_month = "none",
  agg_fun = "sum",
  save_plot = FALSE
)
res_week <- compare_monthly_cases(
  df = df,
  datum_col = "datum",
  value_col = "neue_faelle",
  years = c(2024,2025),
  months = 1:2,
  granularity = "week",
  shift_month = "none",
  agg_fun = "sum",
  save_plot = FALSE
)
compare_distribution_by_granularity(res_day, res_week)

Run the code above in your browser using DataLab