Seb’s blog
  • About
  • Posts
Categories
All (99)
ANOVA vs t-Tests (1)
Algorithmic study design (4)
Linear model vs neural nets (4)
Mishmash (7)
Observable (1)
Psychiatry (2)
Python (15)
Quarto (1)
R (61)
Self-study (7)
Sustainibility (8)
survival (1)

Blog posts

Moran process

R
  • Malignant clone outcompetes own cell type
  • Malignant clone outcompetes other needed cell types
  • Malignant clone causes inflammation
  • Malignant clone does other “bad” things…
Sep 16, 2025

Assessing linearity in logistic regression

R
https://chatgpt.com/share/6851c5ad-9c08-8013-ad26-d03c0de42079
Jul 30, 2025

 

Left censored predictors

R
set.seed(1)
library('tidyverse')

n <- 1000000
beta <- 0.1
dat <- tibble(x = runif(n, min = -6, max = 0),
              slope = runif(n, 0, 0.1),
              lql = -3, #…
Jul 1, 2025

Model diagnostics in logistic regression

R
  • Previous related post
  • Background from chatGPT
Jun 19, 2025

Zahlenmauern

R
# i: row of Zahlenmauer
# j: j-th entry of Zahlenmauer

i_j_to_ii <- function(i, j) {
  ii <- 0
  if(i > 1) {
    ii <- ii + sum(1:(i - 1))
  }
  return(ii + j)
}

ii_to_i_j …

Apr 26, 2025

Genetic algorithm

R
  • We want to fit a model with parameters to data
  • Given: Data points and a function to calculate a loss function for a given parameter set
  • What we don’t have: Derivative of…
Mar 12, 2025

Profiling in R and Julia

R
library('tidyverse')
Dec 22, 2024

ODE benchmark: R, Python and Julia

R
library('tidyverse')

library('reticulate')
use_condaenv('sbloggel')

library('JuliaCall')
julia_setup(JULIA_HOME = '/Users/seb/.juliaup/bin/')

set.seed(1)
Dec 17, 2024

 

Saving output from R terminal

R
In order to save output from within R, the sink commmand usually can do the job. Have a look also at the help page.
Dec 16, 2024

 

Comparing counts

R
We can construct an approximate, pragmatic statistical test. The test statistic \(k = x_2 - x_1\) follows approximately (asymptotically with growing \(\lambda_1\) and \(\lamb…
Dec 6, 2024

 

Neue Klimaabschätzungen

Sustainibility
Ergo: Wenn es gelänge die Sahara komplett aufzuforsten, würde das ungefähr 10% des von Menschen emittierten CO2 gleich wieder binden!
Nov 13, 2024

 

Python Enhancement Proposals – Style guide, Type hints and Docstring Conventions

Python
Python Enhancement Proposals (PEPs)
Nov 11, 2024

 

Dal

Mishmash
Für ein schmackhaftes Dal für 3 Personen:
Nov 8, 2024

 

Parameter class in Python

Python
class param:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            setattr(self, key, value)
            
p = param(a=2, b = 3)
print('a ='…
Nov 8, 2024

 

Speed of ODE solving in R and Python

Python
import time

# Start the timer
start_time = time.time()

# Your code block
# Example:
for i in range(1000000):
    pass

# End the timer
end_time = time.time()

# Calculate…
Nov 7, 2024

 

Speed of ODE solving in R and Python

R
# Load the deSolve package
library(deSolve)

# Define the SIR model
sir_model <- function(time, state, parameters) {
  with(as.list(c(state, parameters)), {
    dS <- -beta *…
Nov 1, 2024

 

Regal

Mishmash
  • Innenmaß 336 mm
  • Außenholz 15 mm
  • Innenholz 12 mm
  • Tiefe oben 415 mm
  • Tiefe unten 390 mm
  • Oct 25, 2024

     

    Energy consumption of artificial intelligence

    R
    Oct 24, 2024

     

    Ventilation

    Mishmash
    Sustainibility
    How much water in liters is removed from a flat with a volume if the air in the flat is changed?
    Oct 23, 2024

     

    Energie Haus

    Sustainibility
    Der Quotient aus beiden:
    Oct 23, 2024

    gglimpse or tibblet, tlimpse or dfsum

    R
    All in all, I like the summarytools package – however – I don’t like its heavy dependencies. Here, I want to create a lightweight alternative!
    Sep 30, 2024

     

    Hypothesis testing in mixed linear models with a factorial design

    R
    dat <- expand_grid(time = factor(1:3), group = factor(1:2), ID = 1:5) |> 
      mutate(hh = paste('time', time, 'group', group, sep = '_'))
    
    X <- model.matrix(~ hh + factor(ID), …
    Sep 30, 2024

     

    Pi mal Daumen - Elektromobilität

    R
    Sustainibility
    (J_per_kWh <- 1e3 * 3.6e3)
    [1] 3600000
    Sep 30, 2024

    Energie

    Sustainibility
    Also PV-Fläche pro Person benötigt:
    Sep 24, 2024

    Testing the package summarytools

    R
    Data Frame Summary
    iris
    Dimensions: 150 x 5
    Duplicates: 1
    Sep 17, 2024

    Power analysis

    R
    draw_sample <- function(x, n) {
      ii <- sample(x, size = n, replace = TRUE)
      x[ii]
    }
    
    
    calc_p_value <- function(effect_size, n) {
      dd <- tibble(x = rnorm(n), 
               …

    Aug 5, 2024

     

    VS Code and Jupyter shortcuts

    R
    Jul 23, 2024

    Elena’s paper

    Python
    Started to play with Elena’s paper: Link to the paper
    Jul 23, 2024

     

    Eisen

    R
    • Kinder 8-10 mg pro Tag
    • Erwachsene 10-15 mg pro Tag
    • Quelle
    Jul 9, 2024

     

    Video test

    Mishmash
    Videos are about 300 kB per second -> 20 MB per minute
    Jul 8, 2024

    Fitting nonlinear models with stats::nls and nlme::nlme

    R
    set.seed(1)
    library('tidyverse')
    Jun 22, 2024

     

    WebAssembly experiment

    R
    // Configure the Monaco Editor's loader require.config({ paths: { 'vs': 'https://cdn.jsdelivr.net/npm/monaco-editor@0.47.0/min/vs' } });
    May 3, 2024

    Legends in ggplot2

    R
    Blog post
    May 3, 2024

    Type I and type II errors

    R
    nr_of_trials <- 100
    
    calc_p <- Vectorize(
      function(effect_size, n) {
        y1 <- rnorm(n)
        y2 <- rnorm(n, effect_size)
        t.test(y1, y2)$p.value
      }
    )
    
    calc_p(1, 10)
    [1…

    Apr 22, 2024

     

    Clone size distributions

    R
    import numpy as np
    import pandas as pd
    import random
    Mar 27, 2024

    Simulating data in Python

    Python
    100 rows × 5 columns
    Jan 22, 2024

    Plotnine and sample data sets from statsmodels

    Python
    import statsmodels.api as sm
    cars = sm.datasets.get_rdataset("cars")["data"]
    from plotnine import ggplot, aes, geom_point
    p = ggplot(cars, aes("speed", "dist")) + geom_point…

    Jan 15, 2024

    Understanding competing risks

    R
    Self-study
    set.seed(2)
    library(tidyverse)
    library(survival)
    Nov 19, 2023

     

    Quantifizierung von Alkoholintoxikation

    R
    Link zu Jan Drehers Beitrag
    Oct 17, 2023

    Understanding the multivariate normal distribution

    R
    Link to question at stackexchange
    Oct 10, 2023

    Decision trees

    R
    library('tidyverse')
    library('rpart')
    library('rpart.plot')
    set.seed(1)
    Oct 7, 2023

    Gradient descent

    R
    library('tidyverse')
    set.seed(1)
    Oct 7, 2023

     

    Book study notes - Competing Risks and Multistate Models with R

    R
    survival
    Here, I want to collect some study notes of the book by Beyersmann et al. “Competing Risks and Multistate Models with R” - (Link).
    Sep 28, 2023

     

    Book series - use R

    R
    Self-study
    The “Use R!” book series seems to contain a lot of books that are worthwile reading! Link to the book series.
    Sep 28, 2023

    Subfigures in quarto

    R
    Quelle: Link
    Sep 25, 2023

     

    Testing Observable

    Observable
    library('tidyverse')
    ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
    ✔ dplyr     1.1.2     ✔ readr     2.1.4
    ✔ forcats   1.0.0     ✔…
    Sep 25, 2023

    SVM code example

    R
    Self-study
    Inspired from this blog post.
    Sep 12, 2023

     

    Algorithmic study design – possible approaches

    Algorithmic study design
    • Model of research environment (e. g. university hospital) and simulate a lot of studies in this environment
    • Continue Elena’s work
    • Use clinicaltrials.gov data set as…
    Sep 7, 2023

     

    Tensorflow Decision Forests

    Python
  • Source
  • Aug 28, 2023

    Two-Way-ANOVA with and without interaction vs. individual t-tests

    R
    ANOVA vs t-Tests
    Often, the effect of different interventions is to be studied. This can be done by comparing individual sets of interventions (e. g. drug A vs. placebo and drug B…
    Aug 28, 2023

    Simulating a clinical study with a mechanistic model in the background

    Algorithmic study design
    • Increased doses for leukemia in comparison to “standard” doses with some substance X is to be studied
    • Randomized, controlled, double-blind clinical trial
    • Groups:
      • standard…
    Aug 22, 2023

     

    Generation of in silico studies

    Algorithmic study design
    Variable type: character
    Aug 21, 2023

     

    Algorithmic study design – white paper

    Algorithmic study design
    Currently, the design of clinical studies is carried out mostly manually by domaine experts. Here, we want to do first steps to think about how the design of experiments…
    Aug 21, 2023

     

    Leave-one-out cross-validation in Python

    Python
    Linear model vs neural nets
    • Look at the cars dataset that is shipped in base R
    • Fit models
      • for each model, leave out one data point
      • predict the response value for that data point based on the model…
    Aug 11, 2023

    Cars dataset and tidymodels

    R
    Linear model vs neural nets
    set.seed(1)
    library('tidymodels')
    ── Attaching packages ────────────────────────────────────── tidymodels 1.1.0 ──
    ✔ broom        1.0.4     ✔ recipes      1.0.6
    ✔…
    Aug 8, 2023

    Leave-one-out cross-validation in R

    R
    Linear model vs neural nets
    • Fit “straight” models: linear model, neural net with 2 layers with 3 perceptrons each
    • Perform “Leave-one-out-cross-validation” (LOOC)
    • Calculate mean absolute prediction…
    Aug 8, 2023

     

    Regularization in R

    R
  • ridge regression
  • lasso regression
  • elastic net
  • Aug 5, 2023

     

    Getting to know mlr3

    R
    Link to package
    Aug 4, 2023

    Getting to know tidymodels

    R
  • Tutorials by Julia Silge: Link
  • Blog post criticising tidymodels: Link, written by this person
  • Aug 4, 2023

    Kaplan Meier plots

    R
    Goal: draw facetted Kaplan-Meier-plots with p-value
    Aug 3, 2023

    Koga Original

    Reducing image file size with ImageMagick

    R
    Mishmash
    Aug 3, 2023

     

    Approximating Pi

    R
    This is a really pointless post about approximating \(\pi\), inspired by this post.
    Jul 23, 2023

    Bicycle comparison

    R
    Jul 23, 2023

     

    First pytorch tutorial

    Python
  • Link to tutorial
  • Jul 21, 2023

     

    Starting with fastai

    Python
  • Link to the book
  • Jul 20, 2023

    The iris dataset

    R
    library('tidyverse')
    library('lme4')
    Jul 12, 2023

     

    Easier publishing

    Quarto
  • File “/usr/local/bin/pq”:
  • Jul 12, 2023

    Model diagnostics for logistic regression

    R
    library('tidyverse')
    library('faraway')
    set.seed(1)
    Jul 12, 2023

    Pie chart

    R
    To build a simple pie chart:
    Jul 12, 2023

     

    Ideas for new posts

    Mishmash
    Jul 10, 2023

     

    Managing python versions in RStudio

    Python
    Start Jupyter from terminal:
    Jul 5, 2023

    Python graphics

    Python
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.get_dataset_names()
    ['anagrams', 'anscombe', 'attention', 'brain_networks', 'car_crashes'…
    Jul 5, 2023

    Exploring the Python library statsmodels

    Python
    • Link
    import matplotlib.pyplot as plt
    import numpy as np
    
    import statsmodels.api as sm
    
    data = sm.datasets.statecrime.load_pandas().data
    murder = data['murder']
    X = data[[…

    Jul 4, 2023

    Bivariate dataset - linear regression and neural net

    R
    Linear model vs neural nets
    set.seed(1)
    library('neuralnet')
    library('tidyverse')
    library('knitr')
    • dist is the stopping distance (not what I said today)
    cars |> 
      ggplot(aes(dist, speed)) + …

    Jul 3, 2023

     

    Python pandas

    Python
  • pandas - Tutorials
  • Access R in Python chunk:
  • Jul 3, 2023

    Specifying mixed effects in lme4

    R
    • \(n\) individuals (\(i = 1, 2, .., n\)) are measured \(m\) times (\(j = 1, 2, ..., m\)) pre-intervention (denoted \(y_{ij}^{pre}\)) and post-intervention (denoted \(y_{ij}…
    Jun 8, 2023

    Interesting R packages

    R
    Link
    Mar 17, 2023

    Python study notes

    Self-study
    Python
    This section contains my study notes on the official python tutorial.
    Mar 17, 2023

     

    Coursera Deep Learning Specialization

    Self-study
    \[V_t = \beta V_{t-1} + (1 - \beta) \theta_t\] * this corresponds approximately to averaging over \(\frac{1}{1-\beta}\) entries
    Mar 17, 2023

     

    Self-study: Deep Learning by Goodfellow et al.

    Self-study
    \(B_n\): partition of entire sample space \(\rightarrow \sum p(B_n) = 1\) \[ P(A) = \sum_n P(A \cap B_n) \]
    Mar 17, 2023

    Self-study: McElreath - Statistical Rethinking

    Self-study
    • Website of the book
    • Statistical rethinking lectures on youtube
    Mar 17, 2023

    How bad are bananas

    Sustainibility
    Recently, I have come a across a book that I find really wonderful: “How bad are bananas” by Mike Berners-Lee Berners-Lee (2020).
    Feb 27, 2023

    Manual colors in ggplot2

    R
    After several instances of “relearning” how to use custom colour palettes in R, I have written this post in order to save some time when I want to use custom colours the…
    Feb 21, 2023

    Strange behavior in ggplot2

    R
    I have asked a question related to this issue on stackoverflow and I am providing the plots on this page. Here is the question on stackoverflow:
    Feb 2, 2023

    SIRS model dynamics

    R
    Solution in terms of parameters in red.
    Jan 19, 2023

     

    Sustainibility data

    Sustainibility
    Die Welt liefert also ca. 3.76e+04 mal so viel Energie wie von den Menschen verbraucht wird.
    Jan 10, 2023

    Contribution plots

    R
    library('tibble')
    library('ggplot2')
    library('RColorBrewer')
    library('plotly')
    
    Attaching package: 'plotly'
    The following object is masked from 'package:ggplot2':
    
       …

    Jan 5, 2023

    R interfaces to trial registries

    R
    library('tidyverse')
    ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
    ✔ dplyr     1.1.2     ✔ readr     2.1.4
    ✔ forcats   1.0.0     ✔…

    Oct 25, 2022

    Simulate time to-event-data

    R
    In this post, two methods to draw from a survival time distribution defined by an arbitrary hazard function are demonstrated. First, some central equations of survival…
    Oct 25, 2022

    Model meadow

    R
    Oct 19, 2022

    Retrieving and plotting COVID-19 data

    R
    The COVID19 package allows to conveniently retrieve statistical data about the COVID-19 pandemy. Here, the data for Germany are retrieved and two exploratory plots are…
    Oct 16, 2022

    Leo’s project

    R
    In hematological cancers, blood stem cells can be transferred to a patient after chemothery. The blood stem cells may proliferate in the patient and populate the patient’s…
    Oct 16, 2022

    SIR-like model with deSolve in deterministic and stochastic version

    R
    Here, an model based on the SIR model is presented in a deterministic version and in a non-deterministic version. For solving the ODEs (deterministic version) and the…
    Oct 4, 2022

     

    Antipsychotics

    Psychiatry
    • D_1/D_5-Gruppe: Signalübertragung durch stimulatorisches G-Protein –> cAMP hoch
    • D_2/D_3/D_4-Gruppe: Signalübertragung durch hemmendes G-Protein –> cAMP runter
    Sep 8, 2022

    Timeline

    R
    format_ods_data_frame <- 
      function(dat, 
               colnames = TRUE, 
               type_definition = TRUE) {
        
        result <- dat
        
        if (colnames) {
          result <- …
    Sep 8, 2022

    Psychopharmaca and time

    Psychiatry
    library('lattice')
    library('readxl')
    
    dat <- read_excel('Psychopharmaka_Data.xlsx')
    
    
    dat <- dat[order(dat$Jahr), ]
    
    
    stripplot(order(dat$Jahr) ~ Jahr, data = dat, 
           …

    Sep 8, 2022

     

    Chess ressources

    Mishmash
    Link
    Sep 8, 2022

    Humidity

    Sustainibility
    Conclusion: Airing once with an indoor temperature of 20 degress Celsius with a relative humidity of 50% and an outdoor temperature of 0 degrees Celsius with a relative…
    Sep 8, 2022

    SIR model

    R
    Here I want to show some sample calculations using the SIR model (https://simple.wikipedia.org/wiki/SIR_model…
    Jul 19, 2022
    No matching items
       
      • View source
      Cookie Preferences