Lab 1

Types of variables

Nominal vs Numerical

What about these?

  • Likert scale responses ranging from 1-7

  • Participant ID numbers

  • Age

  • Zip code

  • Level of education

Discrete vs Continuous

What about these?

  • Likert scale responses ranging from 1-7

  • Participant ID numbers

  • Age

  • Zip code

  • Level of education

Statistic vs Parameter

Population \(\rightarrow\) Parameter

Sample \(\rightarrow\) Statistic

Generally, parameters are depicted as Greek letters, while statistics are depicted using English letters.

Ex. Population mean \(\mu\) vs sample mean \(\bar{X}\)

Ex. Population variance \(\sigma^2\) vs sample variance \(s^2\)

Distributions

Frequency distribution

Relative Frequency Distribution

Cumulative Relative Frequency Distribution

Differences?

Measures of Central Tendency

Mean

The “average”

\(\bar{X} = \displaystyle\frac{\displaystyle\sum_{i=1}^{i=N}x_1,x_2,x_3,...,x_N}{N}\)

Median

The “middle” number (e.g., 50th percentile)

Mode

The most frequent value

Skew

Positive Skew

  • Tail is on right side

  • Data centered on left side of distribution

Negative Skew

  • Tail is on left side

  • Data centered on right side of distribution

What effect does this have on mean, median, and mode?

Questions?

Introduction to R

Types of R files

R Script (.r)

  • Most basic

  • Efficient for smaller tasks

  • Fewer frills

R Markdown (.rmd)

  • Create notebooks

  • Document-like editing style

  • Export to website or pdf - customizable graphics

Quarto (.qmd)

  • Updated/advanced version of R Markdown

  • Additional features like creating presentations

Basics - Anatomy of R

Source

  • Write code
  • Conduct analyses either line-by-line or in chunks

Console

  • Numerical output appears here
  • Can also run single lines of code (e.g., simple calculations or things you won’t need later)

Environment

  • View variables/data frames you’ve created
  • Clear environment using the sweeping icon

Files/Plots

  • Graphics you create will appear here
  • Navigate working directory and import data manually

Some basics - packages

You start with “base R” and can download packages from there

#example installing package "performance"  
#install.packages("performance")

Each time you open R or clear your environment, you need to load packages again

#example loading package "performance" 
library(performance)

Functions in R

Functions are typically written in the following format:

FunctionName(parameter1, parameter2, etc.)

examples:

#function with one parameter
mean(data$AGE)
[1] 39.24628
#function with more parameters
plot(x = data$AGE, y = data$SIBS, xlab = "Age", ylab = "Number of siblings", main = "Scatterplot example", pch = 16, col = "navy")

To see what a function does and what parameters can be specified for the function, use the following:

?mean
?plot
?lm

Using this feature can be confusing at times, but Google is your friend!

The best way to get better at using RStudio is by experimenting and finding new information when you get stuck.

Demo time!