Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a...

25
STAT 215A Fall 2017 Week 3 Rebecca Barter 09/08/2017

Transcript of Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a...

Page 1: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

STAT 215A Fall 2017Week 3

Rebecca Barter09/08/2017

Page 2: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Lab 1 check in

How do you explore the data (for understanding)?

How do you find an interesting story to tell about the data?

Where does creativity come in when doing data analysis?

Page 4: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Modern kernel density estimation

Page 5: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

https://www.reddit.com/r/dataisbeautiful/comments/6vythg/i_redid_my_perceptions_of_probability_and_numbers/

Known on twitter as the “joyplot”

https://twitter.com/hashtag/joyplot

Page 6: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

Page 7: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

bandwidth (h)

Page 8: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

Page 9: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

Estimate the density, f, by adding together individual kernel functions:

Page 10: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

Estimate the density, f, by adding together individual kernel functions:

Each kernel function is centered at a data point

Page 11: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

Estimate the density, f, by adding together individual kernel functions:

The width of the kernel function is defined by the

bandwidth, h

Page 12: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

There are many possible Kernel function that you could use

Page 13: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

There are many possible Kernel function that you could use

Page 14: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

There are many possible Kernel function that you could use

Page 15: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Kernel Density Estimation

There are many possible Kernel function that you could use

Page 16: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

1. Write a function that calculates the density of a vector of numbers.

2. Plot the density of the “chances are slight” probability interpretations.

3. Make a plot that displays the bias-variance tradeoff.

To download the data, clone Zonination’s github repository: https://github.com/zonination/perceptions

Exercise 1

Page 17: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Data: https://github.com/zonination/perceptions

Alternative view of the same data:

A heatmap using the

viridis color scheme

Page 18: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Data: https://github.com/zonination/perceptions

Superheat version

● Automatically selects color transitions based on data quantiles

● Automatically arranges rows in median order

Page 19: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

https://stackoverflow.com/documentation/matplotlib/3385/colormaps#t=201709071849576587196

Viridis: the perceptually

uniform colour palette

Page 20: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Choosing color palettes:

https://coolors.co/app

Page 21: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Choosing color palettes:

http://http://colorbrewer2.org/

Page 22: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Come up with your own visualization of the perception data.

The only requirement is: be creative!

Exercise 2

Page 23: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Interactivity

Page 24: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Come up with your own *interactive* visualization of the perception data.

Useful R packages:

- Plotly- Crosstalk- Highcharter- Shiny

Exercise 3

Page 25: Week 3 STAT 215A Fall 2017 - Rebecca Barter · 1. Write a function that calculates the density of a vector of numbers. 2. Plot the density of the “chances are slight” probability

Next week…. PCA