---
title: "R Project 02 Climate Change"
author: "Your Name Here"
date: "`r Sys.Date()`"
output: html_document
---

```{r setup, include=FALSE}
temps <- read.csv("https://www.dropbox.com/s/gir83plkf8bw5gd/climate_change_blue_hill_2023.csv?dl=1")
```

# Approach 1

*If there have been no temperature trends, we would expect the number of dates where the record high occurred more recently to be about the same as the number where the record low occurred more recently. If there is a warming trend, we would expect more dates where the record high is more recent.*

## 1. Find the proportion of dates where the record high occurred more recently.

```{r}
# Count dates where H_Year >= L_Year using sum() on a logical condition
# Then compute p-hat = x / n

```

**Your interpretation: State x, n, and p-hat.**

## 2. Test the hypothesis H0: p = 0.5 vs H1: p > 0.5

```{r}
# One-sample proportion test function (provided for you)
one.samp.prop.test <- function(x, n, p0, direction = "two.sided") {
  p_hat <- x / n
  se <- sqrt(p0 * (1 - p0) / n)
  z <- (p_hat - p0) / se
  if (direction == "two.sided") {
    p_value <- 2 * pnorm(-abs(z))
  } else if (direction == "greater") {
    p_value <- 1 - pnorm(z)
  } else if (direction == "less") {
    p_value <- pnorm(z)
  }
  return(list(p_hat = p_hat, z_value = z, p_value = p_value))
}
```

```{r}
# Check assumptions: n*p0 >= 10 and n*(1-p0) >= 10

```

**Your interpretation: Are the assumptions satisfied?**

```{r}
# Run the right-tailed test

```

**Your interpretation: State the p-value and your decision about H0.**

## 3. Conclusion about warming trend (Approach 1)

**Your interpretation:**

---

# Approach 2

*If a record low is equally likely to occur in any year of observation, the mean year would be near the midpoint. If there is a warming trend, the mean year of record lows would be less than the midpoint.*

## 1. What is the midpoint of the observation period (1893 to 2023)?

```{r}
First_Year <- 1893
Last_Year <- 2023
# Compute the midpoint

```

**Your interpretation:**

## 2. Test whether the mean year of record lows is less than the midpoint.

```{r}
# One-sample t-test function (provided for you)
one.samp.t.test.data <- function(sample_data, null_mean, direction = "two.sided") {
  sample_mean <- mean(sample_data)
  sample_sd <- sd(sample_data)
  sample_size <- length(sample_data)
  t_value <- (sample_mean - null_mean) / (sample_sd / sqrt(sample_size))
  df <- sample_size - 1
  if (direction == "two.sided") {
    p_value <- 2 * pt(-abs(t_value), df)
  } else if (direction == "greater") {
    p_value <- 1 - pt(t_value, df)
  } else if (direction == "less") {
    p_value <- pt(t_value, df)
  }
  return(list(sample_mean = sample_mean, sample_sd = sample_sd,
              sample_size = sample_size, t_value = t_value, p_value = p_value))
}
```

```{r}
# Check assumptions: is n >= 30?

```

**Your interpretation:**

```{r}
# Run the left-tailed test on L_Year

```

**Your interpretation: State the p-value and your decision about H0.**

## 3. Conclusion about warming trend (Approach 2)

**Your interpretation:**

---

# Approach 3

*A researcher repeats Approach 2 using monthly data instead.*

```{r}
new_temps <- read.csv("https://www.dropbox.com/s/bl9cuq9a6f98j3s/climate_change_blue_hill_2023_monthly.csv?dl=1")
```

## 1. Should a hypothesis test be performed on this data set? Explain why or why not.

```{r}
# hist()

# qqnorm() and qqline()

```

**Your interpretation: Consider the sample size and the shape of the distribution.**
