#Filter data to work with from years 2012-2022df <-data.frame(df)# Define the range of yearsstart_year <-2012end_year <-2022# Filter for the range of years using indexing & removing "Undisclosed Region")MDB_year_data <- df %>%filter(Year.Analyzed >= start_year & Year.Analyzed <= end_year & Region !="Undisclosed Region")#write.csv(MDB_year_data, "D:/My Drive/Statistics/FACT-Manure-Database/data/MDB_year_data.csv")#View(MDB_year_data)#detach("package:MASS", unload = TRUE) only needed when attached earlier.# Select columns to work withMDB_select<-select(MDB_year_data,c(1,2,3,4,6,7,11,14,52,16,41,42,53))#write.csv(MDB_select, "MDB_select.csv")#View(MDB_select)
Percent of samples with metadata for each column
Code
# Define the write_clip functionwrite_clip <-function(data) {# Create a data frame with column names and percentages df <-data.frame(Column =names(data), Percentage = data)# Write to clipboardwrite.table(df, "clipboard", sep="\t", row.names=FALSE, col.names=TRUE)}# Replace "Unknown" values and blanks with NAMDB_year_data_count <- MDB_year_dataMDB_year_data_count[MDB_year_data_count =="Unknown"| MDB_year_data_count ==""] <-NA# Calculate the percentage of non-NA values in each columnpercent_non_na <-colMeans(!is.na(MDB_year_data_count)) *100# Print the percentagesprint(percent_non_na)
Sort out for beef while still having separate NPK columns
Code
# Sort out for beef while still having separate NPK columnsMDB_beefstackNPK <-filter(MDB_stack5fix, Animal.or.Other.Amendment.Type =="Beef")#View(MDB_beefstackNPK)
Check for normality using histogram, Q-Q plots, Jarque-Bera test for original total N beef solid data
Code
# Group data by "Year_Analyzed" and "Region", and perform Jarque-Bera test for each group# Filter out rows with missing values in the Total_N columncleaned_data <- MDB_beefstackNPK %>%filter(!is.na(Total_N))#write.csv(cleaned_data, "D:/My Drive/Statistics/FACT-Manure-Database/data/cleaned_data.csv")jarque_bera_results <- cleaned_data %>%group_by(Year.Analyzed, Region) %>%summarize(jb_test =list(jarque.bera.test(Total_N))) %>%mutate(p_value =map_dbl(jb_test, ~ .x$p.value))# Print the results#print(jarque_bera_results)#View(jarque_bera_results) #not normal distribution for majority# Q-Q plot for original dataqqnorm(cleaned_data$Total_N)qqline(cleaned_data$Total_N, col =2) # Add a reference line
Code
#Histogramhist(cleaned_data$Total_N)
Beef Solid Total N log and square root transformation & check for normality using Jarque-Bera test
Code
# Log transformation with base 10 on Total_N columncleaned_data$log_Total_N <-log(cleaned_data$Total_N, base =10)# Square root transformation of Total_N columncleaned_data$sqrt_Total_N <-sqrt(cleaned_data$Total_N)#View(cleaned_data)#write.csv(cleaned_data, "D:/My Drive/Statistics/FACT-Manure-Database/data/cleaned_data.csv")# Visualize the original and transformed datapar(mfrow =c(1, 2))hist(cleaned_data$Total_N, main ="Original Total_N", xlab ="Value")hist(cleaned_data$log_Total_N, main ="Log Transformed Total_N", xlab ="Log Value")
Code
hist(cleaned_data$sqrt_Total_N, main ="Sq root Transformed Total_N", xlab ="Sq root Value")# Q-Q plot for log-transformed dataqqnorm(cleaned_data$log_Total_N[is.finite(cleaned_data$log_Total_N)])qqline(cleaned_data$log_Total_N, col =2) # Add a reference line
Code
# Q-Q plot for sqrt-transformed dataqqnorm(cleaned_data$sqrt_Total_N)qqline(cleaned_data$sqrt_Total_N, col =2) # Add a reference line# Perform Jarque-Bera test for log data grouped by Year.Analyzed and Regionjarque_bera_results_log <- cleaned_data %>%group_by(Year.Analyzed, Region) %>%summarize(jb_test =list(jarque.bera.test(log_Total_N))) %>%mutate(p_value =map_dbl(jb_test, ~ .x$p.value))# Print the results#print(jarque_bera_results)#View(jarque_bera_results_log)# Perform Jarque-Bera test for sqare root data grouped by Year.Analyzed and Regionjarque_bera_results_sqrt <- cleaned_data %>%group_by(Year.Analyzed, Region) %>%summarize(jb_test =list(jarque.bera.test(sqrt_Total_N))) %>%mutate(p_value =map_dbl(jb_test, ~ .x$p.value))# Print the results#print(jarque_bera_results)#View(jarque_bera_results_sqrt)
Table of samples by region by year for Beef solid manure
Code
# Create a table of number of samples for each region per yearsample_table <-table(MDB_beefstackNPK$Region, MDB_beefstackNPK$Year.Analyzed)# Print the sample tableprint(sample_table) #NE and SE have samples all years
Four Analytes Mann-Whitney comparison by year for not normal distribution with Benjamini-Hochberg correction LOOP (Beef Solid)
Code
# Filter data for selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")filtered_data <- MDB_beefstackNPK[MDB_beefstackNPK$Region %in% selected_regions, ]# Initialize an empty list to store cleaned data for each nutrientcleaned_data_list <-list()# Loop over each nutrientfor (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Remove missing values for the current nutrient cleaned_data <- filtered_data[!is.na(filtered_data[[nutrient]]), ] cleaned_data_list[[nutrient]] <- cleaned_data}# Create a Function for Wilcoxon Test and Correctionperform_wilcoxon_test <-function(region1, region2, year, nutrient, data) {# Extract data for the given regions and year region1_data <- cleaned_data[cleaned_data$Region == region1 & cleaned_data$Year.Analyzed == year, nutrient] region2_data <- cleaned_data[cleaned_data$Region == region2 & cleaned_data$Year.Analyzed == year, nutrient]# Perform Wilcoxon rank sum test wilcox_result <-wilcox.test(region1_data, region2_data)# Apply Benjamini-Hochberg correction adjusted_p_value <-p.adjust(wilcox_result$p.value, method ="BH")# Return resultsreturn(list(wilcox_result = wilcox_result, adjusted_p_value = adjusted_p_value))}# Iterate Over Years, Regions, and Nutrientsyears <-unique(cleaned_data$Year.Analyzed)regions <-unique(cleaned_data$Region)nutrients <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Initialize empty vectorsall_p_values <-c()comparison_results <-list()comparison_names <-c()# Loop over years, regions, and nutrients, perform tests, and gather p-valuesindex <-1for (year in years) {for (nutrient in nutrients) {for (i in1:(length(regions)-1)) {for (j in (i+1):length(regions)) { region1 <- regions[i] region2 <- regions[j]# Perform Wilcoxon test and correction results <-perform_wilcoxon_test(region1, region2, year, nutrient)# Store p-value all_p_values <-c(all_p_values, results$wilcox_result$p.value)# Store comparison name comparison_names <-c(comparison_names, paste(region1, region2, year, nutrient, sep ="_"))# Store results comparison_results[[index]] <- results index <- index +1 } } }}# Sort comparison names based on yearsorted_indices <-order(as.numeric(sapply(strsplit(comparison_names, "_"), `[`, 3)))sorted_comparison_names <- comparison_names[sorted_indices]# Apply Benjamini-Hochberg Procedureadjusted_p_values <-p.adjust(all_p_values, method ="BH")# Print results in chronological orderfor (name in sorted_comparison_names) { index <-match(name, comparison_names) year <-as.numeric(unlist(strsplit(name, "_"))[3]) nutrient <-unlist(strsplit(name, "_"))[4]# Extract Wilcoxon test results result <- comparison_results[[index]]$wilcox_result# Print results with adjusted p-valuescat("Comparison:", name, "\n")cat("Year:", year, "\n")cat("Nutrient:", nutrient, "\n")cat("Wilcoxon Test Statistic:", result$statistic, "\n")cat("Wilcoxon Test P-value:", result$p.value, "\n")cat("Adjusted p-value:", adjusted_p_values[index], "\n")cat("\n")}
Comparison: Northeast_Midwest_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 3505
Wilcoxon Test P-value: 0.0003018019
Adjusted p-value: 0.0009501788
Comparison: Northeast_Southeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 2234
Wilcoxon Test P-value: 0.001069128
Adjusted p-value: 0.002713939
Comparison: Midwest_Southeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 5660
Wilcoxon Test P-value: 0.796449
Adjusted p-value: 0.821338
Comparison: Northeast_Midwest_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 698
Wilcoxon Test P-value: 7.404964e-16
Adjusted p-value: 3.574805e-14
Comparison: Northeast_Southeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1738
Wilcoxon Test P-value: 0.6911428
Adjusted p-value: 0.7417143
Comparison: Midwest_Southeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 3289
Wilcoxon Test P-value: 8.124556e-16
Adjusted p-value: 3.574805e-14
Comparison: Northeast_Midwest_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 3642
Wilcoxon Test P-value: 0.001016043
Adjusted p-value: 0.002629759
Comparison: Northeast_Southeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2204
Wilcoxon Test P-value: 8.159545e-05
Adjusted p-value: 0.0002917686
Comparison: Midwest_Southeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 5192
Wilcoxon Test P-value: 0.1116191
Adjusted p-value: 0.1601491
Comparison: Northeast_Midwest_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 4244
Wilcoxon Test P-value: 0.06493033
Adjusted p-value: 0.09630117
Comparison: Northeast_Southeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 2622
Wilcoxon Test P-value: 0.00974219
Adjusted p-value: 0.01919357
Comparison: Midwest_Southeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 4927
Wilcoxon Test P-value: 0.0311672
Adjusted p-value: 0.05142588
Comparison: Northeast_Midwest_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 17303
Wilcoxon Test P-value: 8.550394e-09
Adjusted p-value: 8.304375e-08
Comparison: Northeast_Southeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 1975
Wilcoxon Test P-value: 0.02489387
Adjusted p-value: 0.04323671
Comparison: Midwest_Southeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 27496
Wilcoxon Test P-value: 0.01238219
Adjusted p-value: 0.02334927
Comparison: Northeast_Midwest_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 6998
Wilcoxon Test P-value: 7.984013e-05
Adjusted p-value: 0.0002917686
Comparison: Northeast_Southeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1565
Wilcoxon Test P-value: 0.4759928
Adjusted p-value: 0.5511495
Comparison: Midwest_Southeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 7015.5
Wilcoxon Test P-value: 0.001663709
Adjusted p-value: 0.004066843
Comparison: Northeast_Midwest_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 14969
Wilcoxon Test P-value: 3.620658e-12
Adjusted p-value: 7.965447e-11
Comparison: Northeast_Southeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1700
Wilcoxon Test P-value: 0.0005002714
Adjusted p-value: 0.001405017
Comparison: Midwest_Southeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 26850
Wilcoxon Test P-value: 0.05651707
Adjusted p-value: 0.08575004
Comparison: Northeast_Midwest_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 23462
Wilcoxon Test P-value: 0.009140988
Adjusted p-value: 0.01828198
Comparison: Northeast_Southeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 2027
Wilcoxon Test P-value: 0.03016975
Adjusted p-value: 0.05041021
Comparison: Midwest_Southeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 22047
Wilcoxon Test P-value: 0.4094161
Adjusted p-value: 0.478256
Comparison: Northeast_Midwest_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 17745
Wilcoxon Test P-value: 9.411929e-07
Adjusted p-value: 5.916069e-06
Comparison: Northeast_Southeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 2345
Wilcoxon Test P-value: 0.01103402
Adjusted p-value: 0.02110857
Comparison: Midwest_Southeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 38121
Wilcoxon Test P-value: 0.2549848
Adjusted p-value: 0.3205523
Comparison: Northeast_Midwest_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 6039
Wilcoxon Test P-value: 1.029191e-06
Adjusted p-value: 6.175144e-06
Comparison: Northeast_Southeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1857
Wilcoxon Test P-value: 0.672087
Adjusted p-value: 0.7331858
Comparison: Midwest_Southeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 11831
Wilcoxon Test P-value: 1.762884e-06
Adjusted p-value: 1.011742e-05
Comparison: Northeast_Midwest_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 20963
Wilcoxon Test P-value: 0.0009980365
Adjusted p-value: 0.002629759
Comparison: Northeast_Southeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2256
Wilcoxon Test P-value: 0.0009216039
Adjusted p-value: 0.002482688
Comparison: Midwest_Southeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 34175
Wilcoxon Test P-value: 0.1586158
Adjusted p-value: 0.2180967
Comparison: Northeast_Midwest_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 27208.5
Wilcoxon Test P-value: 0.8718141
Adjusted p-value: 0.8852266
Comparison: Northeast_Southeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 2558
Wilcoxon Test P-value: 0.02150052
Adjusted p-value: 0.03887765
Comparison: Midwest_Southeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 28995
Wilcoxon Test P-value: 0.0003154775
Adjusted p-value: 0.0009501788
Comparison: Northeast_Midwest_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 14683.5
Wilcoxon Test P-value: 0.0004725723
Adjusted p-value: 0.001356077
Comparison: Northeast_Southeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 1928
Wilcoxon Test P-value: 0.6450134
Adjusted p-value: 0.709973
Comparison: Midwest_Southeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 34098
Wilcoxon Test P-value: 0.004967757
Adjusted p-value: 0.0107499
Comparison: Northeast_Midwest_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 7531.5
Wilcoxon Test P-value: 0.006499069
Adjusted p-value: 0.0138132
Comparison: Northeast_Southeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1384
Wilcoxon Test P-value: 0.16256
Adjusted p-value: 0.2212157
Comparison: Midwest_Southeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 10840
Wilcoxon Test P-value: 9.040119e-05
Adjusted p-value: 0.0003140252
Comparison: Northeast_Midwest_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 13441
Wilcoxon Test P-value: 2.233207e-05
Adjusted p-value: 9.509137e-05
Comparison: Northeast_Southeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1492
Wilcoxon Test P-value: 0.008209497
Adjusted p-value: 0.01667159
Comparison: Midwest_Southeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 29692
Wilcoxon Test P-value: 0.6859694
Adjusted p-value: 0.7417143
Comparison: Northeast_Midwest_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 23131
Wilcoxon Test P-value: 0.1178888
Adjusted p-value: 0.1655459
Comparison: Northeast_Southeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 2256
Wilcoxon Test P-value: 0.3363382
Adjusted p-value: 0.4036058
Comparison: Midwest_Southeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 28114
Wilcoxon Test P-value: 0.7029078
Adjusted p-value: 0.7482567
Comparison: Northeast_Midwest_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 21578.5
Wilcoxon Test P-value: 0.04339108
Adjusted p-value: 0.06984906
Comparison: Northeast_Southeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 2072
Wilcoxon Test P-value: 0.3010761
Adjusted p-value: 0.3646059
Comparison: Midwest_Southeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 27208
Wilcoxon Test P-value: 0.8802182
Adjusted p-value: 0.8869374
Comparison: Northeast_Midwest_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 10708
Wilcoxon Test P-value: 0.02894824
Adjusted p-value: 0.04898933
Comparison: Northeast_Southeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1917
Wilcoxon Test P-value: 0.0003050977
Adjusted p-value: 0.0009501788
Comparison: Midwest_Southeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 11434
Wilcoxon Test P-value: 5.76504e-06
Adjusted p-value: 2.624087e-05
Comparison: Northeast_Midwest_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 16482
Wilcoxon Test P-value: 2.240188e-06
Adjusted p-value: 1.232103e-05
Comparison: Northeast_Southeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1495
Wilcoxon Test P-value: 0.000261411
Adjusted p-value: 0.0008626564
Comparison: Midwest_Southeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 26399
Wilcoxon Test P-value: 0.64543
Adjusted p-value: 0.709973
Comparison: Northeast_Midwest_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 27956
Wilcoxon Test P-value: 0.1702741
Adjusted p-value: 0.2270322
Comparison: Northeast_Southeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 2091
Wilcoxon Test P-value: 0.2786319
Adjusted p-value: 0.3469756
Comparison: Midwest_Southeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 21704
Wilcoxon Test P-value: 0.004231624
Adjusted p-value: 0.009309573
Comparison: Northeast_Midwest_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 24288
Wilcoxon Test P-value: 0.006592662
Adjusted p-value: 0.0138132
Comparison: Northeast_Southeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 1925
Wilcoxon Test P-value: 0.02230509
Adjusted p-value: 0.03925696
Comparison: Midwest_Southeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 24342
Wilcoxon Test P-value: 0.1566063
Adjusted p-value: 0.2176003
Comparison: Northeast_Midwest_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 13453.5
Wilcoxon Test P-value: 0.04765912
Adjusted p-value: 0.07579523
Comparison: Northeast_Southeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2163
Wilcoxon Test P-value: 0.0006996987
Adjusted p-value: 0.001924171
Comparison: Midwest_Southeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 12848
Wilcoxon Test P-value: 2.861671e-05
Adjusted p-value: 0.0001144668
Comparison: Northeast_Midwest_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 20078.5
Wilcoxon Test P-value: 2.396909e-06
Adjusted p-value: 1.265568e-05
Comparison: Northeast_Southeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1604
Wilcoxon Test P-value: 8.178362e-05
Adjusted p-value: 0.0002917686
Comparison: Midwest_Southeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 24514
Wilcoxon Test P-value: 0.05810112
Adjusted p-value: 0.08715169
Comparison: Northeast_Midwest_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 32239
Wilcoxon Test P-value: 0.2890863
Adjusted p-value: 0.3533277
Comparison: Northeast_Southeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 2242
Wilcoxon Test P-value: 0.1648383
Adjusted p-value: 0.2220271
Comparison: Midwest_Southeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 22143
Wilcoxon Test P-value: 0.002245922
Adjusted p-value: 0.005201082
Comparison: Northeast_Midwest_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 18198.5
Wilcoxon Test P-value: 6.878696e-05
Adjusted p-value: 0.0002670553
Comparison: Northeast_Southeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 1269
Wilcoxon Test P-value: 0.000169341
Adjusted p-value: 0.0005731542
Comparison: Midwest_Southeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 18284
Wilcoxon Test P-value: 0.0535498
Adjusted p-value: 0.08315969
Comparison: Northeast_Midwest_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 8843
Wilcoxon Test P-value: 0.0003167263
Adjusted p-value: 0.0009501788
Comparison: Northeast_Southeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1707
Wilcoxon Test P-value: 0.1174179
Adjusted p-value: 0.1655459
Comparison: Midwest_Southeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 10347
Wilcoxon Test P-value: 2.707346e-05
Adjusted p-value: 0.000111678
Comparison: Northeast_Midwest_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 17320
Wilcoxon Test P-value: 8.340413e-06
Adjusted p-value: 3.669782e-05
Comparison: Northeast_Southeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1063
Wilcoxon Test P-value: 2.690533e-07
Adjusted p-value: 1.973058e-06
Comparison: Midwest_Southeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 17492
Wilcoxon Test P-value: 0.001607268
Adjusted p-value: 0.004003006
Comparison: Northeast_Midwest_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 27868
Wilcoxon Test P-value: 0.2095209
Adjusted p-value: 0.2685122
Comparison: Northeast_Southeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 1516
Wilcoxon Test P-value: 0.001918422
Adjusted p-value: 0.004521995
Comparison: Midwest_Southeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 12895
Wilcoxon Test P-value: 7.04401e-09
Adjusted p-value: 7.748411e-08
Comparison: Northeast_Midwest_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 16044
Wilcoxon Test P-value: 5.195836e-08
Adjusted p-value: 4.034414e-07
Comparison: Northeast_Southeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 1872
Wilcoxon Test P-value: 0.02229214
Adjusted p-value: 0.03925696
Comparison: Midwest_Southeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 30360
Wilcoxon Test P-value: 0.07597217
Adjusted p-value: 0.1114259
Comparison: Northeast_Midwest_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 6586
Wilcoxon Test P-value: 4.207884e-09
Adjusted p-value: 5.049461e-08
Comparison: Northeast_Southeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1509
Wilcoxon Test P-value: 0.6204056
Adjusted p-value: 0.6962533
Comparison: Midwest_Southeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 11268
Wilcoxon Test P-value: 2.709693e-08
Adjusted p-value: 2.384529e-07
Comparison: Northeast_Midwest_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 16021
Wilcoxon Test P-value: 4.855481e-08
Adjusted p-value: 4.005772e-07
Comparison: Northeast_Southeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1568
Wilcoxon Test P-value: 0.0003624755
Adjusted p-value: 0.001063262
Comparison: Midwest_Southeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 28063
Wilcoxon Test P-value: 0.5543959
Adjusted p-value: 0.6363501
Comparison: Northeast_Midwest_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 25909
Wilcoxon Test P-value: 0.7471288
Adjusted p-value: 0.7827063
Comparison: Northeast_Southeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 2370
Wilcoxon Test P-value: 0.8512985
Adjusted p-value: 0.8710961
Comparison: Midwest_Southeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 27115
Wilcoxon Test P-value: 0.9181391
Adjusted p-value: 0.9181391
Comparison: Northeast_Midwest_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 16382
Wilcoxon Test P-value: 4.789466e-06
Adjusted p-value: 2.341516e-05
Comparison: Northeast_Southeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 1812
Wilcoxon Test P-value: 0.209236
Adjusted p-value: 0.2685122
Comparison: Midwest_Southeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 32319
Wilcoxon Test P-value: 0.001726326
Adjusted p-value: 0.004143182
Comparison: Northeast_Midwest_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 6004
Wilcoxon Test P-value: 3.489084e-10
Adjusted p-value: 5.117324e-09
Comparison: Northeast_Southeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1556
Wilcoxon Test P-value: 0.007411661
Adjusted p-value: 0.01528655
Comparison: Midwest_Southeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 13551
Wilcoxon Test P-value: 1.228645e-11
Adjusted p-value: 2.316873e-10
Comparison: Northeast_Midwest_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 16239
Wilcoxon Test P-value: 3.32749e-06
Adjusted p-value: 1.689341e-05
Comparison: Northeast_Southeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1700
Wilcoxon Test P-value: 0.04197083
Adjusted p-value: 0.06839691
Comparison: Midwest_Southeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 30849
Wilcoxon Test P-value: 0.05291318
Adjusted p-value: 0.08314928
Comparison: Northeast_Midwest_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 26772
Wilcoxon Test P-value: 0.3611507
Adjusted p-value: 0.4294765
Comparison: Northeast_Southeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 2260
Wilcoxon Test P-value: 0.5883186
Adjusted p-value: 0.6694659
Comparison: Midwest_Southeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 26326
Wilcoxon Test P-value: 0.7213934
Adjusted p-value: 0.7617914
Comparison: Northeast_Midwest_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 14257
Wilcoxon Test P-value: 5.230114e-06
Adjusted p-value: 2.465625e-05
Comparison: Northeast_Southeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 1122
Wilcoxon Test P-value: 0.08251698
Adjusted p-value: 0.119695
Comparison: Midwest_Southeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 31715
Wilcoxon Test P-value: 0.02625866
Adjusted p-value: 0.04501484
Comparison: Northeast_Midwest_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 4672
Wilcoxon Test P-value: 1.811567e-13
Adjusted p-value: 4.782537e-12
Comparison: Northeast_Southeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 838
Wilcoxon Test P-value: 0.7839166
Adjusted p-value: 0.8147795
Comparison: Midwest_Southeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 13776.5
Wilcoxon Test P-value: 8.807671e-09
Adjusted p-value: 8.304375e-08
Comparison: Northeast_Midwest_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 13499
Wilcoxon Test P-value: 7.754613e-07
Adjusted p-value: 5.118045e-06
Comparison: Northeast_Southeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 926
Wilcoxon Test P-value: 0.002898996
Adjusted p-value: 0.006597715
Comparison: Midwest_Southeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 28824
Wilcoxon Test P-value: 0.3883497
Adjusted p-value: 0.4576978
Comparison: Northeast_Midwest_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 20653
Wilcoxon Test P-value: 0.1943833
Adjusted p-value: 0.2542953
Comparison: Northeast_Southeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 1227
Wilcoxon Test P-value: 0.2842132
Adjusted p-value: 0.3506182
Comparison: Midwest_Southeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 25942
Wilcoxon Test P-value: 0.6224082
Adjusted p-value: 0.6962533
Comparison: Northeast_Midwest_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 21121
Wilcoxon Test P-value: 2.228657e-09
Adjusted p-value: 2.941828e-08
Comparison: Northeast_Southeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 1606
Wilcoxon Test P-value: 0.01388027
Adjusted p-value: 0.02580557
Comparison: Midwest_Southeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 31012
Wilcoxon Test P-value: 0.003553034
Adjusted p-value: 0.00794916
Comparison: Northeast_Midwest_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 8598.5
Wilcoxon Test P-value: 8.690041e-17
Adjusted p-value: 1.147085e-14
Comparison: Northeast_Southeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2007
Wilcoxon Test P-value: 0.05472772
Adjusted p-value: 0.08400069
Comparison: Midwest_Southeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 19865
Wilcoxon Test P-value: 6.102811e-15
Adjusted p-value: 2.013928e-13
Comparison: Northeast_Midwest_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 19730
Wilcoxon Test P-value: 5.635671e-11
Adjusted p-value: 9.298857e-10
Comparison: Northeast_Southeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1081
Wilcoxon Test P-value: 3.671411e-07
Adjusted p-value: 2.550664e-06
Comparison: Midwest_Southeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 23384
Wilcoxon Test P-value: 0.1945745
Adjusted p-value: 0.2542953
Comparison: Northeast_Midwest_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 32655.5
Wilcoxon Test P-value: 0.2182953
Adjusted p-value: 0.2770671
Comparison: Northeast_Southeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 1692
Wilcoxon Test P-value: 0.01811221
Adjusted p-value: 0.03320572
Comparison: Midwest_Southeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 20809
Wilcoxon Test P-value: 0.01075146
Adjusted p-value: 0.02087048
Four Analytes All Years Comparison Mann-Whitney comparison for not normal distribution with Benjamini-Hochberg correction LOOP [just comparing regions, for all years] (Beef Solid)
Code
# Filter data for selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")filtered_data <- MDB_beefstackNPK[MDB_beefstackNPK$Region %in% selected_regions, ]# Initialize an empty list to store cleaned data for each nutrientcleaned_data_list <-list()# Loop over each nutrientfor (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Remove missing values for the current nutrient cleaned_data <- filtered_data[!is.na(filtered_data[[nutrient]]), ] cleaned_data_list[[nutrient]] <- cleaned_data}# Create a Function for Wilcoxon Test and Correctionperform_wilcoxon_test <-function(region1, region2, nutrient, data) {# Perform Wilcoxon rank sum test wilcox_result <-wilcox.test(data[data$Region == region1, nutrient], data[data$Region == region2, nutrient])# Apply Benjamini-Hochberg correction adjusted_p_value <-p.adjust(wilcox_result$p.value, method ="BH")# Return resultsreturn(list(wilcox_result = wilcox_result, adjusted_p_value = adjusted_p_value))}# Initialize empty vectorsall_p_values <-c()comparison_results <-list()comparison_names <-c()# Loop over regions, nutrients, perform tests, and gather p-valuesfor (region1 in selected_regions) {for (region2 in selected_regions) {if (region1 != region2) {for (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Perform Wilcoxon test and correction results <-perform_wilcoxon_test(region1, region2, nutrient, cleaned_data_list[[nutrient]])# Store p-value all_p_values <-c(all_p_values, results$wilcox_result$p.value)# Store comparison name comparison_names <-c(comparison_names, paste(region1, region2, nutrient, sep ="_"))# Store results comparison_results[[length(comparison_results) +1]] <- results } } }}# Apply Benjamini-Hochberg Procedureadjusted_p_values <-p.adjust(all_p_values, method ="BH")# Print resultsfor (i inseq_along(comparison_names)) { name_parts <-strsplit(comparison_names[i], "_")[[1]] region1 <- name_parts[1] region2 <- name_parts[2] nutrient <- name_parts[3]# Extract Wilcoxon test results result <- comparison_results[[i]]$wilcox_result# Print results with adjusted p-valuescat("Comparison:", comparison_names[i], "\n")cat("Region 1:", region1, "\n")cat("Region 2:", region2, "\n")cat("Nutrient:", nutrient, "\n")cat("Wilcoxon Test Statistic:", result$statistic, "\n")cat("Wilcoxon Test P-value:", result$p.value, "\n")cat("Adjusted p-value:", adjusted_p_values[i], "\n")cat("\n")}
Comparison: Midwest_Northeast_Total_N
Region 1: Midwest
Region 2: Northeast
Nutrient: Total
Wilcoxon Test Statistic: 4058739
Wilcoxon Test P-value: 3.356785e-48
Adjusted p-value: 1.007035e-47
Comparison: Midwest_Northeast_Ammonium.N
Region 1: Midwest
Region 2: Northeast
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2031229
Wilcoxon Test P-value: 6.242749e-63
Adjusted p-value: 2.4971e-62
Comparison: Midwest_Northeast_Phosphorus
Region 1: Midwest
Region 2: Northeast
Nutrient: Phosphorus
Wilcoxon Test Statistic: 4181152
Wilcoxon Test P-value: 2.263612e-64
Adjusted p-value: 1.358167e-63
Comparison: Midwest_Northeast_Potassium
Region 1: Midwest
Region 2: Northeast
Nutrient: Potassium
Wilcoxon Test Statistic: 3119052
Wilcoxon Test P-value: 0.2592915
Adjusted p-value: 0.2828635
Comparison: Midwest_Southeast_Total_N
Region 1: Midwest
Region 2: Southeast
Nutrient: Total
Wilcoxon Test Statistic: 3394215
Wilcoxon Test P-value: 6.822312e-06
Adjusted p-value: 9.096415e-06
Comparison: Midwest_Southeast_Ammonium.N
Region 1: Midwest
Region 2: Southeast
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1408893
Wilcoxon Test P-value: 2.067603e-68
Adjusted p-value: 2.481123e-67
Comparison: Midwest_Southeast_Phosphorus
Region 1: Midwest
Region 2: Southeast
Nutrient: Phosphorus
Wilcoxon Test Statistic: 3137598
Wilcoxon Test P-value: 0.5207
Adjusted p-value: 0.5207
Comparison: Midwest_Southeast_Potassium
Region 1: Midwest
Region 2: Southeast
Nutrient: Potassium
Wilcoxon Test Statistic: 2760293
Wilcoxon Test P-value: 9.052868e-10
Adjusted p-value: 1.55192e-09
Comparison: Northeast_Midwest_Total_N
Region 1: Northeast
Region 2: Midwest
Nutrient: Total
Wilcoxon Test Statistic: 2087248
Wilcoxon Test P-value: 3.356785e-48
Adjusted p-value: 1.007035e-47
Comparison: Northeast_Midwest_Ammonium.N
Region 1: Northeast
Region 2: Midwest
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 895541.5
Wilcoxon Test P-value: 6.242749e-63
Adjusted p-value: 2.4971e-62
Comparison: Northeast_Midwest_Phosphorus
Region 1: Northeast
Region 2: Midwest
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1905405
Wilcoxon Test P-value: 2.263612e-64
Adjusted p-value: 1.358167e-63
Comparison: Northeast_Midwest_Potassium
Region 1: Northeast
Region 2: Midwest
Nutrient: Potassium
Wilcoxon Test Statistic: 2967505
Wilcoxon Test P-value: 0.2592915
Adjusted p-value: 0.2828635
Comparison: Northeast_Southeast_Total_N
Region 1: Northeast
Region 2: Southeast
Nutrient: Total
Wilcoxon Test Statistic: 228877.5
Wilcoxon Test P-value: 3.457631e-11
Adjusted p-value: 6.915262e-11
Comparison: Northeast_Southeast_Ammonium.N
Region 1: Northeast
Region 2: Southeast
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 199644.5
Wilcoxon Test P-value: 2.383197e-05
Adjusted p-value: 2.859836e-05
Comparison: Northeast_Southeast_Phosphorus
Region 1: Northeast
Region 2: Southeast
Nutrient: Phosphorus
Wilcoxon Test Statistic: 186940
Wilcoxon Test P-value: 5.672693e-34
Adjusted p-value: 1.361446e-33
Comparison: Northeast_Southeast_Potassium
Region 1: Northeast
Region 2: Southeast
Nutrient: Potassium
Wilcoxon Test Statistic: 252340
Wilcoxon Test P-value: 4.982825e-06
Adjusted p-value: 7.474238e-06
Comparison: Southeast_Midwest_Total_N
Region 1: Southeast
Region 2: Midwest
Nutrient: Total
Wilcoxon Test Statistic: 2784420
Wilcoxon Test P-value: 6.822312e-06
Adjusted p-value: 9.096415e-06
Comparison: Southeast_Midwest_Ammonium.N
Region 1: Southeast
Region 2: Midwest
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 482557.5
Wilcoxon Test P-value: 2.067603e-68
Adjusted p-value: 2.481123e-67
Comparison: Southeast_Midwest_Phosphorus
Region 1: Southeast
Region 2: Midwest
Nutrient: Phosphorus
Wilcoxon Test Statistic: 3225990
Wilcoxon Test P-value: 0.5207
Adjusted p-value: 0.5207
Comparison: Southeast_Midwest_Potassium
Region 1: Southeast
Region 2: Midwest
Nutrient: Potassium
Wilcoxon Test Statistic: 3603296
Wilcoxon Test P-value: 9.052868e-10
Adjusted p-value: 1.55192e-09
Comparison: Southeast_Northeast_Total_N
Region 1: Southeast
Region 2: Northeast
Nutrient: Total
Wilcoxon Test Statistic: 341143.5
Wilcoxon Test P-value: 3.457631e-11
Adjusted p-value: 6.915262e-11
Comparison: Southeast_Northeast_Ammonium.N
Region 1: Southeast
Region 2: Northeast
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 149480.5
Wilcoxon Test P-value: 2.383197e-05
Adjusted p-value: 2.859836e-05
Comparison: Southeast_Northeast_Phosphorus
Region 1: Southeast
Region 2: Northeast
Nutrient: Phosphorus
Wilcoxon Test Statistic: 396467
Wilcoxon Test P-value: 5.672693e-34
Adjusted p-value: 1.361446e-33
Comparison: Southeast_Northeast_Potassium
Region 1: Southeast
Region 2: Northeast
Nutrient: Potassium
Wilcoxon Test Statistic: 331067
Wilcoxon Test P-value: 4.982825e-06
Adjusted p-value: 7.474238e-06
Mann-Kendall trend test 4 analytes combined regions (Beef Solid)
Code
# Load required librarylibrary(Kendall)# Function to perform Mann-Kendall trend test for a given analyte across all selected regionsperform_mk_test_combined <-function(data, analyte, selected_regions) {# Subset data for the selected regions and analyte filtered_data <- data[data$Region %in% selected_regions, ] cleaned_data <- filtered_data[!is.na(filtered_data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk))}# List of selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")# List of analytesanalytes <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Perform Mann-Kendall trend test for each analyte combined across selected regionsfor (analyte in analytes) {cat("Analyzing", analyte, "for all regions combined:\n")print(perform_mk_test_combined(MDB_beefstackNPK, analyte, selected_regions))cat("\n")}
Analyzing Total_N for all regions combined:
Score = 7 , Var(Score) = 163
denominator = 53.99074
tau = 0.13, 2-sided pvalue =0.63839
NULL
Analyzing Ammonium.N for all regions combined:
Score = 31 , Var(Score) = 163
denominator = 53.99074
tau = 0.574, 2-sided pvalue =0.018784
NULL
Analyzing Phosphorus for all regions combined:
Score = 5 , Var(Score) = 163
denominator = 53.99074
tau = 0.0926, 2-sided pvalue =0.75405
NULL
Analyzing Potassium for all regions combined:
Score = 3 , Var(Score) = 165
denominator = 55
tau = 0.0545, 2-sided pvalue =0.87627
NULL
Mann-Kendall 4 Analytes trend test by region Beef Solid
Code
# List of selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")# List of analytesanalytes <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Function to perform Mann-Kendall trend testperform_mk_test <-function(data, analyte) {# Filter out NA values in the analyte column cleaned_data <- data[!is.na(data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk))}# Iterate over selected regions and analytesfor (region in selected_regions) {for (analyte in analytes) {# Subset data for the current region region_data <- MDB_beefstackNPK[MDB_beefstackNPK$Region == region, ]# Print information about the current region and analytecat("Analyzing", analyte, "in", region, "region:\n")# Perform Mann-Kendall trend test result_summary <-perform_mk_test(region_data, analyte)# Print summary of the Mann-Kendall test resultprint(result_summary)cat("\n") }}
Four Analytes Line + IQR graph with counts + trend arrow (Beef Solid)
Code
# Filter out rows with non-missing Total_N values and for specific regionsMDB_beefstackNPK_filtered <- MDB_beefstackNPK[!is.na(MDB_beefstackNPK$Total_N) & MDB_beefstackNPK$Region %in%c("Midwest", "Northeast", "Southeast"), ]custom_theme <-theme_minimal() +theme(text =element_text(family ="Times New Roman", size =11),axis.text.x =element_text(angle =45, hjust =1) ) # Create separate plots for each nutrient typeplots <-list()# Initialize variables to store the minimum and maximum values of lower and upper quartilesmin_lower_quantile <-Infmax_upper_quantile <--Inf# Function to calculate counts for each nutrientcalculate_counts <-function(data, nutrient) { counts <- data %>%filter(!is.na(.data[[nutrient]]) & Year.Analyzed >=2012& Year.Analyzed <=2022) %>%group_by(Region) %>%summarise(total_samples =n())return(counts)}for (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Filter data for the current nutrient type filtered_data <- MDB_beefstackNPK_filtered[!is.na(MDB_beefstackNPK_filtered[[nutrient]]), ]# Calculate median and IQR for each combination of Year.Analyzed and Region summary_stats <- filtered_data %>%group_by(Year.Analyzed, Region) %>%summarise(median_value =median(.data[[nutrient]]),lower_quantile =quantile(.data[[nutrient]], 0.25),upper_quantile =quantile(.data[[nutrient]], 0.75)) %>%ungroup() # Remove grouping to avoid issues with plotting# Update minimum and maximum values of lower and upper quartiles min_lower_quantile <-min(min_lower_quantile, min(summary_stats$lower_quantile)) max_upper_quantile <-max(max_upper_quantile, max(summary_stats$upper_quantile))# Determine a suitable step size for the y-axis y_range <- max_upper_quantile - min_lower_quantile num_breaks <-max(4, floor(y_range *10)) # Ensure at least four breaks step_size <- y_range / num_breaks# Calculate counts for the current nutrient counts <-calculate_counts(filtered_data, nutrient)# Create line graph with median for each year and region, with connecting lines plot <-ggplot(summary_stats, aes(x =factor(Year.Analyzed), y = median_value, color = Region, group = Region)) +geom_ribbon(aes(ymin = lower_quantile, ymax = upper_quantile, fill = Region), alpha =0.3, position ="identity") +# Add shaded area for IQRgeom_line(aes(linetype = Region)) +# Add line graph with connecting linesgeom_point() +# Add points for each data pointlabs(x ="Year Analyzed", y =switch(nutrient,Total_N ="Total N (%)",Ammonium.N =expression(paste("NH"[4], "-N (%)")),Phosphorus =expression(paste("P"[2], "O"[5], " (%)")),Potassium =expression(paste("K"[2], "O (%)")) ), title =NULL) +# Remove titles for all graphs custom_theme +# Apply custom theme with font settingsscale_color_manual(values =c("Midwest"="blue", "Northeast"="darkgreen", "Southeast"="red")) +# Define colors for regionsscale_fill_manual(values =c("Midwest"="lightblue", "Northeast"="lightgreen", "Southeast"="lightpink")) +# Define fill colors for IQRguides(fill =FALSE) +# Remove legend for IQR fill colorsscale_y_continuous(limits =c(0, 1.5), breaks =seq(0, 1.5, by =0.25)) +# Specify breaks for y-axis labels and ensure continuous scalegeom_text(data = counts, aes(label =ifelse(Region =="Southeast"& nutrient =="Ammonium.N", paste("* n =", total_samples), paste("n =", total_samples)), x ="2021", y =1.5- (0.15*seq_along(total_samples)), color = Region), hjust =1, vjust =0, size =3) # Add text annotations for counts# Add the arrow only for the Ammonium.N graphif (nutrient =="Ammonium.N") { plot <- plot +annotate("segment", x ="2022", y =1.15, xend ="2022", yend =1, arrow =arrow(type ="open", length =unit(0.1, "inches")), color ="red") }# Add the plot to the list plots[[nutrient]] <- plot}# Arrange the plots together using patchworkbeefstack_final_plot <- plots[[1]] + plots[[2]] + plots[[3]] + plots[[4]] +plot_layout(guides ="collect")# Print the final plotprint(beefstack_final_plot)
Chicken - Broiler
Chicken - Broiler Solid Manure by Region Overview Table (%)
Table of samples by region by year for Chicken - Broiler solid manure
Code
# Create a table of number of samples for each region per yearMDB_broilerstackNPK <-filter(MDB_stack5fix, Animal.or.Other.Amendment.Type =="Chicken - Broiler")sample_table <-table(MDB_broilerstackNPK$Region, MDB_broilerstackNPK$Year.Analyzed)# Print the sample tableprint(sample_table) #NE and SE have samples all years
Mann-Kendall trend test for 4 analytes combined across selected regions and for each region separately (Chicken - Broiler solid)
Code
# Load required librarylibrary(Kendall)# List of selected regionsselected_regions <-c("Northeast", "Southeast")# List of analytesanalytes <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Function to perform Mann-Kendall trend test for a given analyte across all selected regionsperform_mk_test_combined <-function(data, analyte, selected_regions) {# Subset data for the selected regions and analyte filtered_data <- data[data$Region %in% selected_regions, ] cleaned_data <- filtered_data[!is.na(filtered_data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk_combined <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk_combined))}# Perform Mann-Kendall trend test for each analyte combined across selected regionsfor (analyte in analytes) {cat("Analyzing", analyte, "for all regions combined:\n")print(perform_mk_test_combined(MDB_broilerstackNPK, analyte, selected_regions))cat("\n")}
Analyzing Total_N for all regions combined:
Score = -11 , Var(Score) = 165
denominator = 55
tau = -0.2, 2-sided pvalue =0.43627
NULL
Analyzing Ammonium.N for all regions combined:
Score = -35 , Var(Score) = 165
denominator = 55
tau = -0.636, 2-sided pvalue =0.0081234
NULL
Analyzing Phosphorus for all regions combined:
Score = -13 , Var(Score) = 165
denominator = 55
tau = -0.236, 2-sided pvalue =0.3502
NULL
Analyzing Potassium for all regions combined:
Score = 41 , Var(Score) = 165
denominator = 55
tau = 0.745, 2-sided pvalue =0.0018457
NULL
Code
# Mann-Kendall trend test by region four 4 analytes# Function to perform Mann-Kendall trend testperform_mk_test <-function(data, analyte) {# Filter out NA values in the analyte column cleaned_data <- data[!is.na(data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk))}# Iterate over selected regions and analytesfor (region in selected_regions) {for (analyte in analytes) {# Subset data for the current region region_data <- MDB_broilerstackNPK[MDB_broilerstackNPK$Region == region, ]# Print information about the current region and analytecat("Analyzing", analyte, "in", region, "region:\n")# Perform Mann-Kendall trend test result_summary <-perform_mk_test(region_data, analyte)# Print summary of the Mann-Kendall test resultprint(result_summary)cat("\n") }}
Four Analytes Mann-Whitney comparison by year for not normal distribution with Benjamini-Hochberg correction LOOP (Chicken - Broiler solid)
Code
# Filter data for selected regionsselected_regions <-c("Northeast", "Southeast")filtered_data <- MDB_broilerstackNPK[MDB_broilerstackNPK$Region %in% selected_regions, ]# Initialize an empty list to store cleaned data for each nutrientcleaned_data_list <-list()# Loop over each nutrientfor (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Remove missing values for the current nutrient cleaned_data <- filtered_data[!is.na(filtered_data[[nutrient]]), ] cleaned_data_list[[nutrient]] <- cleaned_data}# Create a Function for Wilcoxon Test and Correctionperform_wilcoxon_test <-function(region1, region2, year, nutrient, data) {# Extract data for the given regions, year, and nutrient region1_data <- data[data$Region == region1 & data$Year.Analyzed == year, nutrient] region2_data <- data[data$Region == region2 & data$Year.Analyzed == year, nutrient]# Perform Wilcoxon rank sum test wilcox_result <-wilcox.test(region1_data, region2_data)# Apply Benjamini-Hochberg correction adjusted_p_value <-p.adjust(wilcox_result$p.value, method ="BH")# Return resultsreturn(list(wilcox_result = wilcox_result, adjusted_p_value = adjusted_p_value))}# Iterate Over Years, Regions, and Nutrientsyears <-unique(filtered_data$Year.Analyzed)regions <-unique(filtered_data$Region)nutrients <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Initialize empty vectorsall_p_values <-c()comparison_results <-list()comparison_names <-c()# Loop over years, regions, and nutrients, perform tests, and gather p-valuesindex <-1for (year in years) {for (nutrient in nutrients) {for (i in1:(length(regions)-1)) {for (j in (i+1):length(regions)) { region1 <- regions[i] region2 <- regions[j]# Perform Wilcoxon test and correction results <-perform_wilcoxon_test(region1, region2, year, nutrient, cleaned_data_list[[nutrient]])# Store p-value all_p_values <-c(all_p_values, results$wilcox_result$p.value)# Store comparison name comparison_names <-c(comparison_names, paste(region1, region2, year, nutrient, sep ="_"))# Store results comparison_results[[index]] <- results index <- index +1 } } }}# Sort comparison names based on yearsorted_indices <-order(as.numeric(sapply(strsplit(comparison_names, "_"), `[`, 3)))sorted_comparison_names <- comparison_names[sorted_indices]# Apply Benjamini-Hochberg Procedureadjusted_p_values <-p.adjust(all_p_values, method ="BH")# Print results in chronological orderfor (name in sorted_comparison_names) { index <-match(name, comparison_names) year <-as.numeric(unlist(strsplit(name, "_"))[3]) nutrient <-unlist(strsplit(name, "_"))[4]# Extract Wilcoxon test results result <- comparison_results[[index]]$wilcox_result# Print results with adjusted p-valuescat("Comparison:", name, "\n")cat("Year:", year, "\n")cat("Nutrient:", nutrient, "\n")cat("Wilcoxon Test Statistic:", result$statistic, "\n")cat("Wilcoxon Test P-value:", result$p.value, "\n")cat("Adjusted p-value:", adjusted_p_values[index], "\n")cat("\n")}
Comparison: Southeast_Northeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 23058
Wilcoxon Test P-value: 0.9177721
Adjusted p-value: 0.9177721
Comparison: Southeast_Northeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 4896
Wilcoxon Test P-value: 0.1615552
Adjusted p-value: 0.2090714
Comparison: Southeast_Northeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 17576
Wilcoxon Test P-value: 0.06198993
Adjusted p-value: 0.09091857
Comparison: Southeast_Northeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 27939
Wilcoxon Test P-value: 0.1425744
Adjusted p-value: 0.1900992
Comparison: Southeast_Northeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 25458
Wilcoxon Test P-value: 0.3172815
Adjusted p-value: 0.3988682
Comparison: Southeast_Northeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 7092
Wilcoxon Test P-value: 0.3493619
Adjusted p-value: 0.4269979
Comparison: Southeast_Northeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 24865
Wilcoxon Test P-value: 0.4278888
Adjusted p-value: 0.5088407
Comparison: Southeast_Northeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 29478
Wilcoxon Test P-value: 0.01617289
Adjusted p-value: 0.02846428
Comparison: Southeast_Northeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 56634
Wilcoxon Test P-value: 0.03094642
Adjusted p-value: 0.0486301
Comparison: Southeast_Northeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 28099
Wilcoxon Test P-value: 1.216229e-08
Adjusted p-value: 4.864918e-08
Comparison: Southeast_Northeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 73062
Wilcoxon Test P-value: 1.815159e-11
Adjusted p-value: 9.983372e-11
Comparison: Southeast_Northeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 62840
Wilcoxon Test P-value: 0.0001039004
Adjusted p-value: 0.0002406114
Comparison: Southeast_Northeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 116199
Wilcoxon Test P-value: 1.854813e-17
Adjusted p-value: 1.632235e-16
Comparison: Southeast_Northeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 37077
Wilcoxon Test P-value: 3.254062e-12
Adjusted p-value: 2.04541e-11
Comparison: Southeast_Northeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 132995
Wilcoxon Test P-value: 7.063484e-33
Adjusted p-value: 3.107933e-31
Comparison: Southeast_Northeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 127478
Wilcoxon Test P-value: 3.28991e-27
Adjusted p-value: 4.825201e-26
Comparison: Southeast_Northeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 43051.5
Wilcoxon Test P-value: 0.5072518
Adjusted p-value: 0.5722841
Comparison: Southeast_Northeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 10212
Wilcoxon Test P-value: 1.523772e-08
Adjusted p-value: 5.587162e-08
Comparison: Southeast_Northeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 61432
Wilcoxon Test P-value: 7.039787e-06
Adjusted p-value: 1.720837e-05
Comparison: Southeast_Northeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 68556
Wilcoxon Test P-value: 8.536835e-11
Adjusted p-value: 4.173564e-10
Comparison: Southeast_Northeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 124937
Wilcoxon Test P-value: 0.03488868
Adjusted p-value: 0.05293455
Comparison: Southeast_Northeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 31383
Wilcoxon Test P-value: 1.042037e-06
Adjusted p-value: 3.056642e-06
Comparison: Southeast_Northeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 173019
Wilcoxon Test P-value: 7.667619e-26
Adjusted p-value: 8.434381e-25
Comparison: Southeast_Northeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 179298
Wilcoxon Test P-value: 3.657969e-31
Adjusted p-value: 8.047531e-30
Comparison: Southeast_Northeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 29073
Wilcoxon Test P-value: 0.1112931
Adjusted p-value: 0.1579643
Comparison: Southeast_Northeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 18010
Wilcoxon Test P-value: 9.68709e-09
Adjusted p-value: 4.26232e-08
Comparison: Southeast_Northeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 35491
Wilcoxon Test P-value: 0.5712532
Adjusted p-value: 0.6130522
Comparison: Southeast_Northeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 41596
Wilcoxon Test P-value: 0.00847912
Adjusted p-value: 0.01622093
Comparison: Southeast_Northeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 14813
Wilcoxon Test P-value: 6.48831e-06
Adjusted p-value: 1.679327e-05
Comparison: Southeast_Northeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 11567
Wilcoxon Test P-value: 0.1323543
Adjusted p-value: 0.1819872
Comparison: Southeast_Northeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 26806
Wilcoxon Test P-value: 0.8821972
Adjusted p-value: 0.9027134
Comparison: Southeast_Northeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 28210
Wilcoxon Test P-value: 0.4879743
Adjusted p-value: 0.5650229
Comparison: Southeast_Northeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 43023
Wilcoxon Test P-value: 0.0186328
Adjusted p-value: 0.03153242
Comparison: Southeast_Northeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 17965
Wilcoxon Test P-value: 5.98391e-06
Adjusted p-value: 1.645575e-05
Comparison: Southeast_Northeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 50816
Wilcoxon Test P-value: 3.477186e-07
Adjusted p-value: 1.09283e-06
Comparison: Southeast_Northeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 44411
Wilcoxon Test P-value: 0.00449292
Adjusted p-value: 0.008985841
Comparison: Southeast_Northeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 15734.5
Wilcoxon Test P-value: 2.704815e-07
Adjusted p-value: 9.154758e-07
Comparison: Southeast_Northeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 10508
Wilcoxon Test P-value: 0.556905
Adjusted p-value: 0.6125956
Comparison: Southeast_Northeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 29156
Wilcoxon Test P-value: 0.7606414
Adjusted p-value: 0.7968624
Comparison: Southeast_Northeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 34128
Wilcoxon Test P-value: 0.02018754
Adjusted p-value: 0.03289821
Comparison: Southeast_Northeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 26169.5
Wilcoxon Test P-value: 0.0001489899
Adjusted p-value: 0.0003277779
Comparison: Southeast_Northeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 24463
Wilcoxon Test P-value: 6.248208e-17
Adjusted p-value: 4.58202e-16
Comparison: Southeast_Northeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 27281
Wilcoxon Test P-value: 0.0006796641
Adjusted p-value: 0.001424058
Comparison: Southeast_Northeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 43997
Wilcoxon Test P-value: 0.01096408
Adjusted p-value: 0.02010082
Chicken - Broiler 4 Analyte Median + IQR over time with counts + arrows
Code
# Filter out rows with non-missing Total_N values and for specific regionsMDB_broilerstackNPK_filtered <- MDB_broilerstackNPK[!is.na(MDB_broilerstackNPK$Total_N) & MDB_broilerstackNPK$Region %in%c("Northeast", "Southeast"), ]# Define custom theme with font settings and axis adjustmentscustom_theme <-theme_minimal() +theme(text =element_text(family ="Times New Roman", size =11),axis.text.x =element_text(angle =45, hjust =1))# Create separate plots for each nutrient typeplots <-list()# Initialize variables to store the minimum and maximum values of lower and upper quartilesmin_lower_quantile <-Infmax_upper_quantile <--Inf# Function to calculate counts for each nutrientcalculate_counts <-function(data, nutrient) { counts <- data %>%filter(!is.na(.data[[nutrient]]) & Year.Analyzed >=2012& Year.Analyzed <=2022) %>%group_by(Region) %>%summarise(total_samples =n())return(counts)}for (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Filter data for the current nutrient type filtered_data <- MDB_broilerstackNPK_filtered[!is.na(MDB_broilerstackNPK_filtered[[nutrient]]), ]# Calculate median and IQR for each combination of Year.Analyzed and Region summary_stats <- filtered_data %>%group_by(Year.Analyzed, Region) %>%summarise(median_value =median(.data[[nutrient]]),lower_quantile =quantile(.data[[nutrient]], 0.25),upper_quantile =quantile(.data[[nutrient]], 0.75)) %>%ungroup() # Remove grouping to avoid issues with plotting# Update minimum and maximum values of lower and upper quartiles min_lower_quantile <-min(min_lower_quantile, min(summary_stats$lower_quantile)) max_upper_quantile <-max(max_upper_quantile, max(summary_stats$upper_quantile))# Determine a suitable step size for the y-axis y_range <- max_upper_quantile - min_lower_quantile num_breaks <-max(4, floor(y_range *10)) # Ensure at least four breaks step_size <- y_range / num_breaks# Calculate counts for the current nutrient counts <-calculate_counts(filtered_data, nutrient)# Create line graph with median for each year and region, with connecting lines plot <-ggplot(summary_stats, aes(x =factor(Year.Analyzed), y = median_value, color = Region, group = Region)) +geom_ribbon(aes(ymin = lower_quantile, ymax = upper_quantile, fill = Region), alpha =0.3, pattern =1) +# Add cross-hatch pattern for IQRgeom_line(aes(linetype = Region)) +# Add line graph with connecting linesgeom_point() +# Add points for each data pointlabs(x ="Year Analyzed", y =switch(nutrient,Total_N ="Total N (%)",Ammonium.N =expression(paste("NH"[4], "-N (%)")),Phosphorus =expression(paste("P"[2], "O"[5], " (%)")),Potassium =expression(paste("K"[2], "O (%)")) ), title =NULL) +# Remove titles for all graphs custom_theme +# Apply custom theme with font settings and white backgroundscale_color_manual(values =c("Northeast"="darkgreen", "Southeast"="red")) +# Define colors for regionsscale_fill_manual(values =c("Northeast"="lightgreen", "Southeast"="lightpink")) +# Define fill colors for IQRguides(fill =FALSE) +# Remove legend for IQR fill colorsscale_y_continuous(limits =c(0, 4), breaks =seq(0, 4, by =1)) +# Specify breaks for y-axis labels and ensure continuous scalegeom_text(data = counts, aes(label =paste("n =", total_samples), x ="2021", y =2- (0.3*seq_along(total_samples)), color = Region), hjust =1, vjust =0, size =3, family ="Times New Roman") # Add text annotations for counts# Add the arrow only for the Ammonium.N graphif (nutrient =="Ammonium.N") { plot <- plot +annotate("segment", x ="2022", y =1.6, xend ="2022", yend =1.3, arrow =arrow(type ="open", length =unit(0.05, "inches")), color ="red") }if (nutrient =="Ammonium.N") { plot <- plot +annotate("segment", x ="2022", y =2, xend ="2022", yend =1.65, arrow =arrow(type ="open", length =unit(0.05, "inches")), color ="darkgreen")}if (nutrient =="Potassium") { plot <- plot +annotate("segment", x ="2022", y =1.3, xend ="2022", yend =1.65, arrow =arrow(type ="open", length =unit(0.05, "inches")), color ="red") }# Add the plot to the list plots[[nutrient]] <- plot}# Arrange the plots together using patchworkbroilerstack_final_plot <- plots[[1]] + plots[[2]] + plots[[3]] + plots[[4]] +plot_layout(guides ="collect")# Print the final plotprint(broilerstack_final_plot)
Chicken - Layer
Chicken - Layer Solid Manure by Region Overview Table (%)
Table of samples by region by year for Chicken Layer manure
Code
# Sort out for layer while still having separate NPK columnsMDB_layerstackNPK <-filter(MDB_stack5fix, Animal.or.Other.Amendment.Type =="Chicken - Layer")# Create a table of number of samples for each region per yearsample_table <-table(MDB_layerstackNPK$Region, MDB_layerstackNPK$Year.Analyzed)# Print the sample tableprint(sample_table)
Mann-Kendall trend test for 4 analytes combined across selected regions and for each region separately (Chicken - Layer)
Code
# Load required librarylibrary(Kendall)# List of selected regionsselected_regions <-c("Northeast", "Southeast")# List of analytesanalytes <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Function to perform Mann-Kendall trend test for a given analyte across all selected regionsperform_mk_test_combined <-function(data, analyte, selected_regions) {# Subset data for the selected regions and analyte filtered_data <- data[data$Region %in% selected_regions, ] cleaned_data <- filtered_data[!is.na(filtered_data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk_combined <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk_combined))}# Perform Mann-Kendall trend test for each analyte combined across selected regionsfor (analyte in analytes) {cat("Analyzing", analyte, "for all regions combined:\n")print(perform_mk_test_combined(MDB_layerstackNPK, analyte, selected_regions))cat("\n")}
Analyzing Total_N for all regions combined:
Score = -13 , Var(Score) = 165
denominator = 55
tau = -0.236, 2-sided pvalue =0.3502
NULL
Analyzing Ammonium.N for all regions combined:
Score = -41 , Var(Score) = 165
denominator = 55
tau = -0.745, 2-sided pvalue =0.0018457
NULL
Analyzing Phosphorus for all regions combined:
Score = -33 , Var(Score) = 165
denominator = 55
tau = -0.6, 2-sided pvalue =0.012731
NULL
Analyzing Potassium for all regions combined:
Score = -27 , Var(Score) = 165
denominator = 55
tau = -0.491, 2-sided pvalue =0.04296
NULL
Code
# Function to perform Mann-Kendall trend testperform_mk_test <-function(data, analyte) {# Filter out NA values in the analyte column cleaned_data <- data[!is.na(data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk))}# Iterate over selected regions and analytesfor (region in selected_regions) {for (analyte in analytes) {# Subset data for the current region region_data <- MDB_layerstackNPK[MDB_layerstackNPK$Region == region, ]# Print information about the current region and analytecat("Analyzing", analyte, "in", region, "region:\n")# Perform Mann-Kendall trend test result_summary <-perform_mk_test(region_data, analyte)# Print summary of the Mann-Kendall test resultprint(result_summary)cat("\n") }}
Four analytes Mann-Whitney comparison by year for not normal distribution with Benjamini-Hochberg correction LOOP (Chicken - Layer Solid)
Code
# Filter data for selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")filtered_data <- MDB_layerstackNPK[MDB_layerstackNPK$Region %in% selected_regions, ]# Initialize an empty list to store cleaned data for each nutrientcleaned_data_list <-list()# Loop over each nutrientfor (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Remove missing values for the current nutrient cleaned_data <- filtered_data[!is.na(filtered_data[[nutrient]]), ] cleaned_data_list[[nutrient]] <- cleaned_data}# Create a Function for Wilcoxon Test and Correctionperform_wilcoxon_test <-function(region1, region2, year, nutrient, data) {# Extract data for the given regions, year, and nutrient region1_data <- data[data$Region == region1 & data$Year.Analyzed == year, nutrient] region2_data <- data[data$Region == region2 & data$Year.Analyzed == year, nutrient]# Perform Wilcoxon rank sum test wilcox_result <-wilcox.test(region1_data, region2_data)# Perform Wilcoxon rank sum test with 'exact' argument#wilcox_result <- wilcox.test(region1_data, region2_data, exact = TRUE)# Apply Benjamini-Hochberg correction adjusted_p_value <-p.adjust(wilcox_result$p.value, method ="BH")# Return resultsreturn(list(wilcox_result = wilcox_result, adjusted_p_value = adjusted_p_value))}# Iterate Over Years, Regions, and Nutrientsyears <-unique(filtered_data$Year.Analyzed)regions <-unique(filtered_data$Region)nutrients <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Initialize empty vectorsall_p_values <-c()comparison_results <-list()comparison_names <-c()# Loop over years, regions, and nutrients, perform tests, and gather p-valuesindex <-1for (year in years) {for (nutrient in nutrients) {for (i in1:(length(regions)-1)) {for (j in (i+1):length(regions)) { region1 <- regions[i] region2 <- regions[j]# Perform Wilcoxon test and correction results <-perform_wilcoxon_test(region1, region2, year, nutrient, cleaned_data_list[[nutrient]])# Store p-value all_p_values <-c(all_p_values, results$wilcox_result$p.value)# Store comparison name comparison_names <-c(comparison_names, paste(region1, region2, year, nutrient, sep ="_"))# Store results comparison_results[[index]] <- results index <- index +1 } } }}# Sort comparison names based on yearsorted_indices <-order(as.numeric(sapply(strsplit(comparison_names, "_"), `[`, 3)))sorted_comparison_names <- comparison_names[sorted_indices]# Apply Benjamini-Hochberg Procedureadjusted_p_values <-p.adjust(all_p_values, method ="BH")# Print results in chronological orderfor (name in sorted_comparison_names) { index <-match(name, comparison_names) year <-as.numeric(unlist(strsplit(name, "_"))[3]) nutrient <-unlist(strsplit(name, "_"))[4]# Extract Wilcoxon test results result <- comparison_results[[index]]$wilcox_result# Print results with adjusted p-valuescat("Comparison:", name, "\n")cat("Year:", year, "\n")cat("Nutrient:", nutrient, "\n")cat("Wilcoxon Test Statistic:", result$statistic, "\n")cat("Wilcoxon Test P-value:", result$p.value, "\n")cat("Adjusted p-value:", adjusted_p_values[index], "\n")cat("\n")}
Comparison: Southeast_Midwest_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 1453
Wilcoxon Test P-value: 0.6280891
Adjusted p-value: 0.7676644
Comparison: Southeast_Northeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 16263
Wilcoxon Test P-value: 0.001885838
Adjusted p-value: 0.008030019
Comparison: Midwest_Northeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 939
Wilcoxon Test P-value: 0.07673466
Adjusted p-value: 0.1716776
Comparison: Southeast_Midwest_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 5
Wilcoxon Test P-value: 0.00417844
Adjusted p-value: 0.01662743
Comparison: Southeast_Northeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1378
Wilcoxon Test P-value: 5.88928e-26
Adjusted p-value: 7.77385e-24
Comparison: Midwest_Northeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 196
Wilcoxon Test P-value: 0.6077032
Adjusted p-value: 0.7567625
Comparison: Southeast_Midwest_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1899
Wilcoxon Test P-value: 0.3477627
Adjusted p-value: 0.4989639
Comparison: Southeast_Northeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 20689
Wilcoxon Test P-value: 6.386111e-13
Adjusted p-value: 2.107417e-11
Comparison: Midwest_Northeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 972
Wilcoxon Test P-value: 0.0414382
Adjusted p-value: 0.1139551
Comparison: Southeast_Midwest_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 1701
Wilcoxon Test P-value: 0.8360021
Adjusted p-value: 0.9464435
Comparison: Southeast_Northeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 20700
Wilcoxon Test P-value: 5.852419e-13
Adjusted p-value: 2.107417e-11
Comparison: Midwest_Northeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 1036
Wilcoxon Test P-value: 0.01043303
Adjusted p-value: 0.03358925
Comparison: Southeast_Midwest_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 684.5
Wilcoxon Test P-value: 0.05822502
Adjusted p-value: 0.1380952
Comparison: Southeast_Northeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 4307
Wilcoxon Test P-value: 0.8706341
Adjusted p-value: 0.9497827
Comparison: Midwest_Northeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 170
Wilcoxon Test P-value: 0.07604255
Adjusted p-value: 0.1716776
Comparison: Southeast_Midwest_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 10
Wilcoxon Test P-value: 0.1556771
Adjusted p-value: 0.2854081
Comparison: Southeast_Northeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 872
Wilcoxon Test P-value: 1.105768e-05
Adjusted p-value: 7.68218e-05
Comparison: Midwest_Northeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 19
Wilcoxon Test P-value: 0.7741935
Adjusted p-value: 0.9027055
Comparison: Southeast_Midwest_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1702
Wilcoxon Test P-value: 0.02138494
Adjusted p-value: 0.06272916
Comparison: Southeast_Northeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 5617
Wilcoxon Test P-value: 0.006824839
Adjusted p-value: 0.02252197
Comparison: Midwest_Northeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 87
Wilcoxon Test P-value: 0.2499664
Adjusted p-value: 0.4023849
Comparison: Southeast_Midwest_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 1343
Wilcoxon Test P-value: 0.4250161
Adjusted p-value: 0.5905487
Comparison: Southeast_Northeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 5693
Wilcoxon Test P-value: 0.004185208
Adjusted p-value: 0.01662743
Comparison: Midwest_Northeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 141
Wilcoxon Test P-value: 0.4704272
Adjusted p-value: 0.6209639
Comparison: Southeast_Midwest_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 1351.5
Wilcoxon Test P-value: 0.3317742
Adjusted p-value: 0.4863093
Comparison: Southeast_Northeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 3719
Wilcoxon Test P-value: 0.9892917
Adjusted p-value: 0.9936914
Comparison: Midwest_Northeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 173
Wilcoxon Test P-value: 0.2332888
Adjusted p-value: 0.3801744
Comparison: Southeast_Midwest_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 75
Wilcoxon Test P-value: 0.04915145
Adjusted p-value: 0.1247581
Comparison: Southeast_Northeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 770
Wilcoxon Test P-value: 2.481988e-06
Adjusted p-value: 2.520172e-05
Comparison: Midwest_Northeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 42
Wilcoxon Test P-value: 0.7796093
Adjusted p-value: 0.9027055
Comparison: Southeast_Midwest_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1678
Wilcoxon Test P-value: 0.9252017
Adjusted p-value: 0.9928994
Comparison: Southeast_Northeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 3973
Wilcoxon Test P-value: 0.6220653
Adjusted p-value: 0.7674076
Comparison: Midwest_Northeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 149
Wilcoxon Test P-value: 0.7098086
Adjusted p-value: 0.8365601
Comparison: Southeast_Midwest_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 1424
Wilcoxon Test P-value: 0.4413921
Adjusted p-value: 0.5945282
Comparison: Southeast_Northeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 3769
Wilcoxon Test P-value: 0.967308
Adjusted p-value: 0.9936914
Comparison: Midwest_Northeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 164
Wilcoxon Test P-value: 0.377525
Adjusted p-value: 0.5326553
Comparison: Southeast_Midwest_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 2197.5
Wilcoxon Test P-value: 0.9833434
Adjusted p-value: 0.9936914
Comparison: Southeast_Northeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 5584
Wilcoxon Test P-value: 0.004639691
Adjusted p-value: 0.0170122
Comparison: Midwest_Northeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 317
Wilcoxon Test P-value: 0.01423552
Adjusted p-value: 0.04369973
Comparison: Southeast_Midwest_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 228
Wilcoxon Test P-value: 0.0001602837
Adjusted p-value: 0.0008532465
Comparison: Southeast_Northeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 877
Wilcoxon Test P-value: 1.164663e-07
Adjusted p-value: 1.921694e-06
Comparison: Midwest_Northeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 165
Wilcoxon Test P-value: 0.5364991
Adjusted p-value: 0.6875523
Comparison: Southeast_Midwest_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1296
Wilcoxon Test P-value: 0.00443912
Adjusted p-value: 0.01674182
Comparison: Southeast_Northeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 6358
Wilcoxon Test P-value: 0.0001167785
Adjusted p-value: 0.0006702071
Comparison: Midwest_Northeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 382
Wilcoxon Test P-value: 1.312236e-05
Adjusted p-value: 8.660755e-05
Comparison: Southeast_Midwest_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 1292
Wilcoxon Test P-value: 0.004282823
Adjusted p-value: 0.01662743
Comparison: Southeast_Northeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 6851
Wilcoxon Test P-value: 1.286557e-06
Adjusted p-value: 1.415213e-05
Comparison: Midwest_Northeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 398
Wilcoxon Test P-value: 9.238159e-07
Adjusted p-value: 1.108579e-05
Comparison: Southeast_Midwest_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 2239
Wilcoxon Test P-value: 0.1464574
Adjusted p-value: 0.275767
Comparison: Southeast_Northeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 6849.5
Wilcoxon Test P-value: 3.33417e-07
Adjusted p-value: 4.401104e-06
Comparison: Midwest_Northeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 618.5
Wilcoxon Test P-value: 0.1361569
Adjusted p-value: 0.2682495
Comparison: Southeast_Midwest_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 771
Wilcoxon Test P-value: 0.01112864
Adjusted p-value: 0.03497573
Comparison: Southeast_Northeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2820
Wilcoxon Test P-value: 8.419571e-12
Adjusted p-value: 2.222767e-10
Comparison: Midwest_Northeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 614
Wilcoxon Test P-value: 0.8618433
Adjusted p-value: 0.9497827
Comparison: Southeast_Midwest_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 3295
Wilcoxon Test P-value: 0.3089055
Adjusted p-value: 0.4633583
Comparison: Southeast_Northeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 13347
Wilcoxon Test P-value: 0.02441572
Adjusted p-value: 0.07006251
Comparison: Midwest_Northeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 808
Wilcoxon Test P-value: 0.8787842
Adjusted p-value: 0.9508157
Comparison: Southeast_Midwest_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 2910
Wilcoxon Test P-value: 0.9804514
Adjusted p-value: 0.9936914
Comparison: Southeast_Northeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 15306
Wilcoxon Test P-value: 4.619636e-06
Adjusted p-value: 3.387733e-05
Comparison: Midwest_Northeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 1023
Wilcoxon Test P-value: 0.04274299
Adjusted p-value: 0.1151444
Comparison: Southeast_Midwest_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 2105.5
Wilcoxon Test P-value: 0.07639628
Adjusted p-value: 0.1716776
Comparison: Southeast_Northeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 7893
Wilcoxon Test P-value: 0.006001457
Adjusted p-value: 0.0214106
Comparison: Midwest_Northeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 890
Wilcoxon Test P-value: 0.9383906
Adjusted p-value: 0.9936914
Comparison: Southeast_Midwest_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 217
Wilcoxon Test P-value: 3.604954e-06
Adjusted p-value: 2.974087e-05
Comparison: Southeast_Northeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2397
Wilcoxon Test P-value: 6.003115e-08
Adjusted p-value: 1.132016e-06
Comparison: Midwest_Northeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 808
Wilcoxon Test P-value: 0.03419303
Adjusted p-value: 0.09603148
Comparison: Southeast_Midwest_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2996
Wilcoxon Test P-value: 0.4666637
Adjusted p-value: 0.6209639
Comparison: Southeast_Northeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 13429
Wilcoxon Test P-value: 2.781796e-06
Adjusted p-value: 2.622837e-05
Comparison: Midwest_Northeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1046
Wilcoxon Test P-value: 0.178134
Adjusted p-value: 0.3135159
Comparison: Southeast_Midwest_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 3204
Wilcoxon Test P-value: 0.1874371
Adjusted p-value: 0.3255486
Comparison: Southeast_Northeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 15741
Wilcoxon Test P-value: 5.716059e-15
Adjusted p-value: 3.772599e-13
Comparison: Midwest_Northeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 1216
Wilcoxon Test P-value: 0.006339862
Adjusted p-value: 0.02145799
Comparison: Southeast_Midwest_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 2856.5
Wilcoxon Test P-value: 0.3352587
Adjusted p-value: 0.4863093
Comparison: Southeast_Northeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 3571
Wilcoxon Test P-value: 0.08174325
Adjusted p-value: 0.174034
Comparison: Midwest_Northeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 181.5
Wilcoxon Test P-value: 0.1060308
Adjusted p-value: 0.2170272
Comparison: Southeast_Midwest_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 387
Wilcoxon Test P-value: 0.0003930479
Adjusted p-value: 0.001921568
Comparison: Southeast_Northeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 787
Wilcoxon Test P-value: 3.186285e-07
Adjusted p-value: 4.401104e-06
Comparison: Midwest_Northeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 192
Wilcoxon Test P-value: 0.6629693
Adjusted p-value: 0.7955632
Comparison: Southeast_Midwest_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2295
Wilcoxon Test P-value: 0.5020103
Adjusted p-value: 0.6496604
Comparison: Southeast_Northeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 5112
Wilcoxon Test P-value: 0.2071588
Adjusted p-value: 0.3505765
Comparison: Midwest_Northeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 305
Wilcoxon Test P-value: 0.276251
Adjusted p-value: 0.4290015
Comparison: Southeast_Midwest_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 2548
Wilcoxon Test P-value: 0.9869361
Adjusted p-value: 0.9936914
Comparison: Southeast_Northeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 5631
Wilcoxon Test P-value: 0.02108892
Adjusted p-value: 0.06272916
Comparison: Midwest_Northeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 303
Wilcoxon Test P-value: 0.2929241
Adjusted p-value: 0.4496045
Comparison: Southeast_Midwest_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 1350
Wilcoxon Test P-value: 0.001871887
Adjusted p-value: 0.008030019
Comparison: Southeast_Northeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 3576
Wilcoxon Test P-value: 0.0001615997
Adjusted p-value: 0.0008532465
Comparison: Midwest_Northeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 391
Wilcoxon Test P-value: 0.8401923
Adjusted p-value: 0.9464435
Comparison: Southeast_Midwest_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 213
Wilcoxon Test P-value: 6.091222e-05
Adjusted p-value: 0.0003828768
Comparison: Southeast_Northeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1042
Wilcoxon Test P-value: 1.633798e-08
Adjusted p-value: 3.594356e-07
Comparison: Midwest_Northeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 315
Wilcoxon Test P-value: 0.1961672
Adjusted p-value: 0.3362867
Comparison: Southeast_Midwest_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2046
Wilcoxon Test P-value: 0.2623061
Adjusted p-value: 0.4121953
Comparison: Southeast_Northeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 5659
Wilcoxon Test P-value: 0.9845967
Adjusted p-value: 0.9936914
Comparison: Midwest_Northeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 433
Wilcoxon Test P-value: 0.3793152
Adjusted p-value: 0.5326553
Comparison: Southeast_Midwest_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 2076
Wilcoxon Test P-value: 0.3014785
Adjusted p-value: 0.4574156
Comparison: Southeast_Northeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 6724
Wilcoxon Test P-value: 0.05273616
Adjusted p-value: 0.1289106
Comparison: Midwest_Northeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 487
Wilcoxon Test P-value: 0.08001779
Adjusted p-value: 0.174034
Comparison: Southeast_Midwest_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 1288
Wilcoxon Test P-value: 0.05858586
Adjusted p-value: 0.1380952
Comparison: Southeast_Northeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 1389
Wilcoxon Test P-value: 0.006287827
Adjusted p-value: 0.02145799
Comparison: Midwest_Northeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 169
Wilcoxon Test P-value: 0.4384297
Adjusted p-value: 0.5945282
Comparison: Southeast_Midwest_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 76
Wilcoxon Test P-value: 3.277429e-06
Adjusted p-value: 2.884137e-05
Comparison: Southeast_Northeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 398
Wilcoxon Test P-value: 4.055134e-06
Adjusted p-value: 3.148692e-05
Comparison: Midwest_Northeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 174
Wilcoxon Test P-value: 0.04495086
Adjusted p-value: 0.1168283
Comparison: Southeast_Midwest_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1429
Wilcoxon Test P-value: 0.1483292
Adjusted p-value: 0.275767
Comparison: Southeast_Northeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2032
Wilcoxon Test P-value: 0.5580305
Adjusted p-value: 0.7050077
Comparison: Midwest_Northeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 224
Wilcoxon Test P-value: 0.4924008
Adjusted p-value: 0.6435337
Comparison: Southeast_Midwest_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 1599
Wilcoxon Test P-value: 0.4340824
Adjusted p-value: 0.5945282
Comparison: Southeast_Northeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 2617
Wilcoxon Test P-value: 0.1452393
Adjusted p-value: 0.275767
Comparison: Midwest_Northeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 257
Wilcoxon Test P-value: 0.1124158
Adjusted p-value: 0.2248316
Comparison: Southeast_Midwest_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 1704
Wilcoxon Test P-value: 0.1670453
Adjusted p-value: 0.3020546
Comparison: Southeast_Northeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 1444.5
Wilcoxon Test P-value: 0.0001073132
Adjusted p-value: 0.0006438792
Comparison: Midwest_Northeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 205
Wilcoxon Test P-value: 0.04513822
Adjusted p-value: 0.1168283
Comparison: Southeast_Midwest_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 225
Wilcoxon Test P-value: 0.0003365128
Adjusted p-value: 0.00170845
Comparison: Southeast_Northeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 631
Wilcoxon Test P-value: 0.0004920331
Adjusted p-value: 0.002319584
Comparison: Midwest_Northeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 248
Wilcoxon Test P-value: 0.1693911
Adjusted p-value: 0.3021572
Comparison: Southeast_Midwest_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2460
Wilcoxon Test P-value: 0.2235315
Adjusted p-value: 0.3734956
Comparison: Southeast_Northeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2393
Wilcoxon Test P-value: 0.3292184
Adjusted p-value: 0.4863093
Comparison: Midwest_Northeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 223
Wilcoxon Test P-value: 0.09893432
Adjusted p-value: 0.207291
Comparison: Southeast_Midwest_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 2526
Wilcoxon Test P-value: 0.1454126
Adjusted p-value: 0.275767
Comparison: Southeast_Northeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 2699
Wilcoxon Test P-value: 0.9936914
Adjusted p-value: 0.9936914
Comparison: Midwest_Northeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 225
Wilcoxon Test P-value: 0.1068695
Adjusted p-value: 0.2170272
Comparison: Southeast_Midwest_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 1157
Wilcoxon Test P-value: 0.635746
Adjusted p-value: 0.7698943
Comparison: Southeast_Northeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 2021
Wilcoxon Test P-value: 0.0006632632
Adjusted p-value: 0.003018991
Comparison: Midwest_Northeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 121
Wilcoxon Test P-value: 0.08066288
Adjusted p-value: 0.174034
Comparison: Southeast_Midwest_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 515
Wilcoxon Test P-value: 0.7951143
Adjusted p-value: 0.912653
Comparison: Southeast_Northeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1738
Wilcoxon Test P-value: 0.2284288
Adjusted p-value: 0.3769076
Comparison: Midwest_Northeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 148
Wilcoxon Test P-value: 0.8460631
Adjusted p-value: 0.9464435
Comparison: Southeast_Midwest_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1271
Wilcoxon Test P-value: 0.954773
Adjusted p-value: 0.9936914
Comparison: Southeast_Northeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2594
Wilcoxon Test P-value: 0.05009227
Adjusted p-value: 0.1247581
Comparison: Midwest_Northeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 143
Wilcoxon Test P-value: 0.2536444
Adjusted p-value: 0.4033863
Comparison: Southeast_Midwest_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 1322
Wilcoxon Test P-value: 0.8648985
Adjusted p-value: 0.9497827
Comparison: Southeast_Northeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 3102
Wilcoxon Test P-value: 0.5608016
Adjusted p-value: 0.7050077
Comparison: Midwest_Northeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 171
Wilcoxon Test P-value: 0.6984722
Adjusted p-value: 0.8306156
Four analyte median + IQR plots 2012-2022 with counts + arrows (Chicken-Layer )
Code
# Filter out rows with non-missing Total_N values and for specific regionsMDB_layerstackNPK_filtered <- MDB_layerstackNPK[!is.na(MDB_layerstackNPK$Total_N) & MDB_layerstackNPK$Region %in%c("Northeast", "Southeast"), ]custom_theme <-theme_minimal() +theme(text =element_text(family ="Times New Roman", size =11),axis.text.x =element_text(angle =45, hjust =1) )# Create separate plots for each nutrient typeplots <-list()# Initialize variables to store the minimum and maximum values of lower and upper quartilesmin_lower_quantile <-Infmax_upper_quantile <--Inf# Function to calculate counts for each nutrientcalculate_counts <-function(data, nutrient) { counts <- data %>%filter(!is.na(.data[[nutrient]]) & Year.Analyzed >=2012& Year.Analyzed <=2022) %>%group_by(Region) %>%summarise(total_samples =n()) %>%ungroup() # Remove grouping to avoid issues with plottingreturn(counts)}for (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Filter data for the current nutrient type filtered_data <- MDB_layerstackNPK_filtered[!is.na(MDB_layerstackNPK_filtered[[nutrient]]), ]# Calculate median and IQR for each combination of Year.Analyzed and Region summary_stats <- filtered_data %>%group_by(Year.Analyzed, Region) %>%summarise(median_value =median(.data[[nutrient]]),lower_quantile =quantile(.data[[nutrient]], 0.25),upper_quantile =quantile(.data[[nutrient]], 0.75)) %>%ungroup() # Remove grouping to avoid issues with plotting# Update minimum and maximum values of lower and upper quartiles min_lower_quantile <-min(min_lower_quantile, min(summary_stats$lower_quantile)) max_upper_quantile <-max(max_upper_quantile, max(summary_stats$upper_quantile))# Determine a suitable step size for the y-axis y_range <- max_upper_quantile - min_lower_quantile num_breaks <-max(4, floor(y_range *10)) # Ensure at least four breaks step_size <- y_range / num_breaks# Calculate counts for the current nutrient counts <-calculate_counts(filtered_data, nutrient)# Create line graph with median for each year and region, with connecting lines plot <-ggplot(summary_stats, aes(x =factor(Year.Analyzed), y = median_value, color = Region, group = Region)) +geom_ribbon(aes(ymin = lower_quantile, ymax = upper_quantile, fill = Region), alpha =0.3) +# Add shaded area for IQRgeom_line(aes(linetype = Region)) +# Add line graph with connecting linesgeom_point() +# Add points for each data pointlabs(x ="Year Analyzed", y =switch(nutrient,Total_N ="Total N (%)",Ammonium.N =expression(paste("NH"[4], "-N (%)")),Phosphorus =expression(paste("P"[2], "O"[5], " (%)")),Potassium =expression(paste("K"[2], "O (%)")) ), title =NULL) +# Remove titles for all graphs custom_theme +# Apply custom theme with font settingsscale_color_manual(values =c("Northeast"="darkgreen", "Southeast"="red", "Midwest"="blue")) +# Define colors for regionsscale_fill_manual(values =c("Northeast"="lightgreen", "Southeast"="lightpink", "Midwest"="lightblue")) +# Define fill colors for IQRguides(fill =FALSE) +# Remove legend for IQR fill colorsscale_y_continuous(limits =c(0, 5), breaks =seq(0, 5, by =1))+#breaks = seq(ceiling(min_lower_quantile), floor(max_upper_quantile), by = step_size),#expand = c(0, 0)) # Specify breaks for y-axis labels and ensure continuous scalegeom_text(data = counts, aes(label =paste("n =", total_samples), x ="2021", y =5- (0.4*seq_along(total_samples)), color = Region), hjust =1, vjust =0, size =3, family ="Times New Roman") # Add text annotations for counts # Add the arrow only for the Ammonium.N graphif (nutrient =="Ammonium.N") { plot <- plot +annotate("segment", x ="2022", y =4.5, xend ="2022", yend =4.1, arrow =arrow(type ="open", length =unit(0.05, "inches")), color ="red") }if (nutrient =="Phosphorus") { plot <- plot +annotate("segment", x ="2022", y =4.5, xend ="2022", yend =4.1, arrow =arrow(type ="open", length =unit(0.05, "inches")), color ="red")}if (nutrient =="Potassium") { plot <- plot +annotate("segment", x ="2022", y =4.5, xend ="2022", yend =4.1, arrow =arrow(type ="open", length =unit(0.05, "inches")), color ="red")}# Add the plot to the list plots[[nutrient]] <- plot}# Arrange the plots together using patchworklayerstack_final_plot <- plots[[1]] + plots[[2]] + plots[[3]] + plots[[4]] +plot_layout(guides ="collect")# Print the final plotprint(layerstack_final_plot)
Table of samples by region by year for Dairy Solid manure
Code
# Sort out for dairy while still having separate NPK columnsMDB_dairystackNPK <-filter(MDB_stack5fix, Animal.or.Other.Amendment.Type =="Dairy")# Create a table of number of samples for each region per yearsample_table <-table(MDB_dairystackNPK$Region, MDB_dairystackNPK$Year.Analyzed)# Print the sample tableprint(sample_table)
Mann-Kendall trend test for 4 analytes combined across selected regions and for each region separately (Dairy solid)
Code
# Load required librarylibrary(Kendall)# List of selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")# List of analytesanalytes <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Function to perform Mann-Kendall trend test for a given analyte across all selected regionsperform_mk_test_combined <-function(data, analyte, selected_regions) {# Subset data for the selected regions and analyte filtered_data <- data[data$Region %in% selected_regions, ] cleaned_data <- filtered_data[!is.na(filtered_data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk_combined <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk_combined))}# Perform Mann-Kendall trend test for each analyte combined across selected regionsfor (analyte in analytes) {cat("Analyzing", analyte, "for all regions combined:\n")print(perform_mk_test_combined(MDB_dairystackNPK, analyte, selected_regions))cat("\n")}
Analyzing Total_N for all regions combined:
Score = -24 , Var(Score) = 164
denominator = 54.4977
tau = -0.44, 2-sided pvalue =0.072495
NULL
Analyzing Ammonium.N for all regions combined:
Score = 5 , Var(Score) = 165
denominator = 55
tau = 0.0909, 2-sided pvalue =0.7555
NULL
Analyzing Phosphorus for all regions combined:
Score = -39 , Var(Score) = 163
denominator = 53.99074
tau = -0.722, 2-sided pvalue =0.0029166
NULL
Analyzing Potassium for all regions combined:
Score = -29 , Var(Score) = 165
denominator = 55
tau = -0.527, 2-sided pvalue =0.029273
NULL
Code
# Function to perform Mann-Kendall trend testperform_mk_test <-function(data, analyte) {# Filter out NA values in the analyte column cleaned_data <- data[!is.na(data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk))}# Iterate over selected regions and analytesfor (region in selected_regions) {for (analyte in analytes) {# Subset data for the current region region_data <- MDB_dairystackNPK[MDB_dairystackNPK$Region == region, ]# Print information about the current region and analytecat("Analyzing", analyte, "in", region, "region:\n")# Perform Mann-Kendall trend test result_summary <-perform_mk_test(region_data, analyte)# Print summary of the Mann-Kendall test resultprint(result_summary)cat("\n") }}
Four Analytes Mann-Whitney comparison by year for not normal distribution with Benjamini-Hochberg correction LOOP (Dairy Solid)
Code
# Filter data for selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")filtered_data <- MDB_dairystackNPK[MDB_dairystackNPK$Region %in% selected_regions, ]# Initialize an empty list to store cleaned data for each nutrientcleaned_data_list <-list()# Loop over each nutrientfor (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Remove missing values for the current nutrient cleaned_data <- filtered_data[!is.na(filtered_data[[nutrient]]), ] cleaned_data_list[[nutrient]] <- cleaned_data}# Create a Function for Wilcoxon Test and Correctionperform_wilcoxon_test <-function(region1, region2, year, nutrient, data) {# Extract data for the given regions, year, and nutrient region1_data <- data[data$Region == region1 & data$Year.Analyzed == year, nutrient] region2_data <- data[data$Region == region2 & data$Year.Analyzed == year, nutrient]# Perform Wilcoxon rank sum test wilcox_result <-wilcox.test(region1_data, region2_data)# Apply Benjamini-Hochberg correction adjusted_p_value <-p.adjust(wilcox_result$p.value, method ="BH")# Return resultsreturn(list(wilcox_result = wilcox_result, adjusted_p_value = adjusted_p_value))}# Iterate Over Years, Regions, and Nutrientsyears <-unique(filtered_data$Year.Analyzed)regions <-unique(filtered_data$Region)nutrients <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Initialize empty vectorsall_p_values <-c()comparison_results <-list()comparison_names <-c()# Loop over years, regions, and nutrients, perform tests, and gather p-valuesindex <-1for (year in years) {for (nutrient in nutrients) {for (i in1:(length(regions)-1)) {for (j in (i+1):length(regions)) { region1 <- regions[i] region2 <- regions[j]# Perform Wilcoxon test and correction results <-perform_wilcoxon_test(region1, region2, year, nutrient, cleaned_data_list[[nutrient]])# Store p-value all_p_values <-c(all_p_values, results$wilcox_result$p.value)# Store comparison name comparison_names <-c(comparison_names, paste(region1, region2, year, nutrient, sep ="_"))# Store results comparison_results[[index]] <- results index <- index +1 } } }}# Sort comparison names based on yearsorted_indices <-order(as.numeric(sapply(strsplit(comparison_names, "_"), `[`, 3)))sorted_comparison_names <- comparison_names[sorted_indices]# Apply Benjamini-Hochberg Procedureadjusted_p_values <-p.adjust(all_p_values, method ="BH")# Print results in chronological orderfor (name in sorted_comparison_names) { index <-match(name, comparison_names) year <-as.numeric(unlist(strsplit(name, "_"))[3]) nutrient <-unlist(strsplit(name, "_"))[4]# Extract Wilcoxon test results result <- comparison_results[[index]]$wilcox_result# Print results with adjusted p-valuescat("Comparison:", name, "\n")cat("Year:", year, "\n")cat("Nutrient:", nutrient, "\n")cat("Wilcoxon Test Statistic:", result$statistic, "\n")cat("Wilcoxon Test P-value:", result$p.value, "\n")cat("Adjusted p-value:", adjusted_p_values[index], "\n")cat("\n")}
Comparison: Northeast_Midwest_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 246760.5
Wilcoxon Test P-value: 0.004084169
Adjusted p-value: 0.005924289
Comparison: Northeast_Southeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 70989
Wilcoxon Test P-value: 4.413459e-05
Adjusted p-value: 8.567304e-05
Comparison: Midwest_Southeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 93605
Wilcoxon Test P-value: 9.339594e-07
Adjusted p-value: 2.450997e-06
Comparison: Northeast_Midwest_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 67359
Wilcoxon Test P-value: 7.623292e-06
Adjusted p-value: 1.677124e-05
Comparison: Northeast_Southeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 97755
Wilcoxon Test P-value: 7.951853e-41
Adjusted p-value: 5.248223e-39
Comparison: Midwest_Southeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 51155
Wilcoxon Test P-value: 8.561367e-38
Adjusted p-value: 1.883501e-36
Comparison: Northeast_Midwest_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 228998
Wilcoxon Test P-value: 0.614742
Adjusted p-value: 0.6460259
Comparison: Northeast_Southeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 62666.5
Wilcoxon Test P-value: 6.884542e-26
Adjusted p-value: 9.087595e-25
Comparison: Midwest_Southeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 98487
Wilcoxon Test P-value: 5.914025e-18
Adjusted p-value: 4.592066e-17
Comparison: Northeast_Midwest_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 264548.5
Wilcoxon Test P-value: 4.325327e-08
Adjusted p-value: 1.327775e-07
Comparison: Northeast_Southeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 100813.5
Wilcoxon Test P-value: 0.2485859
Adjusted p-value: 0.2804559
Comparison: Midwest_Southeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 125307
Wilcoxon Test P-value: 0.0004142282
Adjusted p-value: 0.0007010016
Comparison: Northeast_Midwest_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 346888
Wilcoxon Test P-value: 0.9660515
Adjusted p-value: 0.9741233
Comparison: Northeast_Southeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 69179
Wilcoxon Test P-value: 0.002012525
Adjusted p-value: 0.003200642
Comparison: Midwest_Southeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 129709
Wilcoxon Test P-value: 0.008185077
Adjusted p-value: 0.01149394
Comparison: Northeast_Midwest_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 189201
Wilcoxon Test P-value: 0.000143334
Adjusted p-value: 0.0002556769
Comparison: Northeast_Southeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 81478
Wilcoxon Test P-value: 4.223562e-40
Adjusted p-value: 1.858367e-38
Comparison: Midwest_Southeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 56765.5
Wilcoxon Test P-value: 4.791936e-08
Adjusted p-value: 1.437581e-07
Comparison: Northeast_Midwest_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 338772
Wilcoxon Test P-value: 0.1197335
Adjusted p-value: 0.1386388
Comparison: Northeast_Southeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 79109
Wilcoxon Test P-value: 1.509764e-08
Adjusted p-value: 5.109972e-08
Comparison: Midwest_Southeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 149864
Wilcoxon Test P-value: 1.716324e-06
Adjusted p-value: 4.274619e-06
Comparison: Northeast_Midwest_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 360201
Wilcoxon Test P-value: 0.5839728
Adjusted p-value: 0.6216485
Comparison: Northeast_Southeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 109002
Wilcoxon Test P-value: 0.07812447
Adjusted p-value: 0.09460945
Comparison: Midwest_Southeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 193482
Wilcoxon Test P-value: 0.07086208
Adjusted p-value: 0.08660921
Comparison: Northeast_Midwest_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 277932
Wilcoxon Test P-value: 0.004520865
Adjusted p-value: 0.006416712
Comparison: Northeast_Southeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 58813
Wilcoxon Test P-value: 9.958806e-06
Adjusted p-value: 2.120262e-05
Comparison: Midwest_Southeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 141914
Wilcoxon Test P-value: 0.002357684
Adjusted p-value: 0.003665989
Comparison: Northeast_Midwest_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 197505
Wilcoxon Test P-value: 4.572024e-06
Adjusted p-value: 1.097286e-05
Comparison: Northeast_Southeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 52605
Wilcoxon Test P-value: 1.528035e-26
Adjusted p-value: 2.241119e-25
Comparison: Midwest_Southeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 51786.5
Wilcoxon Test P-value: 1.241026e-05
Adjusted p-value: 2.600245e-05
Comparison: Northeast_Midwest_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 282473.5
Wilcoxon Test P-value: 0.01886458
Adjusted p-value: 0.02540943
Comparison: Northeast_Southeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 54782
Wilcoxon Test P-value: 1.018144e-17
Adjusted p-value: 7.466391e-17
Comparison: Midwest_Southeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 137508
Wilcoxon Test P-value: 3.647548e-13
Adjusted p-value: 1.851832e-12
Comparison: Northeast_Midwest_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 311595.5
Wilcoxon Test P-value: 0.4226448
Adjusted p-value: 0.4572878
Comparison: Northeast_Southeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 86366
Wilcoxon Test P-value: 0.5619299
Adjusted p-value: 0.6030468
Comparison: Midwest_Southeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 186800
Wilcoxon Test P-value: 0.9858598
Adjusted p-value: 0.9858598
Comparison: Northeast_Midwest_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 280198
Wilcoxon Test P-value: 2.597903e-07
Adjusted p-value: 7.454851e-07
Comparison: Northeast_Southeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 61754
Wilcoxon Test P-value: 8.399055e-06
Adjusted p-value: 1.817501e-05
Comparison: Midwest_Southeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 139190
Wilcoxon Test P-value: 0.1161507
Adjusted p-value: 0.1356804
Comparison: Northeast_Midwest_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 247031
Wilcoxon Test P-value: 1.129195e-09
Adjusted p-value: 4.258677e-09
Comparison: Northeast_Southeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 67705
Wilcoxon Test P-value: 5.742038e-38
Adjusted p-value: 1.515898e-36
Comparison: Midwest_Southeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 57323.5
Wilcoxon Test P-value: 0.001268767
Adjusted p-value: 0.002067621
Comparison: Northeast_Midwest_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 306732.5
Wilcoxon Test P-value: 7.527035e-07
Adjusted p-value: 2.069935e-06
Comparison: Northeast_Southeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 66701
Wilcoxon Test P-value: 1.163667e-13
Adjusted p-value: 6.144162e-13
Comparison: Midwest_Southeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 144882
Wilcoxon Test P-value: 4.222846e-05
Adjusted p-value: 8.319637e-05
Comparison: Northeast_Midwest_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 340280
Wilcoxon Test P-value: 0.3319069
Adjusted p-value: 0.3650975
Comparison: Northeast_Southeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 95907
Wilcoxon Test P-value: 0.03244919
Adjusted p-value: 0.04283293
Comparison: Midwest_Southeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 182947.5
Wilcoxon Test P-value: 0.06372236
Adjusted p-value: 0.07935237
Comparison: Northeast_Midwest_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 564786
Wilcoxon Test P-value: 5.555452e-09
Adjusted p-value: 1.929789e-08
Comparison: Northeast_Southeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 79187
Wilcoxon Test P-value: 0.1570006
Adjusted p-value: 0.1802093
Comparison: Midwest_Southeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 182670.5
Wilcoxon Test P-value: 5.844736e-06
Adjusted p-value: 1.330181e-05
Comparison: Northeast_Midwest_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 283433.5
Wilcoxon Test P-value: 4.470619e-15
Adjusted p-value: 2.810104e-14
Comparison: Northeast_Southeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 80555
Wilcoxon Test P-value: 2.514458e-48
Adjusted p-value: 3.319085e-46
Comparison: Midwest_Southeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 72371
Wilcoxon Test P-value: 2.871603e-05
Adjusted p-value: 5.743206e-05
Comparison: Northeast_Midwest_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 570376.5
Wilcoxon Test P-value: 2.679e-05
Adjusted p-value: 5.440432e-05
Comparison: Northeast_Southeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 72654
Wilcoxon Test P-value: 2.867424e-09
Adjusted p-value: 1.022973e-08
Comparison: Midwest_Southeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 169533
Wilcoxon Test P-value: 3.331992e-15
Adjusted p-value: 2.199115e-14
Comparison: Northeast_Midwest_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 570211
Wilcoxon Test P-value: 4.518487e-10
Adjusted p-value: 1.807395e-09
Comparison: Northeast_Southeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 95142
Wilcoxon Test P-value: 0.2519117
Adjusted p-value: 0.2817996
Comparison: Midwest_Southeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 223053
Wilcoxon Test P-value: 0.08874713
Adjusted p-value: 0.1064966
Comparison: Northeast_Midwest_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 555413
Wilcoxon Test P-value: 0.03351545
Adjusted p-value: 0.04321371
Comparison: Northeast_Southeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 68507.5
Wilcoxon Test P-value: 0.02053193
Adjusted p-value: 0.0273759
Comparison: Midwest_Southeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 195854.5
Wilcoxon Test P-value: 0.0001390923
Adjusted p-value: 0.0002515093
Comparison: Northeast_Midwest_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 332481
Wilcoxon Test P-value: 1.455765e-18
Adjusted p-value: 1.201006e-17
Comparison: Northeast_Southeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 64025.5
Wilcoxon Test P-value: 3.220525e-33
Adjusted p-value: 6.07299e-32
Comparison: Midwest_Southeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 71852
Wilcoxon Test P-value: 0.002728452
Adjusted p-value: 0.004103315
Comparison: Northeast_Midwest_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 572715.5
Wilcoxon Test P-value: 0.003073116
Adjusted p-value: 0.004557879
Comparison: Northeast_Southeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 71025
Wilcoxon Test P-value: 3.004788e-06
Adjusted p-value: 7.345038e-06
Comparison: Midwest_Southeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 203201
Wilcoxon Test P-value: 5.558481e-10
Adjusted p-value: 2.157999e-09
Comparison: Northeast_Midwest_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 604671.5
Wilcoxon Test P-value: 2.224184e-08
Adjusted p-value: 7.160788e-08
Comparison: Northeast_Southeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 85230
Wilcoxon Test P-value: 0.6166611
Adjusted p-value: 0.6460259
Comparison: Midwest_Southeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 234988
Wilcoxon Test P-value: 0.004374776
Adjusted p-value: 0.006276852
Comparison: Northeast_Midwest_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 509223
Wilcoxon Test P-value: 0.9667436
Adjusted p-value: 0.9741233
Comparison: Northeast_Southeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 56306
Wilcoxon Test P-value: 1.490095e-07
Adjusted p-value: 4.370944e-07
Comparison: Midwest_Southeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 173083
Wilcoxon Test P-value: 3.367378e-07
Adjusted p-value: 9.457316e-07
Comparison: Northeast_Midwest_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 326598.5
Wilcoxon Test P-value: 6.780247e-15
Adjusted p-value: 4.068148e-14
Comparison: Northeast_Southeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 62534.5
Wilcoxon Test P-value: 5.652881e-40
Adjusted p-value: 1.865451e-38
Comparison: Midwest_Southeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 70231.5
Wilcoxon Test P-value: 5.488944e-06
Adjusted p-value: 1.271124e-05
Comparison: Northeast_Midwest_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 554494.5
Wilcoxon Test P-value: 0.001476552
Adjusted p-value: 0.002376889
Comparison: Northeast_Southeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 55134
Wilcoxon Test P-value: 6.049585e-14
Adjusted p-value: 3.471936e-13
Comparison: Midwest_Southeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 162692
Wilcoxon Test P-value: 1.791052e-17
Adjusted p-value: 1.24431e-16
Comparison: Northeast_Midwest_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 566331
Wilcoxon Test P-value: 5.786372e-05
Adjusted p-value: 0.0001106958
Comparison: Northeast_Southeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 70504
Wilcoxon Test P-value: 0.002735543
Adjusted p-value: 0.004103315
Comparison: Midwest_Southeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 194988
Wilcoxon Test P-value: 9.655442e-07
Adjusted p-value: 2.450997e-06
Comparison: Northeast_Midwest_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 531420.5
Wilcoxon Test P-value: 0.06592649
Adjusted p-value: 0.08132988
Comparison: Northeast_Southeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 56996.5
Wilcoxon Test P-value: 0.03336698
Adjusted p-value: 0.04321371
Comparison: Midwest_Southeast_2019_Total_N
Year: 2019
Nutrient: Total
Wilcoxon Test Statistic: 161206
Wilcoxon Test P-value: 0.001038113
Adjusted p-value: 0.001712887
Comparison: Northeast_Midwest_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 154144.5
Wilcoxon Test P-value: 0.03371979
Adjusted p-value: 0.04321371
Comparison: Northeast_Southeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 57950
Wilcoxon Test P-value: 1.389194e-31
Adjusted p-value: 2.29217e-30
Comparison: Midwest_Southeast_2019_Ammonium.N
Year: 2019
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 53950
Wilcoxon Test P-value: 2.792914e-25
Adjusted p-value: 3.351496e-24
Comparison: Northeast_Midwest_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 595401
Wilcoxon Test P-value: 1.369899e-10
Adjusted p-value: 5.833118e-10
Comparison: Northeast_Southeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 57910.5
Wilcoxon Test P-value: 7.715694e-05
Adjusted p-value: 0.0001434467
Comparison: Midwest_Southeast_2019_Phosphorus
Year: 2019
Nutrient: Phosphorus
Wilcoxon Test Statistic: 149141
Wilcoxon Test P-value: 1.568246e-12
Adjusted p-value: 7.666979e-12
Comparison: Northeast_Midwest_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 609861.5
Wilcoxon Test P-value: 9.029353e-14
Adjusted p-value: 4.966144e-13
Comparison: Northeast_Southeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 75348.5
Wilcoxon Test P-value: 0.09772543
Adjusted p-value: 0.116214
Comparison: Midwest_Southeast_2019_Potassium
Year: 2019
Nutrient: Potassium
Wilcoxon Test Statistic: 196954
Wilcoxon Test P-value: 0.2022155
Adjusted p-value: 0.2301073
Comparison: Northeast_Midwest_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 393665.5
Wilcoxon Test P-value: 0.002585431
Adjusted p-value: 0.003968336
Comparison: Northeast_Southeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 30530
Wilcoxon Test P-value: 0.003443199
Adjusted p-value: 0.005050026
Comparison: Midwest_Southeast_2020_Total_N
Year: 2020
Nutrient: Total
Wilcoxon Test Statistic: 162306
Wilcoxon Test P-value: 5.292636e-06
Adjusted p-value: 1.24755e-05
Comparison: Northeast_Midwest_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 122280
Wilcoxon Test P-value: 0.09986155
Adjusted p-value: 0.117694
Comparison: Northeast_Southeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 34937
Wilcoxon Test P-value: 4.891053e-24
Adjusted p-value: 5.380159e-23
Comparison: Midwest_Southeast_2020_Ammonium.N
Year: 2020
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 69136
Wilcoxon Test P-value: 5.642035e-22
Adjusted p-value: 5.728836e-21
Comparison: Northeast_Midwest_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 410850
Wilcoxon Test P-value: 6.421143e-06
Adjusted p-value: 1.436595e-05
Comparison: Northeast_Southeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 31375
Wilcoxon Test P-value: 9.591379e-07
Adjusted p-value: 2.450997e-06
Comparison: Midwest_Southeast_2020_Phosphorus
Year: 2020
Nutrient: Phosphorus
Wilcoxon Test Statistic: 169873
Wilcoxon Test P-value: 3.769156e-11
Adjusted p-value: 1.776888e-10
Comparison: Northeast_Midwest_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 431883.5
Wilcoxon Test P-value: 3.255908e-10
Adjusted p-value: 1.343062e-09
Comparison: Northeast_Southeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 41708
Wilcoxon Test P-value: 0.8137448
Adjusted p-value: 0.8391743
Comparison: Midwest_Southeast_2020_Potassium
Year: 2020
Nutrient: Potassium
Wilcoxon Test Statistic: 211969
Wilcoxon Test P-value: 0.03790381
Adjusted p-value: 0.04810869
Comparison: Northeast_Midwest_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 479433.5
Wilcoxon Test P-value: 0.05641487
Adjusted p-value: 0.07092155
Comparison: Northeast_Southeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 31485.5
Wilcoxon Test P-value: 0.002360674
Adjusted p-value: 0.003665989
Comparison: Midwest_Southeast_2021_Total_N
Year: 2021
Nutrient: Total
Wilcoxon Test Statistic: 133553
Wilcoxon Test P-value: 0.0003290656
Adjusted p-value: 0.000571535
Comparison: Northeast_Midwest_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 130920
Wilcoxon Test P-value: 0.0003409495
Adjusted p-value: 0.0005844849
Comparison: Northeast_Southeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 33031.5
Wilcoxon Test P-value: 3.619046e-21
Adjusted p-value: 3.412244e-20
Comparison: Midwest_Southeast_2021_Ammonium.N
Year: 2021
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 48301
Wilcoxon Test P-value: 2.596849e-19
Adjusted p-value: 2.285227e-18
Comparison: Northeast_Midwest_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 503632
Wilcoxon Test P-value: 0.0001918379
Adjusted p-value: 0.0003376348
Comparison: Northeast_Southeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 30350
Wilcoxon Test P-value: 3.328208e-08
Adjusted p-value: 1.046008e-07
Comparison: Midwest_Southeast_2021_Phosphorus
Year: 2021
Nutrient: Phosphorus
Wilcoxon Test Statistic: 127501
Wilcoxon Test P-value: 5.454988e-11
Adjusted p-value: 2.48296e-10
Comparison: Northeast_Midwest_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 499665.5
Wilcoxon Test P-value: 0.000588744
Adjusted p-value: 0.0009837242
Comparison: Northeast_Southeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 41897
Wilcoxon Test P-value: 0.927836
Adjusted p-value: 0.9494136
Comparison: Midwest_Southeast_2021_Potassium
Year: 2021
Nutrient: Potassium
Wilcoxon Test Statistic: 173363
Wilcoxon Test P-value: 0.3916142
Adjusted p-value: 0.4272155
Comparison: Northeast_Midwest_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 264457
Wilcoxon Test P-value: 0.01840668
Adjusted p-value: 0.02504826
Comparison: Northeast_Southeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 25112.5
Wilcoxon Test P-value: 1.599739e-08
Adjusted p-value: 5.27914e-08
Comparison: Midwest_Southeast_2022_Total_N
Year: 2022
Nutrient: Total
Wilcoxon Test Statistic: 88053
Wilcoxon Test P-value: 6.65995e-05
Adjusted p-value: 0.0001255876
Comparison: Northeast_Midwest_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 136167
Wilcoxon Test P-value: 0.01626237
Adjusted p-value: 0.02236075
Comparison: Northeast_Southeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 38837
Wilcoxon Test P-value: 9.810351e-11
Adjusted p-value: 4.316555e-10
Comparison: Midwest_Southeast_2022_Ammonium.N
Year: 2022
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 63453.5
Wilcoxon Test P-value: 1.858819e-09
Adjusted p-value: 6.81567e-09
Comparison: Northeast_Midwest_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 295643
Wilcoxon Test P-value: 0.2917679
Adjusted p-value: 0.3236417
Comparison: Northeast_Southeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 31444.5
Wilcoxon Test P-value: 9.610247e-05
Adjusted p-value: 0.0001761879
Comparison: Midwest_Southeast_2022_Phosphorus
Year: 2022
Nutrient: Phosphorus
Wilcoxon Test Statistic: 95544
Wilcoxon Test P-value: 1.380516e-05
Adjusted p-value: 2.847314e-05
Comparison: Northeast_Midwest_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 331108.5
Wilcoxon Test P-value: 8.054879e-07
Adjusted p-value: 2.169886e-06
Comparison: Northeast_Southeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 38669
Wilcoxon Test P-value: 0.7622511
Adjusted p-value: 0.792261
Comparison: Midwest_Southeast_2022_Potassium
Year: 2022
Nutrient: Potassium
Wilcoxon Test Statistic: 104978.5
Wilcoxon Test P-value: 0.008824136
Adjusted p-value: 0.01226091
Four analyte median + IQR plots 2012-2022 + counts and arrows (Dairy Solid)
Code
# Filter out rows with non-missing Total_N values and for specific regionsMDB_dairystackNPK_filtered <- MDB_dairystackNPK[!is.na(MDB_dairystackNPK$Total_N) & MDB_dairystackNPK$Region %in%c("Northeast", "Southeast", "Midwest"), ]custom_theme <-theme_minimal() +theme(text =element_text(family ="Times New Roman", size =11),axis.text.x =element_text(angle =45, hjust =1) )# Create separate plots for each nutrient typeplots <-list()# Initialize variables to store the minimum and maximum values of lower and upper quartilesmin_lower_quantile <-Infmax_upper_quantile <--Inf# Function to calculate counts for each nutrientcalculate_counts <-function(data) { counts <- data %>%filter(!is.na(Total_N) & Year.Analyzed >=2012& Year.Analyzed <=2022) %>%group_by(Region) %>%summarise(total_samples =n()) %>%ungroup() # Remove grouping to avoid issues with plottingreturn(counts)}for (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Filter data for the current nutrient type filtered_data <- MDB_dairystackNPK_filtered[!is.na(MDB_dairystackNPK_filtered[[nutrient]]), ]# Calculate median and IQR for each combination of Year.Analyzed and Region summary_stats <- filtered_data %>%group_by(Year.Analyzed, Region) %>%summarise(median_value =median(.data[[nutrient]]),lower_quantile =quantile(.data[[nutrient]], 0.25),upper_quantile =quantile(.data[[nutrient]], 0.75)) %>%ungroup() # Remove grouping to avoid issues with plotting# Update minimum and maximum values of lower and upper quartiles min_lower_quantile <-min(min_lower_quantile, min(summary_stats$lower_quantile)) max_upper_quantile <-max(max_upper_quantile, max(summary_stats$upper_quantile))# Determine a suitable step size for the y-axis y_range <- max_upper_quantile - min_lower_quantile num_breaks <-max(4, floor(y_range *10)) # Ensure at least four breaks step_size <- y_range / num_breaks# Calculate counts for all regions counts <-calculate_counts(filtered_data)# Create line graph with median for each year and region, with connecting lines plot <-ggplot(summary_stats, aes(x =factor(Year.Analyzed), y = median_value, color = Region, group = Region)) +geom_ribbon(aes(ymin = lower_quantile, ymax = upper_quantile, fill = Region), alpha =0.3) +# Add shaded area for IQRgeom_line(aes(linetype = Region)) +# Add line graph with connecting linesgeom_point() +# Add points for each data pointlabs(x ="Year Analyzed",y =switch(nutrient,Total_N ="Total N (%)",Ammonium.N =expression(paste("NH"[4], "-N (%)")),Phosphorus =expression(paste("P"[2], "O"[5], " (%)")),Potassium =expression(paste("K"[2], "O (%)")) ),title =NULL) +# Remove titles for all graphs custom_theme +# Apply custom theme with font settingsscale_color_manual(values =c("Northeast"="darkgreen", "Southeast"="red", "Midwest"="blue")) +# Define colors for regionsscale_fill_manual(values =c("Northeast"="lightgreen", "Southeast"="lightpink", "Midwest"="lightblue")) +# Define fill colors for IQRguides(fill =FALSE) +# Remove legend for IQR fill colorsscale_y_continuous(limits =c(0, 1), breaks =seq(0, 1, by = .25)) +geom_text(data = counts, aes(label =paste("n =", total_samples),x ="2021", y =1- (0.08*seq_along(total_samples)), color = Region),hjust =1, vjust =0, size =3, family ="Times New Roman") # Add text annotations for counts# Add the arrow only for the Ammonium.N graphif (nutrient =="Total_N") { plot <- plot +annotate("segment", x ="2022", y = .9, xend ="2022", yend = .81, arrow =arrow(type ="open", length =unit(0.1, "inches")), color ="darkgreen") }if (nutrient =="Ammonium.N") { plot <- plot +annotate("segment", x ="2022", y = .9, xend ="2022", yend = .81, arrow =arrow(type ="open", length =unit(0.1, "inches")), color ="darkgreen") }if (nutrient =="Phosphorus") { plot <- plot +annotate("segment", x ="2022", y =1, xend ="2022", yend = .9, arrow =arrow(type ="open", length =unit(0.1, "inches")), color ="blue") }# Add the plot to the list plots[[nutrient]] <- plot}# Arrange the plots together using patchworkdairystack_final_plot <- plots[[1]] + plots[[2]] + plots[[3]] + plots[[4]] +plot_layout(guides ="collect")# Print the final plotprint(dairystack_final_plot)
Table of samples by region by year for Turkey solid manure
Code
# Sort out for turkey while still having separate NPK columnsMDB_turkeystackNPK <-filter(MDB_stack5fix, Animal.or.Other.Amendment.Type =="Turkey")# Create a table of number of samples for each region per yearsample_table <-table(MDB_turkeystackNPK$Region, MDB_turkeystackNPK$Year.Analyzed)# Print the sample tableprint(sample_table)
Mann-Kendall trend test for 4 analytes combined across selected regions and for each region separately (Turkey Solid)
Code
# Load required librarylibrary(Kendall)# List of selected regionsselected_regions <-c("Midwest", "Southeast")# List of analytesanalytes <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Function to perform Mann-Kendall trend test for a given analyte across all selected regionsperform_mk_test_combined <-function(data, analyte, selected_regions) {# Subset data for the selected regions and analyte filtered_data <- data[data$Region %in% selected_regions, ] cleaned_data <- filtered_data[!is.na(filtered_data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk_combined <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk_combined))}# Perform Mann-Kendall trend test for each analyte combined across selected regionsfor (analyte in analytes) {cat("Analyzing", analyte, "for all regions combined:\n")print(perform_mk_test_combined(MDB_turkeystackNPK, analyte, selected_regions))cat("\n")}
Analyzing Total_N for all regions combined:
Score = -5 , Var(Score) = 165
denominator = 55
tau = -0.0909, 2-sided pvalue =0.7555
NULL
Analyzing Ammonium.N for all regions combined:
Score = -17 , Var(Score) = 165
denominator = 55
tau = -0.309, 2-sided pvalue =0.21291
NULL
Analyzing Phosphorus for all regions combined:
Score = -39 , Var(Score) = 165
denominator = 55
tau = -0.709, 2-sided pvalue =0.0030935
NULL
Analyzing Potassium for all regions combined:
Score = 15 , Var(Score) = 165
denominator = 55
tau = 0.273, 2-sided pvalue =0.27576
NULL
Code
# Function to perform Mann-Kendall trend testperform_mk_test <-function(data, analyte) {# Filter out NA values in the analyte column cleaned_data <- data[!is.na(data[[analyte]]), ]# Aggregate data by year and calculate median for the analyte aggregated_data <-aggregate(cleaned_data[[analyte]] ~ Year.Analyzed, data = cleaned_data, FUN = median)# Perform Mann-Kendall trend test result_mk <-MannKendall(aggregated_data[[2]])# Return summary of the Mann-Kendall test resultreturn(summary(result_mk))}# Iterate over selected regions and analytesfor (region in selected_regions) {for (analyte in analytes) {# Subset data for the current region region_data <- MDB_turkeystackNPK[MDB_turkeystackNPK$Region == region, ]# Print information about the current region and analytecat("Analyzing", analyte, "in", region, "region:\n")# Perform Mann-Kendall trend test result_summary <-perform_mk_test(region_data, analyte)# Print summary of the Mann-Kendall test resultprint(result_summary)cat("\n") }}
Four Analytes Mann-Whitney comparison by year for not normal distribution with Benjamini-Hochberg correction LOOP (Turkey Solid)
Code
# Filter data for selected regionsselected_regions <-c("Midwest", "Northeast", "Southeast")filtered_data <- MDB_turkeystackNPK[MDB_turkeystackNPK$Region %in% selected_regions, ]# Initialize an empty list to store cleaned data for each nutrientcleaned_data_list <-list()# Loop over each nutrientfor (nutrient inc("Total_N", "Ammonium.N", "Phosphorus", "Potassium")) {# Remove missing values for the current nutrient cleaned_data <- filtered_data[!is.na(filtered_data[[nutrient]]), ] cleaned_data_list[[nutrient]] <- cleaned_data}# Create a Function for Wilcoxon Test and Correctionperform_wilcoxon_test <-function(region1, region2, year, nutrient, data) {# Extract data for the given regions, year, and nutrient region1_data <- data[data$Region == region1 & data$Year.Analyzed == year, nutrient] region2_data <- data[data$Region == region2 & data$Year.Analyzed == year, nutrient]# Perform Wilcoxon rank sum test wilcox_result <-wilcox.test(region1_data, region2_data)# Apply Benjamini-Hochberg correction adjusted_p_value <-p.adjust(wilcox_result$p.value, method ="BH")# Return resultsreturn(list(wilcox_result = wilcox_result, adjusted_p_value = adjusted_p_value))}# Iterate Over Years, Regions, and Nutrientsyears <-unique(filtered_data$Year.Analyzed)regions <-unique(filtered_data$Region)nutrients <-c("Total_N", "Ammonium.N", "Phosphorus", "Potassium")# Initialize empty vectorsall_p_values <-c()comparison_results <-list()comparison_names <-c()# Loop over years, regions, and nutrients, perform tests, and gather p-valuesindex <-1for (year in years) {for (nutrient in nutrients) {for (i in1:(length(regions)-1)) {for (j in (i+1):length(regions)) { region1 <- regions[i] region2 <- regions[j]# Perform Wilcoxon test and correction results <-perform_wilcoxon_test(region1, region2, year, nutrient, cleaned_data_list[[nutrient]])# Store p-value all_p_values <-c(all_p_values, results$wilcox_result$p.value)# Store comparison name comparison_names <-c(comparison_names, paste(region1, region2, year, nutrient, sep ="_"))# Store results comparison_results[[index]] <- results index <- index +1 } } }}# Sort comparison names based on yearsorted_indices <-order(as.numeric(sapply(strsplit(comparison_names, "_"), `[`, 3)))sorted_comparison_names <- comparison_names[sorted_indices]# Apply Benjamini-Hochberg Procedureadjusted_p_values <-p.adjust(all_p_values, method ="BH")# Print results in chronological orderfor (name in sorted_comparison_names) { index <-match(name, comparison_names) year <-as.numeric(unlist(strsplit(name, "_"))[3]) nutrient <-unlist(strsplit(name, "_"))[4]# Extract Wilcoxon test results result <- comparison_results[[index]]$wilcox_result# Print results with adjusted p-valuescat("Comparison:", name, "\n")cat("Year:", year, "\n")cat("Nutrient:", nutrient, "\n")cat("Wilcoxon Test Statistic:", result$statistic, "\n")cat("Wilcoxon Test P-value:", result$p.value, "\n")cat("Adjusted p-value:", adjusted_p_values[index], "\n")cat("\n")}
Comparison: Midwest_Southeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 30433
Wilcoxon Test P-value: 0.9961638
Adjusted p-value: 0.9961638
Comparison: Midwest_Northeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 1509
Wilcoxon Test P-value: 0.2459761
Adjusted p-value: 0.3491273
Comparison: Southeast_Northeast_2012_Total_N
Year: 2012
Nutrient: Total
Wilcoxon Test Statistic: 5934
Wilcoxon Test P-value: 0.2412691
Adjusted p-value: 0.3484366
Comparison: Midwest_Southeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 16598
Wilcoxon Test P-value: 3.619086e-16
Adjusted p-value: 4.777194e-14
Comparison: Midwest_Northeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1337
Wilcoxon Test P-value: 0.0001930398
Adjusted p-value: 0.0007962893
Comparison: Southeast_Northeast_2012_Ammonium.N
Year: 2012
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2665
Wilcoxon Test P-value: 0.4130107
Adjusted p-value: 0.5047909
Comparison: Midwest_Southeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 21920
Wilcoxon Test P-value: 1.434156e-06
Adjusted p-value: 9.963609e-06
Comparison: Midwest_Northeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 465
Wilcoxon Test P-value: 2.604999e-06
Adjusted p-value: 1.637428e-05
Comparison: Southeast_Northeast_2012_Phosphorus
Year: 2012
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2975
Wilcoxon Test P-value: 0.001025238
Adjusted p-value: 0.003657607
Comparison: Midwest_Southeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 28806
Wilcoxon Test P-value: 0.3549019
Adjusted p-value: 0.4461623
Comparison: Midwest_Northeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 826.5
Wilcoxon Test P-value: 0.007612942
Adjusted p-value: 0.02050833
Comparison: Southeast_Northeast_2012_Potassium
Year: 2012
Nutrient: Potassium
Wilcoxon Test Statistic: 3592
Wilcoxon Test P-value: 0.01856339
Adjusted p-value: 0.04375655
Comparison: Midwest_Southeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 13591
Wilcoxon Test P-value: 0.0347434
Adjusted p-value: 0.0727957
Comparison: Midwest_Northeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 335
Wilcoxon Test P-value: 0.8766659
Adjusted p-value: 0.9184119
Comparison: Southeast_Northeast_2013_Total_N
Year: 2013
Nutrient: Total
Wilcoxon Test Statistic: 2119
Wilcoxon Test P-value: 0.4989535
Adjusted p-value: 0.5933502
Comparison: Midwest_Southeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 7379
Wilcoxon Test P-value: 0.001851498
Adjusted p-value: 0.005960921
Comparison: Midwest_Northeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 268
Wilcoxon Test P-value: 0.2115274
Adjusted p-value: 0.3172911
Comparison: Southeast_Northeast_2013_Ammonium.N
Year: 2013
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1062
Wilcoxon Test P-value: 0.8692122
Adjusted p-value: 0.9178881
Comparison: Midwest_Southeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 10456
Wilcoxon Test P-value: 1.289274e-06
Adjusted p-value: 9.454677e-06
Comparison: Midwest_Northeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 158
Wilcoxon Test P-value: 0.007991053
Adjusted p-value: 0.02109638
Comparison: Southeast_Northeast_2013_Phosphorus
Year: 2013
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1476
Wilcoxon Test P-value: 0.277994
Adjusted p-value: 0.3822417
Comparison: Midwest_Southeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 12402
Wilcoxon Test P-value: 0.001650912
Adjusted p-value: 0.005448009
Comparison: Midwest_Northeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 167
Wilcoxon Test P-value: 0.0115501
Adjusted p-value: 0.02989437
Comparison: Southeast_Northeast_2013_Potassium
Year: 2013
Nutrient: Potassium
Wilcoxon Test Statistic: 1223
Wilcoxon Test P-value: 0.07527204
Adjusted p-value: 0.1419416
Comparison: Midwest_Southeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 23418
Wilcoxon Test P-value: 0.8906342
Adjusted p-value: 0.9254175
Comparison: Midwest_Northeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 2042
Wilcoxon Test P-value: 0.9734644
Adjusted p-value: 0.9808954
Comparison: Southeast_Northeast_2014_Total_N
Year: 2014
Nutrient: Total
Wilcoxon Test Statistic: 7059
Wilcoxon Test P-value: 0.6487875
Adjusted p-value: 0.7319654
Comparison: Midwest_Southeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 6181
Wilcoxon Test P-value: 6.301401e-06
Adjusted p-value: 3.78084e-05
Comparison: Midwest_Northeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1327
Wilcoxon Test P-value: 1.076335e-08
Adjusted p-value: 1.092894e-07
Comparison: Southeast_Northeast_2014_Ammonium.N
Year: 2014
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 5760
Wilcoxon Test P-value: 5.463243e-08
Adjusted p-value: 4.507176e-07
Comparison: Midwest_Southeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 17244
Wilcoxon Test P-value: 2.75167e-05
Adjusted p-value: 0.0001397002
Comparison: Midwest_Northeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2100
Wilcoxon Test P-value: 0.7714325
Adjusted p-value: 0.8457171
Comparison: Southeast_Northeast_2014_Phosphorus
Year: 2014
Nutrient: Phosphorus
Wilcoxon Test Statistic: 9977
Wilcoxon Test P-value: 0.000521743
Adjusted p-value: 0.001967716
Comparison: Midwest_Southeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 22814
Wilcoxon Test P-value: 0.7752407
Adjusted p-value: 0.8457171
Comparison: Midwest_Northeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 660
Wilcoxon Test P-value: 1.11681e-09
Adjusted p-value: 1.340172e-08
Comparison: Southeast_Northeast_2014_Potassium
Year: 2014
Nutrient: Potassium
Wilcoxon Test Statistic: 1965
Wilcoxon Test P-value: 2.684232e-13
Adjusted p-value: 7.086373e-12
Comparison: Midwest_Southeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 25190
Wilcoxon Test P-value: 0.4709207
Adjusted p-value: 0.5702893
Comparison: Midwest_Northeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 4627
Wilcoxon Test P-value: 0.68439
Adjusted p-value: 0.7655889
Comparison: Southeast_Northeast_2015_Total_N
Year: 2015
Nutrient: Total
Wilcoxon Test Statistic: 10720
Wilcoxon Test P-value: 0.2927494
Adjusted p-value: 0.3903326
Comparison: Midwest_Southeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 13867
Wilcoxon Test P-value: 3.406871e-14
Adjusted p-value: 1.124268e-12
Comparison: Midwest_Northeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 3810
Wilcoxon Test P-value: 5.755428e-05
Adjusted p-value: 0.0002813765
Comparison: Southeast_Northeast_2015_Ammonium.N
Year: 2015
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 7368
Wilcoxon Test P-value: 0.9417615
Adjusted p-value: 0.9562501
Comparison: Midwest_Southeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 20250
Wilcoxon Test P-value: 0.003754155
Adjusted p-value: 0.01126247
Comparison: Midwest_Northeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 6015
Wilcoxon Test P-value: 0.002886071
Adjusted p-value: 0.008859566
Comparison: Southeast_Northeast_2015_Phosphorus
Year: 2015
Nutrient: Phosphorus
Wilcoxon Test Statistic: 17718
Wilcoxon Test P-value: 2.82595e-11
Adjusted p-value: 5.328934e-10
Comparison: Midwest_Southeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 21499
Wilcoxon Test P-value: 0.0445183
Adjusted p-value: 0.09040639
Comparison: Midwest_Northeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 5808
Wilcoxon Test P-value: 0.01335111
Adjusted p-value: 0.03263604
Comparison: Southeast_Northeast_2015_Potassium
Year: 2015
Nutrient: Potassium
Wilcoxon Test Statistic: 15504
Wilcoxon Test P-value: 2.735836e-05
Adjusted p-value: 0.0001397002
Comparison: Midwest_Southeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 41139
Wilcoxon Test P-value: 0.0255574
Adjusted p-value: 0.05622629
Comparison: Midwest_Northeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 1696.5
Wilcoxon Test P-value: 0.1220123
Adjusted p-value: 0.2147416
Comparison: Southeast_Northeast_2016_Total_N
Year: 2016
Nutrient: Total
Wilcoxon Test Statistic: 4290
Wilcoxon Test P-value: 0.01711732
Adjusted p-value: 0.04108156
Comparison: Midwest_Southeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 20333
Wilcoxon Test P-value: 2.144748e-14
Adjusted p-value: 9.43689e-13
Comparison: Midwest_Northeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1375
Wilcoxon Test P-value: 0.2092982
Adjusted p-value: 0.3172911
Comparison: Southeast_Northeast_2016_Ammonium.N
Year: 2016
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2042
Wilcoxon Test P-value: 9.492162e-05
Adjusted p-value: 0.0004474877
Comparison: Midwest_Southeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 32383
Wilcoxon Test P-value: 0.02375285
Adjusted p-value: 0.05405821
Comparison: Midwest_Northeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1558
Wilcoxon Test P-value: 0.03686767
Adjusted p-value: 0.07603958
Comparison: Southeast_Northeast_2016_Phosphorus
Year: 2016
Nutrient: Phosphorus
Wilcoxon Test Statistic: 5074
Wilcoxon Test P-value: 0.2106881
Adjusted p-value: 0.3172911
Comparison: Midwest_Southeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 33093
Wilcoxon Test P-value: 0.05787306
Adjusted p-value: 0.1157461
Comparison: Midwest_Northeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 1539
Wilcoxon Test P-value: 0.03066126
Adjusted p-value: 0.06527881
Comparison: Southeast_Northeast_2016_Potassium
Year: 2016
Nutrient: Potassium
Wilcoxon Test Statistic: 5132
Wilcoxon Test P-value: 0.2428498
Adjusted p-value: 0.3484366
Comparison: Midwest_Southeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 34464
Wilcoxon Test P-value: 0.02424487
Adjusted p-value: 0.05424276
Comparison: Midwest_Northeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 3013.5
Wilcoxon Test P-value: 0.1128031
Adjusted p-value: 0.2039728
Comparison: Southeast_Northeast_2017_Total_N
Year: 2017
Nutrient: Total
Wilcoxon Test Statistic: 4185
Wilcoxon Test P-value: 0.004693128
Adjusted p-value: 0.0131807
Comparison: Midwest_Southeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 20027
Wilcoxon Test P-value: 4.499384e-13
Adjusted p-value: 9.898644e-12
Comparison: Midwest_Northeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 2017
Wilcoxon Test P-value: 0.1353588
Adjusted p-value: 0.2261692
Comparison: Southeast_Northeast_2017_Ammonium.N
Year: 2017
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 1439
Wilcoxon Test P-value: 1.042922e-09
Adjusted p-value: 1.340172e-08
Comparison: Midwest_Southeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 25012
Wilcoxon Test P-value: 0.0003495631
Adjusted p-value: 0.001357127
Comparison: Midwest_Northeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 2192
Wilcoxon Test P-value: 0.0001564536
Adjusted p-value: 0.000688396
Comparison: Southeast_Northeast_2017_Phosphorus
Year: 2017
Nutrient: Phosphorus
Wilcoxon Test Statistic: 4550
Wilcoxon Test P-value: 0.02739236
Adjusted p-value: 0.05927527
Comparison: Midwest_Southeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 25682
Wilcoxon Test P-value: 0.001565332
Adjusted p-value: 0.005298047
Comparison: Midwest_Northeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 1691
Wilcoxon Test P-value: 3.067943e-07
Adjusted p-value: 2.382168e-06
Comparison: Southeast_Northeast_2017_Potassium
Year: 2017
Nutrient: Potassium
Wilcoxon Test Statistic: 3730
Wilcoxon Test P-value: 0.0003156382
Adjusted p-value: 0.001262553
Comparison: Midwest_Southeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 33605
Wilcoxon Test P-value: 0.0006905474
Adjusted p-value: 0.002532007
Comparison: Midwest_Northeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 1136
Wilcoxon Test P-value: 0.07693033
Adjusted p-value: 0.1430254
Comparison: Southeast_Northeast_2018_Total_N
Year: 2018
Nutrient: Total
Wilcoxon Test Statistic: 1636
Wilcoxon Test P-value: 0.3174314
Adjusted p-value: 0.4148608
Comparison: Midwest_Southeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 14440
Wilcoxon Test P-value: 1.969954e-09
Adjusted p-value: 2.16695e-08
Comparison: Midwest_Northeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 631
Wilcoxon Test P-value: 0.2114133
Adjusted p-value: 0.3172911
Comparison: Southeast_Northeast_2018_Ammonium.N
Year: 2018
Nutrient: Ammonium.N
Wilcoxon Test Statistic: 662
Wilcoxon Test P-value: 0.3336877
Adjusted p-value: 0.4318311
Comparison: Midwest_Southeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 23670
Wilcoxon Test P-value: 0.001543212
Adjusted p-value: 0.005298047
Comparison: Midwest_Northeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 941
Wilcoxon Test P-value: 0.5514352
Adjusted p-value: 0.6441544
Comparison: Southeast_Northeast_2018_Phosphorus
Year: 2018
Nutrient: Phosphorus
Wilcoxon Test Statistic: 1782
Wilcoxon Test P-value: 0.1275942
Adjusted p-value: 0.2212087
Comparison: Midwest_Southeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 26248
Wilcoxon Test P-value: 0.1382643
Adjusted p-value: 0.22787
Comparison: Midwest_Northeast_2018_Potassium
Year: 2018
Nutrient: Potassium
Wilcoxon Test Statistic: 1031
Wilcoxon Test P-value: 0.2555021
Adjusted p-value: 0.3587902
Comparison: Southeast_