library(readr) library(tidyr) library(ggplot2) library(knitr) library(ggplot2) install.packages(“pdflatex”)

4.a) Determine the number of samples that are required to estimate the population mean at the 95% confidence level.

#Calc the sample mean and sample std dev for the intital Cr TCLP val’s

cr_tclp_values <- c(4.2, 5.8, 2.9, 5.2, 3.9, 5.0)

sample_mean <- mean(cr_tclp_values) sample_sd <- sd(cr_tclp_values)

#Confidence level & margin of error:

confidence <- 0.95 zscore <- qnorm(0.5 + confidence / 2) marg_error <- 0.5

#Calc required sample size:

req_sample_size <- (zscore * sample_sd/marg_error)^2 cat(“Required Sample Size:”, ceiling(req_sample_size), “”) # Required Sample Size: 17 (calculated above and printed in the console)

4.b) Define a grid for a 20x20 m area and plot sampling points

#Grid dimensions:

gridx <- seq(0, 20, length.out = 6) gridy <- seq(0, 20, length.out = 5)

#Create a df with sample location coordinates:

sample_locs <- expand.grid(x = gridx, y = gridy) sample_locs$cr_tclp <- c(4.8, 3.6, 5.8, 4.3, 2.5, 3.9, 4.9, 6.1, 4.1, 5.8, 3.4, 4.6, 4.0, 5.2, 3.7, 6.0, 4.2, 5.1, 2.9, 4.4, 6.1, 4.8, 5.3, 4.2, 4.3, 4.1, 3.9, 4.0, 5.5, 4.7)

#Plot sample pts:

ggplot(sample_locs, aes(x = x, y = y)) + geom_point(aes(color = cr_tclp), size = 3) + scale_color_gradient(low = “blue”, high = “red”) + labs(title = “Cr TCLP Sample Locations”, x = “Distance (m)”, y = “Distance (m)”, color = “Cr TCLP (mg/L)”) + theme_minimal()

4.c) Are the Cr CTCLP Levels Below the Regulatory Threshold?

#I’ll use the sample_locs ds created above to calc mean and confidence interval

#Calc mean and 95% conf interval for all samples:

all_samples <- sample_locs$cr_tclp all_mean <- mean(all_samples) all_sd <- sd(all_samples) all_n <- length(all_samples)

#Calc margin of error and confidence interval:

marg_of_err <- zscore * (all_sd / sqrt(all_n))

lower_bound <- all_mean - marg_of_err upper_bound <- all_mean + marg_of_err

cat(“Mean Cr TCLP:”, all_mean, “”) # Mean Cr TCLP: 4.54 cat(“95% Confidence Interval: (”, lower_bound, “,”, upper_bound, “)”) # 95% Confidence Interval: ( 4.210343 , 4.869657 )