Flag_From_Trend: Flag values as outliers based on error from estimated trend...

View source: R/library--data_prep--filter_tools--sd_trend_outlier.R

Flag_From_TrendR Documentation

Flag values as outliers based on error from estimated trend This function can be done within group if the data fed into it was grouped

Description

Flag values as outliers based on error from estimated trend This function can be done within group if the data fed into it was grouped

Usage

Flag_From_Trend(DF, base_data, trend_data, sd_degree = 2.5)

Arguments

DF

Dataframe containing selected columns

base_data

Name of column containing Raw data

trend_data

Name of generated trend data

sd_degree

Threshold to flag deviant values as an outlier

Value

DF with a new column 'flagged_outlier' that contains if the column is an outlier

Examples

library(dplyr)
data("Example_data", package = "Covid19Wastewater")
smoothing_df <- Example_data%>%
    select(site, date, N1, N2)%>%
    filter(N1 != 0, N2 != 0)%>%
    mutate(N1 = log(N1), N2 = log(N2), N12_avg = (N1 + N2) / 2)
    df_data <- loessSmoothMod(smoothing_df, "N12_avg", "N12_avg_loess", Filter = NULL)
head(df_data%>%
   group_by(site)%>%
   Flag_From_Trend( N12_avg, N12_avg_loess)%>%
   select(site, date, N12_avg, flagged_outlier))

Covid19Wastewater documentation built on Aug. 25, 2023, 1:07 a.m.