Skip to content

Instantly share code, notes, and snippets.

### Thanks to metafor-project.org
### https://www.metafor-project.org/doku.php/plots:forest_plot_revman
### You will want to use png or pdf or tif to save this res 350, width=3196, height=1648
### Import Dataset
pacman::p_load(readxl,
metafor,
library(ggplot2)
library(ggdist)
library(MetBrewer)
library(dplyr)
pal = met.brewer(name="VanGogh1", n=7, type="discrete")
set.seed(123)
pacman::p_load(dplyr,
brms,
patchwork,
ggplot2)
# Install rmsb v0.2 to use cmdstan
pacman::p_load_gh("harrelfe/rmsb")
# Data
pacman::p_load(rmsb,
dplyr,
magrittr,
ggdist,
tidyr,
brms)
# Data
a <- c(rep(0,0), rep(1,3), rep(2,5), rep(3,5), rep(4,25), rep(5,40), rep(6,24))
b <- c(rep(0,2), rep(1,3), rep(2,9), rep(3,17), rep(4,33), rep(5,18), rep(6,18))
@arthur-albuquerque
arthur-albuquerque / gist:af0a79551f3da001781f4afa25f44e70
Last active January 17, 2023 20:33
survival random slope-intercept
pacman::p_load(survival, brms, simsurv, splines2)
n <- 100
h = c(rep("A", n/4),
rep("B", n/4),
rep("C", n/4),
rep("D", n/4))
covs <- data.frame(id = 1:n, race_final = stats::rbinom(n, 1L, 0.5),
pacman::p_load(extraDistr, dplyr, purrr, tidyr, ggplot2, forcats, ggdist, patchwork)
set.seed(123)
N = 100
mean_ARR = rhnorm(N, sigma = 0.02)
d =
tibble(mu = mean_ARR) |>
pacman::p_load(rms, marginaleffects, brms, dplyr, tidybayes)
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"))
dd = sample_frac(gusto, size = 0.1, weight = tx)
@arthur-albuquerque
arthur-albuquerque / gist:1de97d450e6f157b158736d8540d12bf
Last active October 5, 2022 16:06
bayesian constrained partial proportion odds model
# Install/load packages -----
pacman::p_load(ggdist,
dplyr,
tidyr,
rmsb,
stringr,
gt,
flextable)
## Data ----
pacman::p_load(brms,
tidybayes,
ggplot2,
dplyr,
tidyr,
gt,
stringr)
#define function to calculate mode
# https://www.statology.org/mode-in-r/
@arthur-albuquerque
arthur-albuquerque / gist:77bf1978bfa4157fb522685a1736ae12
Last active September 20, 2022 20:23
ATE vs. average patient
library(rms)
#define function to calculate mode
# https://www.statology.org/mode-in-r/
find_mode <- function(x) {
u <- unique(x)
tab <- tabulate(match(x, u))
u[tab == max(tab)]
}