Skip to content
Introduction to Statistics in R

Introduction to Statistics in R

Run the hidden code cell below to import the data used in this course.

Intro to Statistics ->

  • Descriptive statistics focuses on describing and summarizing the data at hand. After asking four friends how they get to work, we can see that 50% of them drive to work, 25% ride the bus, and 25% bike. These are examples of descriptive statistics.
  • Inferential statistics uses the data at hand, which is called sample data, to make inferences about a larger population. We could use inferential statistics to figure out what percent of people drive to work based on our sample data.

Types of Data ->

There are two main types of data.

  • Numeric (quantitative data) is made up of numeric values.
  • Categorical (qualitative data) is made up of values that belong to distinct groups.

msleep

WAYS TO MEASURE CENTER - MEAN, MEDIAN, MODE

calculate mean

mean(msleep$sleep_total) 

calculate median

  • The median is the value where 50% of the data is lower than it, and 50% of the data is higher. We can calculate this by sorting all the data points and taking the middle one
sort(msleep$sleep_total) #way 1
sort(msleep$sleep_total)[42]
median(msleep$sleep_total) #way 2

calculate mode

  • most frequent value in the data
library(dplyr)
msleep %>% count(sleep_total, sort = TRUE)

There are 4 mammals that sleep for 12.5 hours, so this is the mode.