Skip to content

Instantly share code, notes, and snippets.

View strengejacke's full-sized avatar
⁉️
Focusing

Daniel strengejacke

⁉️
Focusing
View GitHub Profile
@strengejacke
strengejacke / Positron-Setup
Last active November 9, 2024 09:43
Positron-Setup
Positron Version: 2024.11.0 (system setup) build 140
Code - OSS Version: 1.93.0
Commit: e0d844b031f95acbf89f234a2cce2af9b6721f6c
Date: 2024-10-31T14:14:22.699Z
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.22631
@strengejacke
strengejacke / gist:bd14a299a806d5e2d03347d5c274a7f9
Created May 6, 2024 06:14
Compile R Report (HTML/PDF/Word file from R scripts)
#' ---
#' title: "Compile Report"
#' author: ""
#' date: ""
#' ---
#' Comments that are to be displayed as normal text are marked with `#'`
#' at the beginning of the line. Comments that are to be displayed as
#' code are marked with `#` at the beginning of the line.
library(easystats)
library(palmerpenguins)
library(lme4)
library(ggplot2)
# data generation -----------------------
data(penguins)
d <- penguins |>
@strengejacke
strengejacke / intersectional.R
Created June 9, 2023 06:13
Example for building intersectional strata
easystats::install_latest(force= TRUE)
library(datawizard) # data wrangling and preparation
library(parameters) # model summaries
library(glmmTMB) # multilevel modelling
# sample data set
data(efc, package = "ggeffects")
efc <- efc |>
# numeric to factors, set labels as levels
@strengejacke
strengejacke / .lintr
Last active October 29, 2024 23:21
VS Code setup for R
// save to windows-user directory
linters: with_defaults(object_name_linter = NULL,
object_length_linter(50),
commented_code_linter = NULL,
object_usage_linter = NULL,
line_length_linter(120),
cyclocomp_linter = cyclocomp_linter(50))
@strengejacke
strengejacke / keybindings.json
Last active August 6, 2022 16:53
keybindings for VS Code using R
[
{
"description": "R Build Docs",
"key": "ctrl+shift+d",
"command": "r.document",
"when": "resourceLangId == 'r'"
},
{
"description": "R Pipe Operator",
"key": "ctrl+shift+m",
@strengejacke
strengejacke / predictions.R
Last active May 21, 2022 09:01
Approach of different packages to generate predicted values
library(insight)
library(datawizard)
library(modelbased)
library(ggeffects)
library(emmeans)
library(marginaleffects)
data(efc, package = "ggeffects")
efc <- data_to_factor(efc, select = "c161sex")
model <- lm(neg_c_7 ~ barthtot + c160age * c161sex, data = efc)
library(easystats)
#> # Attaching packages: easystats 0.4.3
#> ✔ insight 0.17.0.6 ✔ datawizard 0.4.0.14
#> ✔ bayestestR 0.12.1 ✔ performance 0.9.0.3
#> ✔ parameters 0.17.0.9 ✔ effectsize 0.6.0.7
#> ✔ modelbased 0.8.0 ✔ correlation 0.8.0.1
#> ✔ see 0.7.0.2 ✔ report 0.5.1.1
library(emmeans)
library(marginaleffects)
@strengejacke
strengejacke / ordinal predictors.R
Last active September 26, 2022 09:45
Example showing different ways of modelling ordinal predictors, and how their model summaries and predictions look like.
library(ggeffects)
library(parameters)
library(brms)
income_options <- c("below_20", "20_to_40", "40_to_100", "greater_100")
income <- factor(sample(income_options, 100, TRUE),
levels = income_options, ordered = TRUE)
mean_ls <- c(30, 60, 70, 75)
ls <- mean_ls[income] + rnorm(100, sd = 7)
dat <- data.frame(income, ls)
@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
)