Skip to content

Instantly share code, notes, and snippets.

@arthur-albuquerque
arthur-albuquerque / gist:1bacfb71cda93843303de3af6264c52e
Last active September 16, 2022 19:05
Unit-level ORs, RRs, ARRs without interaction
library(marginaleffects)
library(rms)
load(url(
"https://github.com/vincentarelbundock/modelarchive/raw/main/data-raw/gusto.rda"
))
gusto <- subset(gusto, tx %in% c("tPA", "SK"))
gusto$tx <- factor(gusto$tx, levels = c("tPA", "SK"))
pacman::p_load(rio, here, brms, dplyr, ggplot2, tidyr)
remotes::install_github("stan-dev/cmdstanr")
d = import(here("/Users/arthur/Downloads/il6_paper.xlsx"))
d =
d |>
mutate(phecode = as.factor(phecode),
yi = log(OR),
# Calculate mean effect size and SE in log scale
@arthur-albuquerque
arthur-albuquerque / gist:eacdc2a10d6429dae1dbcbacb6c2e4ef
Created August 9, 2022 12:43
ordered beta vs. cumulative logistic regression
# data from https://cran.microsoft.com/snapshot/2022-07-18/web/packages/ordbetareg/vignettes/package_introduction.html
pacman::p_load(ordbetareg,
brms)
data("pew")
model_data <- select(pew,therm,age="F_AGECAT_FINAL",
sex="F_SEX_FINAL",
income="F_INCOME_FINAL",
ideology="F_IDEO_FINAL",
# Install/Load package
pacman::p_load(brms,
tidybayes,
ggplot2,
dplyr,
tidyr,
patchwork)
# Data from
@arthur-albuquerque
arthur-albuquerque / AME_brms.md
Created August 6, 2022 16:43
"Average marginal effect" in brms

The objective of this code is to compare outputs from multiple R packages on the “average marginal effect” with a random-effect model fitted with brms.

pacman::p_load(dplyr,
               tidyr,
               tidybayes,
               brms,
               marginaleffects,
               brmsmargins,
               emmeans)
@arthur-albuquerque
arthur-albuquerque / .md
Created July 26, 2022 23:04
Average Treatment Effect: marginal ARR, RR, and OR with G-formula and the delta method

Make some data

library(MASS)
library(marginaleffects)
library(dplyr)
library(broom)
@arthur-albuquerque
arthur-albuquerque / .md
Created July 26, 2022 20:07
Adjusted Marginal Risk Ratio with G-formula through marginaleffects::comparisons()

Make some data

library(MASS)
library(marginaleffects)
library(dplyr)
library(broom)
@arthur-albuquerque
arthur-albuquerque / .md
Last active July 24, 2022 15:24
Adjusted Marginal Odds Ratio with G-formula through marginaleffects::comparisons()

Make some data

library(MASS)
library(marginaleffects)
library(dplyr)
library(broom)
@arthur-albuquerque
arthur-albuquerque / gist:3452e22d7c6f81f80915236b7b1ab8f2
Created July 24, 2022 15:14
Adjusted Marginal Odds Ratio with G-formula through marginaleffects::comparisons()
``` r
# Code based on
# https://gist.github.com/mattansb/8dd0fb5a0be86e958ef6bdc4c49ac02c?permalink_comment_id=4241354#gistcomment-4241354
# https://gist.github.com/arthur-albuquerque/1a126043fef15b55792392e91f969f83
library(MASS)
library(marginaleffects)
library(dplyr)
#>
#> Attaching package: 'dplyr'