+ - 0:00:00
Notes for current slide
Notes for next slide

Statistics with R:

Data Wrangling | Data Visualisation | Basic Modelling

Arif P. Sulistiono


Kelas Data on 28 Oct. 2021, 4 Nov. 2021, and 11 Nov. 2021
mof.dac

1

About me

An employee of the Republic of Indonesia’s Ministry of Finance. Funded by the Indonesia Endowment Fund for Education ("Lembaga Pengelola Dana Pendidikan"), at the moment, on study leave to join a PhD program in the School of Economics, the University of Nottingham with research interests in Indonesia's government bonds market and their bondholders' behaviour. Also a research assistant at tracktheeconomy.ac.uk.

2

Functions

  • Rows: filter(), arrange(), recode(), slice(), slice_min(), slice_max(), slice_head(), slice_tail()
  • Columns: select(), relocate(), rename()
  • Both: count(), mutate(), transmute()

  • Analysing: group_by(), summarise()/summarize(), rowwise()
  • Merging: left_join(), inner_join(), right_join(), full_join(), semi_join(), anti_join()
  • Manipulating: ifelse()
  • Dealing with NA: fill(), replace(), zoo::na.approx(), drop_na()
  • Combining: rbind(), bind_rows, cbind(), bind_cols
  • Reshaping: pivot_wider(), pivot_longer()

  • Scatter plot: geom_point()
  • Line chart: geom_line()
  • Bar plot: geom_bar(), geom_col()
  • Box plot: geom_boxplot()
  • Histogram: geom_histogram()

  • Loading the dataset: read_csv() or read_excel(),
  • Correlation: Hmisc::rcorr(as.matrix())
  • Summary: stargazer()
  • Linear regression: lm(), lm_robust(), dynlm()
  • Reporting: broom::tidy()
  • Saving: write_csv()
3

%>%

Pipe operator: ...then

4

Prerequisites

Clean the environment

rm(list=ls())
ls()
5

Prerequisites

Clean the environment

rm(list=ls())
ls()

Install the package & load the library

install.packages("tidyverse")
library(tidyverse)
6

Prerequisites

Clean the environment

rm(list=ls())
ls()

Install the package & load the library

install.packages("tidyverse")
library(tidyverse)

Set the working directory

getwd()
setwd("/Users/arifpras/OneDrive - The University of Nottingham/BB_KelasData")
dir()
7

Data

Ages

library(readxl)
op_ages <- read_excel(path = "/Users/arifpras/OneDrive - The University of Nottingham/BB_KelasData/KelasData/00_Datasets/OP_all.xlsx", sheet = "OP_ages")
DT::datatable(op_ages, fillContainer = FALSE, options = list(pageLength = 3))
8

Data

Powers

library(readxl)
op_powers <- read_excel(path = "/Users/arifpras/OneDrive - The University of Nottingham/BB_KelasData/KelasData/00_Datasets/OP_all.xlsx", sheet = "OP_powers")
DT::datatable(op_powers, fillContainer = FALSE, options = list(pageLength = 3))
9

Data Visualisation

10

Datasaurus

Never trust summary statistics alone.

Source: library(datasauRus); https://github.com/Z3tt/TidyTuesday/tree/master/plots/2020_42

11

ggplot2

Basic elements:

  • Data: data = ...
  • Geometries: geom_
  • Aesthetics: aes(x = ..., y = ..., ...)
  • Scales: scale_
  • Statistical transformations: stat_
  • Coordinate system: coord_
  • Facets: facet_
  • Visual themes: theme()
12

Decision trees

Source: https://www.data-to-viz.com

13

Line plot

15

Animating bar plot


16

Animating line plot


17

Practical sessions

Source: https://arifpras.github.io/WranglingViz/

18

Basic Modelling

19

Initial specifications

 

    Salest=α0+α1Chapterst+α2LastMoviet+α3VIX indext+υt Salest=β0+β1Pagest+β2LastMoviet+β3VIX indext+ϵt

20

Dataset

library(readxl)
op_sales <- read_excel(path = "/Users/arifpras/OneDrive - The University of Nottingham/BB_KelasData/KelasData/00_Datasets/OP_all.xlsx", sheet = "OP_sales")
DT::datatable(op_sales, fillContainer = FALSE, options = list(pageLength = 3))
21

Dependent variable

22

Independent variables

23

Let's practice!
24

Practical sessions

Source: https://arifpras.github.io/BasicModelling/

25

Thank you for listening.

All teaching materials are available on https://github.com/arifpras/KelasData

Slides created via the R packages: xaringan and gadenbuie/xaringanthemer.
The chakra comes from remark.js, knitr, and R Markdown.

26

Acknowledgements

Datasets:

GIF files:

27

About me

An employee of the Republic of Indonesia’s Ministry of Finance. Funded by the Indonesia Endowment Fund for Education ("Lembaga Pengelola Dana Pendidikan"), at the moment, on study leave to join a PhD program in the School of Economics, the University of Nottingham with research interests in Indonesia's government bonds market and their bondholders' behaviour. Also a research assistant at tracktheeconomy.ac.uk.

2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow