| layout | title | nav_order | permalink |
|---|---|---|---|
default |
Home |
1 |
/ |
This is a collection of custom R functions designed to automate common analyses and improve workflow efficiency.
Load any function directly into your R session using:
source("<function-URL>")Replace <function-URL> with the corresponding raw GitHub link provided for each function.
Extracts and reports statistical regression model outputs with publication-quality formatting. The function is compatible with linear, generalized linear, and mixed-effects models, and generates templates for output interpretation. For documentation, see link.
# Fit regression model
model <- glm(formula = outcome ~ predictor1 + predictor2,
data = df,
family = <gaussian/binomial/poisson... etc.>)
# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/main/report_mod_out_knitr.R")
# Run function
report_mod_out_knitr(model,
exp = TRUE,
params = names(coef(model)),
n_digits = 3,
caption_input = "Association between outcome, predictor1 and predictor2",
knitr_output = TRUE)Computes absolute fitted values from regression models for specific parameter combinations. For documentation, see link.
# Fit regression model
mod <- glm(formula = y ~ a + bx,
data = df,
family = <gaussian/binomial/poisson... etc.>)
# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/regression/report_mod_out_knitr.R")
# Run function
# e.g., report fitted values at point x = 4
calc_abs_effect_val(model = mod,
parms = (e.g., "(Intercept) + a + b * 4"),
exp = FALSE,
n_digits = 3)# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/epi/prob_to_rate.R")
prob_to_rate(time = 1,
prob = 0.7) # returns 1.203973# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/epi/rate_to_prob.R")
rate_to_prob(time = 1,
rate = 1.203973) # returns 0.7# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/epi/conv_trans_prob.R")
conv_trans_prob(tp = 0.3,
ratio = 1 / 12) # This converts an annual 30% TP to a monthly TP of 2%This is the logical complement to %in%. Returns TRUE for elements not present in a vector. Elements could be single values or vectors.
# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/misc/notin.R")
c("a", "b") %!in% c("b", "c", "d") # returns: TRUE, FALSEThis function generates a comprehensive missingness report for data frames, including counts and percentages by variable.
# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/misc/report_missing.R")
report_missing(your_dataframe)# Call function
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/misc/calc_salary.R")
calc_salary(val = 75, # salary value
rate = "hourly", # value above is hourly rate
days = 5, # days worked
fte = 1) # full-time equivalent, 100%
# Returns: "Annual salary = 156,000.0"Chris Adoph's Theme (Modified)
# Call theme
source("https://raw.githubusercontent.com/Mohamed-Albirair/my-R-functions/refs/heads/main/R/viz_ggplot/theme_caviz.R")
# add `theme_caviz` to your `ggplot` script