
---
title: "Statistical Testing Scenarios"
output: pdf_document
---

```{r}
knitr::opts_chunk$set(echo = TRUE)
```

## Scenario 1: Independent t-test


```{r scenario1}
scores <- data.frame(
  group = rep(c("yes", "no"), each = 15),
  score = c(85, 80, 78, 83, 81, 79, 84, 82, 87, 83, 85, 88, 80, 86, 84,
            72, 70, 69, 73, 75, 68, 71, 74, 70, 69, 72, 71, 68, 73, 70)
)
t.test(score ~ group, data = scores)
```


---

## Scenario 2: Paired t-test


```{r scenario2}
bp <- data.frame(
  before = c(140, 145, 138, 142, 141, 139, 144, 143, 140, 137,
             141, 142, 139, 143, 138, 140, 144, 146, 139, 141),
  after  = c(130, 132, 129, 134, 133, 130, 131, 132, 129, 128,
             131, 132, 130, 133, 129, 130, 134, 135, 130, 132)
)
t.test(bp$before, bp$after, paired = TRUE)
```


---

## Scenario 3: Independent t-test


```{r scenario3}
heart_data <- data.frame(
  group = rep(c("A", "B"), each = 20),
  bpm = c(72, 70, 71, 73, 74, 72, 70, 72, 73, 71,
          70, 72, 74, 72, 71, 73, 72, 72, 73, 71,
          72, 72, 73, 71, 72, 70, 72, 74, 73, 71,
          70, 71, 72, 73, 72, 70, 72, 71, 73, 72)
)
t.test(bpm ~ group, data = heart_data)
```


---

## Scenario 4: One-way ANOVA


```{r scenario4}
sleep_data <- data.frame(
  age_group = rep(c("young", "middle", "senior"), each = 15),
  hours = c(8.5, 8.2, 8.1, 7.8, 8.0, 8.3, 7.9, 8.4, 8.2, 8.1, 8.0, 7.7, 7.9, 8.3, 8.0,
            6.5, 6.3, 6.6, 6.4, 6.2, 6.5, 6.6, 6.4, 6.3, 6.1, 6.4, 6.2, 6.3, 6.5, 6.4,
            5.4, 5.2, 5.5, 5.3, 5.1, 5.3, 5.4, 5.2, 5.3, 5.5, 5.2, 5.3, 5.4, 5.1, 5.3)
)
anova_model <- aov(hours ~ age_group, data = sleep_data)
summary(anova_model)
```


---

## Scenario 5: Correlation


```{r scenario5}
study <- data.frame(
  hours = c(2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
  score = c(55, 60, 65, 70, 74, 78, 82, 85, 88, 90)
)
cor.test(study$hours, study$score, method = "pearson")
```


---

## Scenario 6: Chi-square Test


```{r scenario6}
gender <- c(rep("Male", 20), rep("Female", 20))
preference <- c("Remote", "Office", "Remote", "Remote", "Remote",
                "Office", "Remote", "Remote", "Office", "Remote",
                "Office", "Remote", "Remote", "Remote", "Remote",
                "Office", "Remote", "Office", "Remote", "Remote",
                "Office", "Office", "Office", "Remote", "Office",
                "Remote", "Office", "Office", "Remote", "Office",
                "Remote", "Remote", "Office", "Remote", "Remote",
                "Office", "Office", "Remote", "Remote", "Office")
table_data <- table(gender, preference)
chisq.test(table_data)
```


---

## Scenario 7: One-way ANOVA


```{r scenario7}
work_hours <- data.frame(
  department = rep(c("HR", "Finance", "IT"), each = 15),
  hours = c(
    38, 39, 40, 41, 39, 40, 38, 40, 39, 41, 40, 39, 38, 40, 39,
    39, 40, 41, 40, 39, 40, 38, 41, 40, 39, 40, 40, 39, 40, 39,
    40, 41, 39, 40, 40, 38, 39, 40, 41, 40, 39, 39, 40, 40, 40)
)
anova_model2 <- aov(hours ~ department, data = work_hours)
summary(anova_model2)
```
