Skip to content

Instantly share code, notes, and snippets.

View StefanThoma's full-sized avatar

StefanThoma StefanThoma

View GitHub Profile
# Connect existing rstudio cloud environment to github using R
install.packages("usethis")
# Add authentication information: Use your GitHub user name and associated email address.
usethis::use_git_config(user.name = "StefanThoma",
user.email = "stefan.thoma@roche.com")
# Initiate git:
usethis::use_git()
@StefanThoma
StefanThoma / download.data.R
Last active January 18, 2023 10:29
download (example) data from github
# set paths and data names
external.path <-
"https://github.com/pharmaverse/intro-to-r-for-sas-programmers-workshop/blob/main/data"
# should we check first?
check <- TRUE
local.path <- ("data")
subdir <- file.path(local.path, "save_data")
f <- function(x) (dchisq(x, 1) + dchisq(x, 2))/2
curve(f, from = 0, to = 10)
pf <- function(x) integrate(f, 0, x)$value
# test
pf(5.14)
@StefanThoma
StefanThoma / multiple testing adjustment
Last active April 29, 2022 18:42
Example of critical p-values for three basic multiple testing adjustments.
library(tidyverse, jmv, ggplot2)
library(ggthemes)
data <- read_csv(file = "https://raw.githubusercontent.com/methodenlehre/data/master/alkohol-aggression.csv") %>%
mutate(alkoholbedingung = factor(alkoholbedingung,
levels = c("kein_alkohol", "placebo", "anti_placebo", "alkohol")))
# 2. ANOVA inkl. Post-hoc Tests und Helmert-Kontrasten mit jamovi-Syntax
jmv_res <- jmv::ANOVA(
######## Miminal working example
# Bin nicht sicher, ob Du alle packages hier brauchst.
pacman::p_load(tidyverse, nlme, ggplot2, ggthemes)
therapie <- read_csv("https://raw.githubusercontent.com/methodenlehre/data/master/therapie.csv") %>%
mutate(id = as.factor(id),
bedingung = as.factor(bedingung))
@StefanThoma
StefanThoma / visualise.grade.R
Last active July 6, 2021 12:22
Visualise grades of a class in R.
pacman::p_load(ggplot2, ggthemes)
# Grade needed to pass
passing.grade <- 4
# BinSize (increment of grades)
binsize <- .25
# Input grades
noten <- c(2.75, 2.5, 6.00, 3.25, 4.25, 1, 3.75, 6, 6, 5.00, 3.75, 5.25, 5.75, 4.25, 5.50, 4.50, 5.50, 4.25, 4.25, 5.25, 5.25, 2.50, 4.75, 4.75, 6.00, 5.25, 4.75, 5.25, 3.75, 3.50, 5.75, 2.50, 4.75, 4.50, 5.25, 5.00, 5.00, 5.50, 5.25, 5.25, 5.00, 3.50, 3.75, 5.00, 4.75, 4.75, 5.25, 5.50, 3.50, 3.75, 3.50, 5.25, 5.00, 5.25, 4.75, 4.75, 4.75, 4.00, 3.25, 5.00)
@StefanThoma
StefanThoma / create.if.necessary.R
Last active July 6, 2021 12:20
Check if File exists. If not, create it and save.
filename <- paste("file", ".csv", sep = "")
if(filename %in% list.files()){
# Load files
df <- read_csv(filename)
} else{
# create df