Review
Review for PSQF 6243
This serves as a non-exhaustive review for the course. These are elements that I assume you have knowledge of prior to starting the course.
- Variable vs constant attributes
- Types of variables (ie., nominal, ordinal, integer, ratio)
- Descriptive Statistics (eg., mean, median, standard deviation, variance, percentiles)
- Higher order moments (eg., skewness and kurtosis)
- Exploring/summarizing univariate distributions (eg., histogram or density figure)
- What is a statistical model? Why do we use them?
- Population vs Sample
Examples
Mario Kart 64 world record data:
variable | class | description |
---|---|---|
track | character | Track name |
type | factor | Single or three lap record |
shortcut | factor | Shortcut or non-shortcut record |
player | character | Player’s name |
system_played | character | Used system (NTSC or PAL) |
date | date | World record date |
time_period | period | Time as hms period |
time | double | Time in seconds |
record_duration | double | Record duration in days |
# load some libraries
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.3.2
## Warning: package 'tidyr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggformula)
## Loading required package: scales
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
##
## Loading required package: ggridges
## Warning: package 'ggridges' was built under R version 4.3.2
##
## New to ggformula? Try the tutorials:
## learnr::run_tutorial("introduction", package = "ggformula")
## learnr::run_tutorial("refining", package = "ggformula")
library(lubridate)
library(mosaic)
## Warning: package 'mosaic' was built under R version 4.3.2
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Attaching package: 'mosaic'
##
## The following object is masked from 'package:Matrix':
##
## mean
##
## The following object is masked from 'package:scales':
##
## rescale
##
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
##
## The following object is masked from 'package:purrr':
##
## cross
##
## The following object is masked from 'package:ggplot2':
##
## stat
##
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
## quantile, sd, t.test, var
##
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
library(e1071)
theme_set(theme_bw(base_size = 18))
# load in some data
mariokart <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-05-25/records.csv') %>%
mutate(year = year(date),
month = month(date),
day = month(date))
## Rows: 2334 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): track, type, shortcut, player, system_played, time_period
## dbl (2): time, record_duration
## date (1): date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(mariokart)
## # A tibble: 6 × 12
## track type shortcut player system_played date time_period time
## <chr> <chr> <chr> <chr> <chr> <date> <chr> <dbl>
## 1 Luigi Raceway Thre… No Salam NTSC 1997-02-15 2M 12.99S 133.
## 2 Luigi Raceway Thre… No Booth NTSC 1997-02-16 2M 9.99S 130.
## 3 Luigi Raceway Thre… No Salam NTSC 1997-02-16 2M 8.99S 129.
## 4 Luigi Raceway Thre… No Salam NTSC 1997-02-28 2M 6.99S 127.
## 5 Luigi Raceway Thre… No Gregg… NTSC 1997-03-07 2M 4.51S 125.
## 6 Luigi Raceway Thre… No Rocky… NTSC 1997-04-30 2M 2.89S 123.
## # ℹ 4 more variables: record_duration <dbl>, year <dbl>, month <dbl>, day <dbl>
# univariate distribution of time
gf_histogram(~ time, data = mariokart, bins = 30) %>%
gf_labs(x = "Time (in seconds)")
gf_density(~ time, data = mariokart) %>%
gf_labs(x = "Time (in seconds)")
df_stats(~ time, data = mariokart, mean, median, sd, skewness, kurtosis, quantile(probs = c(0.1, 0.5, 0.9)))
## response mean median sd skewness kurtosis 10% 50% 90%
## 1 time 90.62383 86.19 66.6721 1.771732 3.844745 31.31 86.19 171.961
Bivariate Association
cor(time ~ record_duration, data = mariokart)
## [1] -0.06736739
gf_point(time ~ record_duration, data = mariokart) %>%
gf_labs(x = "How long the record was held",
y = "Time (in seconds)")
Questions
- What is problematic about the analyses above? Why?
- What could be done to improve the analyses above?