Skip to content

Instantly share code, notes, and snippets.

View strengejacke's full-sized avatar
⁉️
Focusing

Daniel strengejacke

⁉️
Focusing
View GitHub Profile
@strengejacke
strengejacke / ggpredict_glmmTMB.R
Created December 23, 2020 21:41
ggpredict and glmmTMB
library(glmmTMB)
library(ggeffects)
data("Salamanders")
m1 <- glmmTMB(
count ~ mined + (1 | site),
zi = ~ mined,
family = poisson,
data = Salamanders
)
@strengejacke
strengejacke / gist:adc5e0494d8aa687f5921409a408285c
Created August 6, 2020 07:38
Explained variance for models with and without intercept
library(parameters)
library(performance)
library(ggplot2)
set.seed(123)
x <- 3 + rnorm(200)
y <- 4 + .5 * x + rnorm(100)
dat <- data.frame(x, y)
ggplot(dat, aes(x, y)) +
# Second Generation P-value
p_delta <- function(lb, ub, delta_lb, delta_ub) {
# special case: infinite CI and H0 bounds in the same direction
if ((delta_lb == -Inf & lb == -Inf) | (delta_ub == Inf & ub == Inf)) {
return(1)
}
# usual case: non-point CI & non-point Ho
@strengejacke
strengejacke / table-performance.R
Created May 22, 2020 10:29
performance comparison of table functions in R
See https://twitter.com/malte_grosser/status/1262862749794795520?s=20
``` r
table2 <- function(x) {
x_u <- if (is.factor(x)) sort(x[!duplicated(x)]) else sort(unique(x))
x_f <- factor(x, levels = as.character((x_u)), exclude = NULL)
t_x_f <- tabulate(x_f)
names(t_x_f) <- as.character(x_u)
t_x_f
}
library(tidyverse)
library(parameters)
library(lme4)
library(see)
# data generation -----------------------
set.seed(123)
n <- 5
b <- seq(1, 1.5, length.out = 5)