This is the R script repository of the "Data Analysis 1a: Exploration" course in the 2018/2019 Fall term, part of the MSc in Business Analytics at CEU. For the previous years, see the 2015/2016 Winter, 2016/2017 Fall and 2017/2018 Fall branches.
Please find in the syllabus
folder of this repository.
Please bring your own laptop and make sure to install the below items before attending the first class:
- Install
R
from https://cran.r-project.org - Install
RStudio Desktop
(Open Source License) from https://www.rstudio.com/products/rstudio/download - Register an account at https://github.com
- Enter the following commands in the R console (bottom left panel of RStudio) and make sure you see a plot in the bottom right panel and no errors in the R console:
install.packages('ggplot2')
library(ggplot2)
ggplot(diamonds, aes(cut)) + geom_bar()
Optional steps I highly suggest to do as well before attending the class if you plan to use git
:
-
Bookmark, watch or star this repository so that you can easily find it later
-
Install
git
from https://git-scm.com/ -
Verify that in RStudio, you can see the path of the
git
executable binary in the Tools/Global Options menu's "Git/Svn" tab -- if not, then you might have to restart RStudio (if you installed git after starting RStudio) or installed git by not adding that to the PATH on Windows. Either way, browse the "git executable" manually (in somebin
folder look for theegit
executable file). -
Create an RSA key (optionally with a passphrase for increased security -- that you have to enter every time you push and pull to and from GitHub). Copy the public key and add that to you SSH keys on your GitHub profile.
-
Create a new project choosing "version control", then "git" and paste the SSH version of the repo URL copied from GitHub in the pop-up -- now RStudio should be able to download the repo. If it asks you to accept GitHub's fingerprint, say "Yes".
-
If RStudio/git is complaining that you have to set your identity, click on the "Git" tab in the top-right panel, then click on the Gear icon and then "Shell" -- here you can set your username and e-mail address in the command line, so that RStudio/git integration can work. Use the following commands:
$ git config --global user.name "Your Name" $ git config --global user.email "Your e-mail address"
Close this window, commit, push changes, all set.
Find more resources in Jenny Bryan's "Happy Git and GitHub for the useR" tutorial if in doubt or contact me.
- General overview of the R ecosystem: slides
- Basic math operations: 1.R
- Numbers, strings, vectors: 1.R
- Functions: 1.R
- Basic plots: 1.R
- Basic stats: 1.R
- Intro to data frames: 1.R
Suggested reading: Hadley Wickham: Style guide. In Advanced R.
Homework: DataCamp
- Recap on data frames: 2.R
- Loading data from text and Excel files: 2.R
- Variable types, conversion between variable types: 2.R
Homework: DataCamp
- Recap on data frames: 3.R
- Creating new variables: 3.R
- Finding missing values 3.R and duplicates 3.R
- Intro into
data.table
: 3.R - Summarizing data, aggregates: 3.R
- Combining datasets: 3.R
Homework: DataCamp
- Recap on
data.table
summaries: 4.R - Recap on merging datasets: 4.R
- Creating new variables - numeric to factor: 4.R
- Creating new variables - numeric to numeric: 4.R
- Demo: multiple summaries: 4.R
Homework: DataCamp
- Recap on
data.table
summaries and merging datasets: 5.R - Introduction to data visualization with
ggplot2
: 5.R - Scales and coordinate transformations: 5.R
- Plotting numeric variables: 5.R
- Recap on
factor
s: 5.R - Facets: 5.R
- Stacked and clustered bar charts: 5.R
- Histograms and density plots: 5.R
- Popular and custom themes: 5.R
Suggested reading:
- Saghir Bashir and Dirk Eddelbuettel: Getting Started in R: Tinyverse Edition
- Garrett Grolemund and Hadley Wickham: Data Visualization. In. R for Data Science
- Hadley Wickham: The Layered Grammar of Graphics
- Winston Chang: R Graphics Cookbook
Homework: DataCamp
Ideas to practice using the hotels
dataset:
- plot a barplot on the number of hotels per popularity
- plot a barplot on the number of hotels per popularity by feeding a
data.table
summary toggplot2
- plot a histogram on the prices in EUR
- plot a histogram on the prices in EUR with a bindwidth of 100 EUR
- plot a histogram on the prices in EUR split by popularity
- plot a boxplot on the prices below 1000 EUR split by city type
- plot a boxplot on the prices in EUR split by popularity
- plot a scatterplot on the prices in EUR and the distance from city center
- add a linear model to the previous plot
- Introduction to random sampling: 6.R
- Introduction to writing loops: 6.R
- Estimating the standard error: 6.R
- Confidence intervals: 6.R
- t-test: 6.R
- Required sample size calculations: 6.R
Suggested reading / materials:
- Visualizing uncertainty with
ggpplot2
- teaching examples - Data generator Shiny app for statistical tests
- A/B Testing in R class on Datacamp
Homework: DataCamp
Ideas to practice using the hotels
dataset:
hotels <- readRDS(url('http://bit.ly/CEU-R-hotels-2018-merged'))
- create a new
pricecat
variable based onavg_price_per_night
: "cheap" below 100 EUR, "expensive" above - check if expensive hotels are rated above cheap
- plot the difference of ratings between cheap and expensive hotels including the results of a
t.test
- create a new
popularity
variable with 3 categories from the number of bookings (0-3, 4-7, 8-10) - check if popular hotels are higher rated than less popular hotels
- plot the difference
File a GitHub ticket.