R4VN

Version 1.6

R4VN 1.6 adds egenvar() for flexible row-wise and group-wise variable generation, distdata() for distribution/probability calculations, and distlearn() for interactive distribution teaching. It also incorporates the CRAN resubmission changes concerning package availability checks, examples, and user-controlled random seeds.

R4VN provides short commands for health-data management, descriptive and inferential statistics, epidemiological analysis, regression, publication Tables, export, and graphs.

Active-data workflow

patient <- opendata("patient.dta")
usedf(patient)

genvar(age2 = age^2)
tab1(sex, smoking, by = c(province, agegroup))
sum1(age, bmi, by = c(sex, agegroup))
describe(age2)

View(patient)

Because patient was activated with usedf(patient), R4VN data-editing commands update the visible object as well as the active data.

Extended variable generation

egenvar() complements genvar() with row-wise and grouped calculations.

egenvar(min_score = rowmin(q1:q5),
        max_score = rowmax(q1:q5),
        mean_score = rowmean(q1:q5))

egenvar(mean_bmi = mean(bmi), z_bmi = z(bmi), by = sex)

Probability distributions

distdata() acts as a compact probability calculator. For discrete distributions, a single x automatically returns equality and both tail probabilities. distlearn() launches the interactive R4VN Distribution Learning Studio.

distdata("binomial", n = 10, x = 3, p = .20)
distdata("normal", mean = 100, sd = 15, lower = 85, upper = 115)

# Interactive teaching app
distlearn("binomial")

Publication tables

tb <- tab(
  vars = vars(c.age, b2.sex, q.bmi),
  by = hypertension,
  test = TRUE,
  or = TRUE,
  event = "Yes",
  show = FALSE
)

tabexport(tb, export = c("html", "docx", "xlsx"), file = "report")

One-command survival report

tabsurv() uses a context-sensitive reporting profile by default. A grouped call produces descriptive outcomes, Kaplan-Meier estimates, automatically selected time-point risks, overall incidence rates, group comparisons, RMST, a publication-ready graph, and export-ready tables. Adding vars also activates Cox models and proportional-hazards diagnostics.

Interpretation and the detailed life table are intentionally off by default. Enable them explicitly with interpretation = TRUE and lifetable = TRUE. For cumulative incidence at selected times, use the direct shorthand cuminc = c(6, 12, 24); this is 1-KM for ordinary survival and the Aalen-Johansen CIF for competing risks.

surv_result <- tabsurv(
  followup, death,
  by = treatment,
  vars = vars(c.age, b2.sex, stage, treatment),
  data = patient,
  failure = 1
)

# Optional narrative interpretation and event-time Kaplan-Meier life table.
surv_detail <- tabsurv(
  followup, death, by = treatment, data = patient, failure = 1,
  interpretation = TRUE, lifetable = TRUE
)
surv_detail$lifetable

# Cumulative incidence at 6, 12, and 24 follow-up units.
surv_ci <- tabsurv(
  followup, death, by = treatment, data = patient, failure = 1,
  cuminc = c(6, 12, 24), report = "custom"
)
surv_ci$cuminc

# Export every non-empty table from the same command.
tabsurv(
  followup, death, by = treatment, data = patient,
  failure = 1, export = "docx", file = "survival-report.docx"
)

# Use the concise R4VN 1.5 defaults when an older workflow requires them.
tabsurv(followup, death, by = treatment, data = patient,
        report = "custom")

Run help(package = "R4VN") or ?R4VN_examples for the complete cookbook.

One-command meta-analysis report

tabmeta() accepts either study-level estimates or raw outcome summaries. For a binary outcome, the four 2-by-2 cells can be supplied directly; OR is inferred when no effect selector is specified. The default automatic profile adds the appropriate prediction, few-study inference, publication-bias and sensitivity modules, figures, and export-ready tables.

meta_result <- tabmeta(
  data = trials, study = study,
  a = event_treat, b = non_event_treat,
  c = event_control, d = non_event_control,
  subgroup = region,
  moderator = vars(c.year, design)
)

meta_result$estimates$overall
meta_result$tables$Statistical_tests
meta_result$tests$overall
meta_result$tests$heterogeneity
meta_result$tables$Subgroup_test
meta_result$tables$Meta_regression
meta_result$tables$Publication_bias
meta_result$tables$Small_sample_inference

The HTML Viewer remains the complete report. With plot=TRUE, the forest plot is also drawn in the R/RStudio Plot pane by default; use plot_display=c("forest", "funnel", "trimfill") or plot_display="all" to populate Plot history. The forest plot has separate headed Estimate (95% CI) and Weight columns, with Weight on the far right, and uses round parentheses. For direct a,b,c,d input, plot(m, show_abcd=TRUE) displays the four cells. Labelled subgroup codes use their value labels, and the Viewer adds one clearly titled forest plot per subgroup level. The same overall and subgroup forest plots are added to R/RStudio Plot history, where Previous/Next reviews them. Meta-regression output prints Intercept in full and uses moderator labels when available. Each subgroup result contains the pooled-effect test and the full heterogeneity test, with confidence intervals for I-squared and tau-squared when estimable. For publication, these results are transposed so statistics are rows and the few subgroup levels are columns; $subgroup_long retains tidy one-row-per-group data. Effect and meta-regression estimates use two decimals by default; change this consistently with digit=. Restricting xlim clips outlying graphical intervals with arrows while retaining exact numerical annotations. Prediction intervals remain in the result but are not drawn by default. Figures expose journal controls for fonts, colors, symbols, shading, axes, contours, labels, size, and resolution, while engine_args provides direct advanced metafor controls.

Set interpretation=TRUE for sectioned interpretation of the pooled result, heterogeneity, prediction interval, subgroup/moderator tests, small-study effects, few-study inference, influence, leave-one-out, and cumulative evidence.

Use ?tabmeta for complete examples covering OR/RR/RD, subgroup analyses, moderators, meta-regression, cumulative meta-analysis, small-study effects, few-study inference, figures, and direct report export.

R4VN 1.5 workflow additions

R4VN 1.5 keeps the compact R4VN syntax while adding quick vector data entry, label-aware hierarchical grouping, richer distribution diagnostics, Bonferroni and other post-hoc/effect-size inference, combined labelled graph panels with xline/yline, and model postestimation.

# Quick data entry: no data.frame() is required first
genvar(weight = c(29, 26, 13, 23, 23, 25, 17, 22))
ghist(x = weight, normal = TRUE, xline = mean(weight, na.rm = TRUE))

# One convention for nested grouping: final variable is the inner group
ttest(weight, by = vars(province, sex), effect = TRUE)
normtest(vars = vars(weight, age), by = vars(province, sex))

# Postestimation uses the most recently fitted R4VN model
logistic(outcome, c.age, i.sex, data = d)
margins(at = at(age = seq(30, 60, 5)))
marginsplot()
predict(newvar = phat, type = "probability")

# Regression diagnostics are opt-in
m <- regress(score, c.age, c.bmi, data = d, diagnosis = TRUE)
predict(m, type = "standardized")
predict(m, type = "studentized")
predict(m, type = "leverage")
predict(m, type = "cooksd")
predict(m, type = "dfbetas", term = "age")