Code
x <- rnorm(100, 10, 5)
mean_x <- sum(x)/length(x)
print(mean_x)[1] 10.13319
The class Applied Methods aims to introduce students to the use of data and statistics to answers substantial questions and provide student with a strong and practical background in the analysis and visualisation of data with R. In addition to the classical statistical approach, the class is designed to provide an fundamental transferable skill to the use of data for data-driven report and in-depth analyses with quantitative data.
The course first covers the basics of R and RStudio, on statistics and data manipulation.
Second, the course dives into the data vizualisation and the production of high quality and resolution figures.
Third, the course propose an overview on how to use APIs and web-scrapping methods to get data from the web.
Fourth, the class then turns on more complexe analyses with sessions on regression models, interaction terms, and their associated visualization.
Fifth the class then provide key technical skkils on how to use R to create data driven reports, and create interactive data leaderbord.
Finally, the course ends with a introduction to quantitative text analyses, text data pre-processing, text statistics and the visualization of text data.
Overall, this course is designed to provide a strong practical guide to use quantitative data and produce data-driven transferable knowledge.
This course provides students with a comprehensive and practical foundation in applied quantitative methods using the statistical programming language R and the integrated development environment RStudio. It is designed for students seeking to develop transferable analytical skills for data-driven research, reporting, and decision-making across disciplines.
The course follows a progressive, hands-on approach structured around real-world data applications. It begins with foundational skills in data handling and statistical reasoning, then moves toward increasingly advanced analytical techniques and forms of output. Throughout, emphasis is placed on reproducibility, clarity of interpretation, and effective communication of results.
The philosophy of the class does not build on strong statistical background but instead uses applied approach and hands on approach to statistical analyses and data representation to perform valid statistical analyses with R. As such, the class build less on this type of content:
\[ \bar{X} = \frac{1}{n}\sum_{i=1}^{n} X_i \]
Than on this type of content:
x <- rnorm(100, 10, 5)
mean_x <- sum(x)/length(x)
print(mean_x)[1] 10.13319
The idea is to enable student to think about the data and how to use R to solve practical issue with the data (changing the structure, coding data, merging data set), and perform meaningful analyses that helps understand the social reality it aims to analyse.
By the end of the course, students will be able to:
Develop proficiency in data manipulation, cleaning, and transformation
Apply core statistical concepts to real datasets
Produce high-quality, publication-ready data visualizations
Collect and manage data from external sources such as APIs and websites
Conduct and interpret regression models
Analyze complex relationships including interaction effects
Create reproducible, data-driven reports
Build interactive data visualization tools
Perform introductory quantitative text analysis
More broadly, the course aims to equip students with transferable analytical skills that extend beyond R, including structured problem-solving, critical interpretation of quantitative evidence, and the ability to communicate findings effectively to both technical and non-technical audiences.
Each session strats Friday morning at 10h15 and ends at 15h with a one hour lunch breack in the middle. The session usually contain:
The course also provides various ressource that support students in their learning. These ressources are:
The class is graded based on two complementary types of evaluation. First, three in class assignment presented as problem sets will count for one third of the final grade. Second, students will provide group work and hand in data driven policy report with a reproducible R script, a Quarto document with the written report, a Shiny application providing an interactive visualization of their main findings and an in-class presentation of their work in progress during the two last weeks of the semester. Third, students will have an tailored oral exam on their own project. During this exam, student will be asked to answer substantive question on the interpretation of their analyses and lines of codes in their project.
The first assignment will present students with problem sets to resolve in a R script. These problem sets will focus on data manipulation, descriptive statistics and the graphical representation of variables and relationship aond variable.
The second assignment will ask students to use R to compute regression models, including interaction terms, and include visual representation of their results and substantive interpretation of these results.
For the third assignment, students will developp a small shiny application that presents descriptive and more advanced statistics.
The group projects are collaborative works aiming to provide reprocible data driven policy report on a delimited topics using administrative data. The goal of this project is to show that students know how to conduct quality data driven analyses, present their work in progress, provide reproducible material for their work, present their findings in a Quarto report and provide an interactive visualization of their findings.
The group project thus have four components:
During the two lasts sessions of the semester, students will present their work in progress in class presentation. Each group has 10 minute to present their work follow by 5 minutes of question from the audience, and 5 minutes of comments by the instructor.
Each group need to upload reproductible R script and associated folder structure so the instructor can replicate their analyses.
Each group is requiered to provide a Quarto document that presents their data driven report and the interpretation of their finding. They thus need to upload both a -qmd file and an .html file containing the compiled document.
Each group developps a small shiny application that provide an interactive presentation of their main results.
For group projects, students need to upload all the content of their work in a .zip folder in Moodle before the 13th of January 2027 at 20h.
During the exam session, tailored oral examination for each student regarding their own group project will be held. For these examination, no preparation is necessary, and students will be asked to provide justification on the code, the content and the interpretation of their group project.
The grading combine the evaluation and gives each student a unique grade based on these three types of evaluations.
| Session | Date | Title |
|---|---|---|
| 1 | September 18 | Introduction to R and RStudio |
| 2 | September 25 | Data manipulation and descriptive statistics |
| 3 | October 2 | Data visualization |
| - | October 9 | Dies Academic |
| 4 | October 16 | Assignment 1 Writing report with Quarto |
| 5 | October 23 | Hypothesis testing and introduction to regressions |
| 6 | October 30 | Interpret interaction terms in statistical models |
| - | November 6 | Reading week |
| 7 | November 13 | Assignment 2 Free code session on projects |
| 8 | November 20 | Introduction to text as data |
| 9 | November 27 | Introduction to ShinyR: Building shiny applications |
| 10 | December 4 | Assignment 3 Introduction to Webscrapping |
| 11 | December 11 | Group project presentations 2 Using Application Private Interfaces (API) |
| 12 | December 18 | Group project presentations 3 Class synthesis |
The first session introduces the course and provides an overview of its objectives, organization, evaluation, and learning resources. Students will then become familiar with R and the RStudio integrated development environment. They will learn the basic principles of working with R, including creating objects, calling functions, using packages, writing scripts, importing data, and inspecting datasets.
The session is structured as follows:
Session 2 is devoted to preparing data for meaningful analysis. Students learn how datasets are structured, how observations and variables are defined, and how codebooks document the meaning and coding of variables. The session introduces the principal tools provided by dplyr and tidyr for selecting, filtering, transforming, recoding, summarizing, reshaping, and combining data.
Particular attention is given to administrative data, where information may be distributed across several datasets, collected at different levels of analysis, or organized according to administrative rather than analytical needs. Students also learn to identify missing values, duplicates, inconsistent categories, and unsuccessful joins.
The session is structured as follows:
filter(), select(), mutate(), and summarise().dplyr, tidyr, and data import.Session 3 introduces data visualization as both an analytical and communication tool. Students learn to use ggplot2 and its layered grammar of graphics to explore distributions, compare groups, and represent relationships between variables.
The session distinguishes exploratory graphics, which help analysts understand their data, from explanatory graphics, which communicate a finding to a particular audience. Students learn how to select an appropriate graphical representation, improve labels and visual appearance, and avoid misleading data representations.
The session is structured as follows:
At the end of the session, you should be able to produce plots as shown bellow
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(RSwissPos)Loading required package: pxR
Loading required package: stringr
Loading required package: reshape2
Loading required package: jsonlite
Loading required package: plyr
------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
------------------------------------------------------------------------------
Attaching package: 'plyr'
The following objects are masked from 'package:dplyr':
arrange, count, desc, failwith, id, mutate, rename, summarise,
summarize
Loading required package: rjson
Attaching package: 'rjson'
The following objects are masked from 'package:jsonlite':
fromJSON, toJSON
library(ggplot2)
library(ggpubr)
Attaching package: 'ggpubr'
The following object is masked from 'package:plyr':
mutate
data <- getSwissvotes()Please cite: Swissvotes (Year). Swissvotes – die Datenbank der eidgenössischen Volksabstimmungen.
data <- data %>%
mutate(gov_support = ifelse(br.pos==1, as.numeric(volkja.proz),
ifelse(br.pos==2, 100 - as.numeric(volkja.proz), NA)),
date= as.Date(datum, "%d.%m.%Y"))
fig <- ggarrange(
ggplot(data[data$rechtsform!=5,])+
geom_bar(aes(x=rechtsform), width=.3, color = "black", fill = "darkblue", alpha = .3)+
scale_x_continuous(breaks = c(1,2,3,4),
labels = c("Mandatory referendums","Facultative referendums", "Initiative", "Counter proposals"))+
xlab("Institution type")+
labs(title = "Number of allot by institutional type",
subtitle = "Example of a bar plot")+
ylab("N")+
theme_minimal(),
ggplot(data)+
geom_histogram(aes(x=gov_support), color = "black", fill = "lightgrey")+
geom_density(aes(x=gov_support))+
xlab("% of support for the government position")+
ylab("N")+
labs(title = "Share of support for the government's position",
subtitle = "Example of an historam with density line.")+
theme_minimal(),
ggplot(data)+
geom_point(aes(x=date, y=gov_support))+
geom_smooth(aes(x=date, y=gov_support), method="lm", color = "grey", fill="lightblue")+
theme_minimal()+
labs(title = "Evolution of support for the government's position",
subtitle = "Example of scatter plot with regression line")+
xlab("Date")+
ylab("% of support for the government position"),
ggplot(data[data$rechtsform!=5,])+
geom_boxplot(aes(x=as.factor(rechtsform), y=gov_support))+
scale_x_discrete(breaks = c(1,2,3,4),
labels = c("Mandatory referendums","Facultative referendums", "Initiative", "Counter proposals"))+
xlab("Institution type")+
labs(title = "Share of support for the government's position \n by institution type",
subtitle = "Example of a cross categorical boxplot")+
ylab("% of support for the government position")+
theme_minimal(),
nrow=4, ncol=1
)`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning: Removed 146 rows containing non-finite outside the scale range
(`stat_bin()`).
Warning: Removed 146 rows containing non-finite outside the scale range
(`stat_density()`).
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 146 rows containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 146 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 142 rows containing non-finite outside the scale range
(`stat_boxplot()`).
figggplot2 components.The first part of Session 4 is devoted to Assignment 1. Students complete a series of problems involving data inspection, manipulation, descriptive statistics, and visualization. The assignment assesses their ability to navigate an unfamiliar dataset and use R to answer clearly defined analytical questions.
The second part introduces Quarto as a system for combining written analysis, R code, tables, and figures in a reproducible report. Students create and render a short report in which results are generated directly from the underlying code.
The session is structured as follows:
Session 5 introduces statistical inference through practical policy questions. Students learn how analysts move from describing observed data to assessing whether an observed difference or relationship is compatible with random variation.
The session introduces hypotheses, confidence intervals, p-values, and common forms of statistical error without relying heavily on mathematical derivations. It then presents simple linear regression as a way to summarize and analyze the relationship between an outcome and an explanatory variable. Emphasis is placed on substantive interpretation and on the distinction between statistical association and causation.
The session is structured as follows:
lm()Session 6 extends linear regression to relationships that vary across groups or contexts. Students learn that the association between an explanatory variable and an outcome may depend on a third variable. These conditional relationships are represented using interaction terms.
Because interaction coefficients can be difficult to interpret directly, the session emphasizes predictions and visualization. Students compare additive and interactive models, calculate predicted outcomes for meaningful combinations of variables, and communicate the resulting patterns in substantive language.
The session is structured as follows:
The first part of Session 7 is devoted to Assignment 2. Students estimate and interpret regression models, including interaction terms, and communicate their findings through tables, visualizations, and substantive written interpretations.
The second part introduces Application Programming Interfaces, or APIs. Students learn how APIs provide structured and reproducible access to data made available by public institutions. They examine endpoints, parameters, requests, responses, status codes, and JSON data before using R to retrieve and transform data from a public API.
The session is structured as follows:
Session 8 introduces written documents as a source of quantitative data. Students learn how administrative reports, parliamentary debates, consultation responses, policy documents, and other textual materials can be transformed into structured datasets.
The session presents the principal stages of a quantitative text-analysis workflow: importing documents, cleaning text, tokenizing documents, removing non-informative terms, counting words, comparing documents, and visualizing textual patterns. Particular attention is paid to the analytical consequences of preprocessing decisions and to the limitations of automated interpretation.
The session is structured as follows:
Session 9 introduces Shiny as a framework for transforming an R analysis into an interactive web application. Students learn how an application can allow users to filter data, choose indicators, explore results, and generate customized visualizations without directly interacting with the underlying code.
The session focuses on the basic architecture of a Shiny application: the user interface, the server function, inputs, outputs, and reactive relationships. Students progressively transform a static visualization into a small interactive public-data dashboard.
The session is structured as follows:
app.R fileggplot2 visualizationsThe first part of Session 10 is devoted to Assignment 3. Students develop a small Shiny application that presents descriptive statistics, model results, or interactive visualizations based on a supplied dataset.
The second part introduces web scraping as a method for collecting structured information from web pages when a direct download or API is not available. Students learn the elementary structure of HTML documents, the role of CSS selectors, and the use of rvest to extract text, links, and tables.
The session also addresses responsible data collection. Students are expected to consult website terms of use, respect access restrictions, limit the frequency of requests, and avoid collecting personal or sensitive information.
The session is structured as follows:
read_html()html_elements()rvest functions.Using Application Programming Interfaces {#sec16}
The first part of Session 11 is devoted to group project presentations. Groups present their research question, data, analytical strategy, preliminary results, and the planned structure of their Quarto report and Shiny application. The presentations provide an opportunity to receive feedback before the final submission.
The remainder of the session is organized as a project coding workshop. Student groups work on their data-driven policy projects with support from the instructor.
The session is structured as follows:
The final session completes the group project presentations and provides a synthesis of the course. Students review the complete data-analysis workflow, from formulating a policy question and obtaining data to cleaning, analysis, visualization, and communication.
The remainder of the session is organized as a project coding workshop. Student groups work on their data-driven policy projects with support from the instructor. At the end of the session, we will review the scope o the oral examinaion and conclude the class with students feedbacks.
The session is structured as follows: