Skip to content

Instantly share code, notes, and snippets.

View ABohynDOE's full-sized avatar

Alexandre Bohyn ABohynDOE

View GitHub Profile
@ABohynDOE
ABohynDOE / cLDA.R
Created April 15, 2025 09:03
Constrainted longitudinal data analysis (cLDA) in R. Example with the `fev_data` from the `mmrm` package.
library(tidyverse)
library(nlme)
library(rms)
library(lmerTest)
library(emmeans)
data("fev_data", package = "mmrm")
data <- fev_data %>%
as_tibble() %>%
mutate(ARMCD = as.character(ARMCD)) %>%
@ABohynDOE
ABohynDOE / hr_over_covariate.R
Last active September 13, 2024 12:52
Generate a plot of the Hazard Ratio of between groups over different levels of a continuous covariate
library(survival)
library(dplyr)
library(modelbased)
library(ggplot2)
# Recode the status into 0 for censoring
data <- survival::lung %>%
select(time, status, age, sex) %>%
mutate(
status = status - 1, # Status is coded as 1=dead 2=alive
@ABohynDOE
ABohynDOE / ggplot_to_svg.R
Created August 30, 2024 15:01
Save a `ggplot` object to a an editable `svg` file
# Install necessary packages if not already installed
install.packages("svglite")
install.packages("ggplot2")
# Load the ggplot2 library
library(ggplot2)
# Create a basic boxplot of Sepal Length by Species
p <- ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_boxplot() +
@ABohynDOE
ABohynDOE / pool_imputation.R
Created May 14, 2024 07:26
Two different ways of pooling a list of models fitted on imputed data and then generating a summary table of the model using ´tbl_regression´
library(mice)
library(gtsummary)
# impute the data
df_imputed <- mice::mice(trial, m = 2, seed = 123)
# build the model list
imputed_model_list <- purrr::map(
1:df_imputed$m,
~ lm(age ~ marker + grade, complete(df_imputed, .x))
@ABohynDOE
ABohynDOE / pipenv_cheat_sheet.md
Created September 21, 2022 13:12 — forked from bradtraversy/pipenv_cheat_sheet.md
Pipenv cheat sheet for common commands

Pipenv Cheat Sheet

Install pipenv

pip3 install pipenv

Activate

pipenv shell
@ABohynDOE
ABohynDOE / kravchuck.py
Created August 30, 2022 13:06
Compute the Kravchuck matrix (i.e. the matrix of Kravchuck polynomials)
from math import comb
import numpy as np
def kravchuck(k: int, x: int, n: int, q: int) -> int:
"""
Kravchuck polynomials of the form K_k(x,n,q) where k = 0,...,n and q
must be a prime power.
"""
k_values = [

Create a new project

poetry new <project-name>

Add a new package

Use -D or --dev to add it to the dev dependencies

potry add <package>

Remove a package

@ABohynDOE
ABohynDOE / collatz.py
Created July 9, 2021 09:23
Collatz conjecture
import numpy as np
import matplotlib.pyplot as plt
def collatz(x):
if x % 2 == 0:
return(x/2)
else:
return((3*x)+1)