# 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. 

## Random Sampling

Random sampling involves selecting individuals or items from the population in such a way that each member has an equal chance of being chosen. This helps to reduce bias in your sample.

For example, let's look at the exercise 1.14 and 1.17 on page 30 of [the book](https://www.openintro.org/go/?id=os4_for_screen_readers&referrer=/book/os/index.php).


What is the population?

What is the sample?

Is it a random sample?

Is there any bias?





# Study Design in Research

Study design is a critical aspect of research that involves planning and organizing the methodology of a study. It is essential for ensuring that the data collected is valid, reliable, and capable of answering the research question.

## Observational Study

There is no treatment/intervention.

## Experiment Design

Let's look at 1.30 on page 39

# Simpson's Paradox

Simpson's Paradox is a statistical phenomenon that can lead to counterintuitive results when analyzing data. 
We'll explore Simpson's Paradox using an example involving Kidney stone treatment.

## Example: Kidney stone treatment


```{r}
total_patients = c(87, 263, 270, 80)
success = c(81, 191, 234, 55)
# Example data
data <- data.frame(
  treatment = c("A", "A", "B", "B"),
  stone = c("S", "L", "S", "L"),
  total_patients = c(87, 263, 270, 80),
  success = c(81, 191, 234, 55)
)

# Calculate mortality rates by hospital and surgery type
success_rates <- aggregate(success / total_patients, by = list(data$treatment, data$stone), FUN = mean)

success_rates
```

It appears that Treatment A has a higher success rate for both kind of stones, while treatment B has a lower success rate for them.

However, when we aggregate the data without considering the stone type:

The overall success rates for each treatment are as follows:

| Treatment| Success Rate   |
|----------|----------------|
| A        | 78%            |
| B        | 83%            |

Surprisingly, when we look at the overall success rates without considering the stone type, treatment B seems better. This is an example of Simpson's Paradox.

## Implications

Simpson's Paradox is a reminder that drawing conclusions from aggregated data without considering all relevant factors can lead to incorrect or misleading insights. When encountering this paradox, it's essential to dig deeper into the data, consider confounding variables, and analyze subgroups to gain a more accurate understanding of the relationships within the data.



# Intro to Probability

## Sample Space and Events

- **Sample Space (S)**: The sample space is the set of all possible outcomes of a random experiment. It encompasses every possible result, such as the outcomes of rolling a die (1, 2, 3, 4, 5, 6).

- **Events (E)**: Events are subsets of the sample space, representing specific outcomes or combinations of outcomes. For example, getting an even number (E) when rolling a fair six-sided die.

## Defining Probability

- **Probability (P)**: Probability measures the likelihood of an event occurring. It is a value between 0 (impossible) and 1 (certain). The probability of an event E is denoted as P(E).

- **Relative Frequency Probability**: Probability is estimated based on the relative frequency of an event occurring in repeated experiments.

## Axioms of Probability

Three axioms govern probability theory:

1. **Non-Negativity**: Probability is never negative, i.e., P(E) ≥ 0 for all events E.

2. **Additivity**: For mutually exclusive events (events that cannot occur simultaneously), the probability of their union is the sum of their individual probabilities, i.e., P(E₁ ∪ E₂) = P(E₁) + P(E₂).

3. **Normalization**: The probability of the entire sample space is 1, i.e., P(S) = 1.

Example: 3.26 on page 127

