Introduction to R for Road Safety

background-image: url(https://user-images.githubusercontent.com/1825120/61066243-12dc6d80-a3fd-11e9-8805-826a47c553f6.png)

About the course team and location


About the course

--


About the package

See https://docs.ropensci.org/stats19/


R and RStudio demo

Actions speak louder than words...


Over to you

Work through Section 2 of the exercises


Time data

Section 3.4 shows how to change classes in R

Time is represented by special classes:

library(lubridate)
x = today()
class(x)
day(x)
month(x)
year(x)
weekdays(x)

Time representations

as.Date("2019-10-17") # works
# as.Date("2019 10 17") # fails
ymd("2019 10 17") # works
dmy("17/10/2019") # works

Subsetting time objects

c_sample = stats19::accidents_sample
c_sample$date
c_sample$date_formatted = dmy(c_sample$date)
c_sample$date_formatted > ymd("2022-08-01")

Next up

After lunch

Spatial data (maps!)

Spatial data and maps

library(sf)
crashes = readr::read_csv("https://github.com/ropensci/stats19/releases/download/1.0.0/crashes.csv")
crashes_sf = crashes # create copy of crashes dataset
crashes_sf$longitude = c(-1.3, -1.2, -1.1)
crashes_sf$latitude = c(50.7, 50.7, 50.68)
crashes_sf = st_as_sf(crashes_sf, coords = c("longitude", "latitude"), crs = 4326)
plot(crashes_sf)

Doing spatial data with R


Practical


Afternoon session


Day 2

--


The R learning curve

See video: https://www.youtube.com/watch?v=7oyiPBjLAWY&feature=youtu.be&t=357


Agenda

09:30-11:00 Point pattern analysis

11:15-12:30 Road network data

Lunch

13:30-15:00 Analysing crash data on road network

Break

15:15-15:30: Talk on Road Safety 3

15:30-16:30 Applying the methods to your own data


Bonus extras

--

Merging, forecasting, network analysis


Visualising spatial data practical

--


Further information



Try the stats19 package in your browser

Any scripts or data that you put into this service are public.

stats19 documentation built on Nov. 5, 2023, 1:09 a.m.