Join WQP data with the TADA criteria table - #965
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
for more information, see https://pre-commit.ci
This comment was marked as resolved.
This comment was marked as resolved.
add new test using the example Data_Nutrients_UT data
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…m/USEPA/EPATADA into join-wqp-data-with-criteria-table
for more information, see https://pre-commit.ci
…e in TADA_DefineCriteriaMethodology in test
…iteria include flags for case in which the AUMLRef or AU_UsesRef contain values that are not a match when compared to the criteria table.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
includes the CRITERIATYPE_WATERORG crosswalk for ATTAINS Use Groups to help narrow the list down to better likely matches.
for more information, see https://pre-commit.ci
|
The ATTAINS and CST uses crosswalk function, TADA_GetTADAUsesAliasRef, needs review/edits. Too many rows are being generated with the auto assign method. Currently, for the ATTAINS.UseName there is also a UseGroup that these uses would fall under. The CST has an Aquatic Life or Human Health indicator column. If a CST use is NA for that Aquatic Life or Human Health indicator column or if that ATTAINS.UseName is NA, it will get assigned to all unique CST uses. For example, this means many CST uses are getting matched to "Domestic Source" for UT even though they are not all related to domestic source...
To do:
|
|
I compared the "like match" method currently used in TADA vs Greg's table. Greg's table after filtering only had 156 ATTAINS Uses that matched to CST Uses (filtering out NAs, filtering out any changes in ATTAINS.Uses domain as well as CST uses domain.) From there, the TADA method was able to match 147 out of those 156 matches in Greg's table. The TADA method is looking at % like matches to avoid any manual review needed, and the tolerance is meant to be adjustable. TADA identifies 7,708 close matches out of the 17281 total matches. The remaining 10k matches are based on the Human health/Aquatic Life and Organism & water or water only indicator crosswalk of ATTAINS Use Groups.
|
…re kept this approval list is further filtered down by an entity match. As the entity crosswalk is incomplete, those entities in the CST that could not be matched are not included. This results in 61 matches that are labeled as approved.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
@cristinamullin This PR is ready to review. We can work on additional approval or rejection of rows in a future PR by adding ways to differentiate the methods of the uses alias (percent match method vs A/H and O/W categories crosswalk). The use alias from Greg's table was added as approved and adding on the O/W indicator to the ATTAINS Use Group was added to help reduce the list of potential use alias match to those that are more certain. I added arg inputs to ensure that the csv file does not replace any rows that got approved (reviewing these additional inputs would be nice to test). |
|
So far I have tested your example workflow with some Colorado data using the criteria table from TADACommunityHub. It appears like it all run correctly - I will take a closer look at each of the outputs in the workflow tomorrow or Monday but so far so good as far as a different example from the community hub. |
|
I realized I did not run the final step in your example workflow with the CO data and I am seeing a failure there: To reproduce: #' # create the MLSummaryRef (ML only - no AU or other spatial columns) I also see the same error if I run it with the example UT nutrients data set with UTDWQ as the org id. Would there be some reason that I would not want to run TADA_Analysis_Join_WQP_Critieria a second time on some data sets? Let's chat about this on Monday during our call and I can continue helping troubleshoot after that if you'd like. |
|
#' # join the table by best match, along with the MLSummaryRef The argument input for criteria is meant to only be for the criteria table itself and not the data_with_criteria already combined. CO_data_criteria2 <- TADA_Analysis_Join_WQP_Criteria( |
Thanks for clarifying! Maybe that could be explained in a comment with the example? I'll test again know that I understand what I should be doing there. |
|
The first time I tried with the UT nutrients data (following your instructions to use criteria not the data_with_criteria in TADA_Analysis_Join_WQP_Criteria, no matches were found. I think this is because UT has not entered TADA.ComparableDataIdentifier in their criteria table. When I set byChar = TRUE, matches are found. In a situation where byChar = FALSE, but the criteria table does not contain any TADA.ComparableDataIdentifier values I would suggest either (1) error with message explaining failure or (2) switch to following byChar = TRUE workflow for the rest of the function with a printed message explaining why. Additionally, we may want to discuss how a criteria table with some values and some NAs in the TADA.ComparableDataIdentifier column should be handled. To recreate: load example criteria table from community hubcriteria_UT <- EPATADA::TADA_GetCriteriaFile(org_id = "UTAHDWQ") get usesUT_uses <- TADA_UsesForAnalysis(UT_data, create ML summaryUT_mlsummary <- TADA_MLSummary( join the table by best match, along with the MLSummaryRefwhen byChar = FALSEUT_data_criteria2 <- TADA_Analysis_Join_WQP_Criteria( when byChar = TRUEUT_data_criteria3<- TADA_Analysis_Join_WQP_Criteria( |
|
The function will automatically join the criteria table by the best match of what has been filled out from the criteria table. (If TADA.ComparableDataIdentifier is missing, it will proceed with joining by TADA.Characteristic with any combo of fraction or speciation) I believe the problem arises when using a combination of the criteria table (sourced from the community hub) and the MLSummaryRef table. Ideally the TADA_CommunityHub should be fully compatible, but if a user does not go through the full recommended Mod 3 workflow and jumps straight to filling out the criteria table, these mismatches occurred. For example, TT filled out the communityhub criteria table using the shortcut method. If a user has gone through the full work with creating the MLSummaryRef, they should also create the criteria table sourced from the MLSummaryRef
|
@hillarymarler I took a deeper look. The Criteria table from the CH has a FRESH label for the SaltFresh indicator. The MLSummaryRef does not have any salt indicator, so no matches were found if we were to use the CommunityHub criteria table (as we are joining by those column names below) The case for byChar = T should not have resulted in any matches either. This has been addressed. To handle these mismatches from either
the plan is to handle this with a validation message error (either a function in EPATADA itself or in the TADACommunityHub package)
|
Have you added the validation message error yet? I re ran the UT example and got the same result (criteria not matched due to SaltFresh indicator) and did not see any message about it. Would it make sense to give users the option to exclude SaltFresh as a joining column? For example, w/ the UT criteria table all the rows are "Fresh". So I can imagine a scenario where a user goes through mod 2, skips the SaltFresh step (because they know their criteria are only for freshwater) and is then surprised when no criteria are joined because the criteria table does have the SaltFresh column filled. |
|
The validation messages will be done as a separate PR (still trying to decide if that is best for a TADACommunityHub validation function or as part of the EPATADA package). We can allow users to skip the SaltFresh Indicator step if it is not relevant, and therefore exclude it as a column in the final MLSummaryRef output. So in the scenario when the function tries to join the MLSummaryRef and criteria table, it will get joined by all columns except the SaltFresh Indicator. Users will still get a warning message (will be done as a future PR) about a mismatch if a user has filled out the criteria table with a saltfresh indicator but it was not included in the MLSummaryRef. Would that make sense as an approach @hillarymarler? |
That approach makes sense to me and I think will be useful for states without any saltwater criteria. Other than adding some additional helpful messages (future PR), this all seems to be working well for the examples I've tested. I am still wondering what would happen in a situation where a user fills out some, but not all TADA.ComparableDataIdentifier values in a criteria table. Would this be caught by a validation test? Would users be prompted to join by TADA.CharacteristicName? Or a message indicating which criteria could not be joined due to no value for TADA.ComparableDataIdentifier? |
|
The function will automatically split the criteria table into 5 categories and joins it to the WQP data based on what has been filled out. All rows will get binded at the end. So users are allowed to fill some rows out by the TADA.ComparableDataIdentifier and some rows with just the characteristic name (or by its fraction and/or speciation) and the function will join it based on its best match.
If an invalid char, fraction and/or speciation is provided, a warning message will be returned (does not currently do so but will create a function to return this warning message) |





This is the first PR step for joining the criteria table to the WQP data for analysis. This new function will automatically join the WQP data frame with the TADA compatible criteria table dependent on what has been filled out in the criteria table.
Join WQP results to a criteria table by the best available key:
Users can make the criteria table join only by the TADA.CharacteristicName regardless of what has been filled out in the criteria table.
For testing, please look at the example tests and test out example WQP data retrievals with criteria table filled out. You can use the autoassign method in TADA_DefineCriteriaMethodology() if desired for testing or use a criteria table from the TADACommunityHub.
Ex.