## Sampling

Sampling is the process of selecting a subset of individuals or items from a larger population for the purpose of drawing conclusions about the population.  Let's dive into random sampling and explore some real examples.

---

### Random Sampling

Random sampling ensures each individual/item in the population has an equal chance of being selected. It reduces bias in your sample.

```{r}
student_ids <- 1:1000
sample_ids <- sample(student_ids, 50)

sample_ids
```


```{r}
set.seed(123)
sample_ids <- sample(student_ids, 50)
sample_ids
```

- Each student has the same chance of being selected.
- This is called random sampling.
- Random sampling helps make the sample fair.

---

**Example**: Let's consider a new example for sampling. You want to survey the average number of hours university students spend on social media per day.

- **What is the population in this scenario?**

The population is all university students you want to make conclusions about (e.g., all students at your university)

- **What is the sampling method you would select for this survey?** Do not just write the title of the sampling method but also explain the steps you are utilizing (e.g., get a list of registrar or post on a website etc).

Use simple random sampling: get a full student list (sampling frame), assign each student a number, use a random number generator to pick n students, then survey only those selected students.

- **Is your sample a random sample? Why or why not?**

It is random if every student had an equal chance to be selected using the random process above.

- **Could there be any bias in the sampling process? What kind of bias might exist?**

Yes. Examples: nonresponse bias (people who don’t reply are different from those who do) and undercoverage/coverage bias (your student list misses some groups).

---

### Random Sampling vs. Convenience Sampling

Read the following two scenarios and decide which one uses random sampling and which uses convenience sampling.

1. You randomly select 200 students from the entire student population at your university.
2. You survey students waiting in line at a campus coffee shop.

**Which sampling method is less likely to introduce bias? Why?**

- Convenience sampling means choosing people who are easy to reach.
= This group is not representative of all students.
- This can lead to bias.

---

## Study Design in Research

The way a study is designed plays a critical role in the validity and reliability of the conclusions drawn from it. Let’s explore **observational studies** and **experimental designs**.

---

### Observational Study

In an observational study, researchers observe the subjects without interfering. There is no treatment or intervention involved.

(A researcher wants to study whether students who sleep less tend to have lower GPAs. The researcher does not change anyone’s sleep schedule. They simply survey students about their average hours of sleep and record their GPAs, then analyze the relationship.)
 
- **What are the strengths of an observational study?**  

- Often cheaper and faster than experiments.

- Useful when experiments are unethical or impossible (e.g., smoking, pollution exposure).

- **What are the limitations?**

- Cannot prove cause-and-effect (only association).

- Selection bias (groups may differ in important ways).

- Measurement issues (self-reports, missing data) can reduce accuracy.

---

### Experiment Design

An experimental design involves manipulating one or more variables (treatments) and observing the effects.

**Example**: Suppose you are studying the effect of two different diets on weight loss over a 6-week period. The two diets are a low-carb diet and a low-fat diet.

- **What is the treatment in this experiment?**

The treatment is the type of diet assigned: low-carb diet vs. low-fat diet.

- **What variables will you control for (e.g., exercise, initial weight)?**

Keep other factors the same, such as exercise level, starting weight/BMI, total calories eaten, age/sex, and the 6-week study length. These are control variables because they could also affect weight loss.


# Intro to Probability

Probability helps us quantify uncertainty and make predictions about the likelihood of events.

---

## Sample Space and Events

- **Sample Space (S)**: The set of all possible outcomes of an experiment.
- **Event (E)**: A specific outcome or set of outcomes within the sample space.

**Think About This**

- **If you flip a fair coin, what is the sample space?**
- **If your event is getting heads, what is the outcome for this event?**

```{r, message = FALSE}
library(tidyverse)
# Sample space for flipping a coin
sample_space <- c("Heads", "Tails")

# Event: Getting Heads
event <- sample_space[1]

# Display results
sample_space
event
```

Type your answers below.

---

## Defining Probability

- **Probability (P)**: The chance that an event will occur, ranging from 0 (impossible) to 1 (certain).
  
**Example**:  
If you flip a fair coin, there are two possible outcomes: heads or tails. Each outcome has a probability of 0.5.

**Try It**:

- **What is the probability of drawing a face card from a standard deck of 52 cards?**
- **What is the probability of rolling an odd number on a fair six-sided die?**

```{r}
# Probability of drawing a face card (12 face cards in a deck of 52)
prob_face_card <- 12 / 52

# Probability of rolling an odd number on a fair six-sided die
odd_numbers <- c(1, 3, 5)
prob_odd <- length(odd_numbers) / 6

# Display probabilities
prob_face_card
prob_odd
```

---

## Axioms of Probability

There are three fundamental axioms of probability:

1. **Non-Negativity**: Probability of any event is ≥ 0.
2. **Additivity**: For mutually exclusive events, the probability of their union is the sum of their probabilities.
3. **Normalization**: The probability of the entire sample space is 1.

**Activity**:  

- **If you roll a die, what is the probability of getting a number less than or equal 3?**
- **What is the probability of rolling a number greater than 4?**

```{r}
# Sample Space
sample_space <- c(1, 2, 3, 4, 5, 6)

# Probability of rolling a number less than 3
sum(sample_space <= 3) / length(sample_space)

# Probability of rolling a number greater than 4
sum(sample_space > 4) / length(sample_space)

```


