Skip to content

Instantly share code, notes, and snippets.

View graebnerc's full-sized avatar

Claudius Graebner-Radkowitsch graebnerc

View GitHub Profile
@graebnerc
graebnerc / VisualizationScript.R
Last active April 26, 2024 15:10
The script we developed during the session on visualization. See also the lecture script on the course homepage for more explanations.
library(DataScienceExercises)
library(ggplot2)
library(scales)
# Bubble plot------
gdp_data <- DataScienceExercises::gdplifexp2007
# In the following, lines with changes are marked with '# <---'
# 1st step: empty list
gdp_plot <- ggplot()
@graebnerc
graebnerc / FunctionDefinition.R
Created April 19, 2024 12:03
The example of a function definition discussed in the recap session on April 19.
# A step-by-step solution for the first function task of the "Basics" tutorial
# Goal: define a function that computes the sample variance of a vector
# Note: there are many strategies to develop functions; here we start by first
# writing the code that solves our problem for one particular case outside the
# function, and then generalize this code in a function.
# First step: think about the starting point for your function. In our case:
# we start with a vector containing some numbers, because this is from what
@graebnerc
graebnerc / Recap1-Exercises-Template.R
Created April 18, 2024 09:52
Template file for working on the exercises for the first recap session.
# remotes::install_github("graebnerc/DataScienceExercises")
library(DataScienceExercises)
library(tibble)
# # Exercise 1: Basic object types I---------
#
# 1. Create a vector containing the numbers `2`, `5`, `2.4` and `11`.
#
# 2. Replace the second element with `5.9`.
#
@graebnerc
graebnerc / BasicObjectTypes-Solutions.R
Created April 18, 2024 09:30
Solutions to the intermediate exercises of the session on basic object types.
# Task 1: Intermediate exercises I===============
# Create a vector containing the numbers 2, 5, 2.4 and 11.
vec_task_1 <- c(2, 5, 2.4, 11)
# What is the type of this vector?
typeof(vec_task_1)
# Transform this vector into the type integer. What happens?
typeof(vec_task_1)
@graebnerc
graebnerc / Session-04-Script.R
Created March 25, 2024 21:53
Data Science Using R (Spring 2024) - Session 4
# Session Script on Advanced object types (Spring Semester 2024)
# Digression
ff <- factor(c("F", "M", "M"), levels = c("F", "M", "D"))
attributes(ff) # See the class attribute 'factor'
typeof(ff) # It still remains an integer type...
class(ff) # but the class was changed
# Factors--------------------
@graebnerc
graebnerc / Session-02-Script.R
Last active March 24, 2024 08:05
Data Science Using R (Spring 2024) - Session 2
# This is the script that we developed during the session on March 21, 2024
# 1. Basic commands-----------
# This is an addition:
2 + 4
4 - 9 # This is substraction
4/9
3*9
2**3
@graebnerc
graebnerc / inclass-regression-solution.R
Created June 22, 2023 15:13
In-class solutions for the recap session.
here::i_am("inclass-regression-solution.R")
library(here)
library(dplyr)
library(tidyr)
library(data.table)
library(ggplot2)
# Step 1: import data----------
reg_data <- data.table::fread(here("data/reg_data_1.csv")) %>%
as_tibble()
@graebnerc
graebnerc / #T17T18: Lecture notes
Last active June 25, 2023 22:58
The examples used during session 17 and 18 on multiple linear regression, as well as possible solutions to the exercises.
Contains solutions to the exercises as well as the code used to create the relevant figures in the slides.
The code assumes a standard folder structure and might need to be adjusted to your case.
@graebnerc
graebnerc / #T14: Lecture script
Last active June 2, 2023 09:32
The script used during session 14 on sampling theory, as well as possible solutions to the exercises.
This is the script we used during the lecture. For a version that is better documented but essentially covers the same issues, see the tutorial on Monte Carlo Simulations:
https://euf-datascience-spring23.netlify.app/tutorial/mcs/pubdir/onlinecontent.html
This contains the script developed during the recap session.