This function analyzes weight data to identify outliers using the Interquartile Range (IQR) method, and computes time-based metrics for data entries within a specified number of days from a reference date. It also reshapes the results into a wide format, separating the percentage of weight outliers and other metrics like count of observations and total duration by location and date.
extreme_time_n(data, days, ref_date = Sys.Date())
data.table, required.
The input data table which must contain the following columns: visit_time
(POSIXct), location
(character),
responder
(character), weight
(numeric, in grams), and duration
(numeric, in seconds).
integer, required. The number of days before the reference date to include in the analysis.
Date, optional. The specific date to use as the reference for filtering data; defaults to the current system date.
A list of two data.tables:
weight_outlier
: A data table in wide format showing the percentage of weight outliers
per location across the specified dates.
feedintake
: A data table in wide format showing the count of observations and total
duration in hours per location across the specified dates.
The function assumes that the input data has all the required columns. The 'visit_time' should be in POSIXct format to correctly convert to dates. Make sure the data is pre-cleaned to avoid errors due to missing values, especially in the 'location' and 'responder' columns.
# Load CSV data
data <- data.table::fread("C:/Users/Dell/Documents/projects/pptsdm_data/ppt_monitor_test_data.csv")
print(extreme_time_n(data = data, days = 5))
#> $weight_outlier
#> Key: <location>
#> location 06-03 06-04 06-05 06-06 06-07
#> <int> <num> <num> <num> <num> <num>
#> 1: 501 7.07 4.31 4.12 2.78 5.79
#> 2: 502 5.38 6.86 3.12 6.67 7.32
#> 3: 503 4.82 5.32 6.17 5.19 5.21
#> 4: 504 5.95 3.70 2.41 5.41 3.53
#> 5: 505 1.28 3.37 5.05 4.67 11.30
#> 6: 506 7.69 7.46 4.35 1.28 7.50
#> 7: 507 7.59 3.85 4.29 2.41 8.43
#> 8: 508 1.47 1.37 2.63 1.32 6.10
#> 9: 509 6.84 4.62 4.31 6.78 8.13
#> 10: 510 6.74 3.12 7.58 4.41 8.57
#>
#> $feedintake
#> Key: <location>
#> location n_06-03 n_06-04 n_06-05 n_06-06 n_06-07 time_06-03 time_06-04
#> <int> <int> <int> <int> <int> <int> <num> <num>
#> 1: 501 99 116 97 108 121 17.62 18.14
#> 2: 502 93 102 96 75 82 17.24 16.38
#> 3: 503 83 94 81 77 96 18.15 16.92
#> 4: 504 84 81 83 74 85 18.61 17.66
#> 5: 505 78 89 99 107 115 16.82 17.51
#> 6: 506 65 67 69 78 80 18.65 17.29
#> 7: 507 79 78 70 83 83 17.45 15.67
#> 8: 508 68 73 76 76 82 18.12 17.93
#> 9: 509 117 130 116 118 123 17.97 16.86
#> 10: 510 89 96 66 68 70 19.07 19.84
#> time_06-05 time_06-06 time_06-07
#> <num> <num> <num>
#> 1: 18.64 18.62 18.54
#> 2: 16.92 16.48 16.30
#> 3: 15.49 15.84 15.86
#> 4: 16.87 17.10 16.49
#> 5: 16.73 17.26 16.33
#> 6: 17.48 19.43 18.44
#> 7: 15.85 15.88 16.28
#> 8: 17.49 18.09 17.18
#> 9: 17.39 17.98 16.58
#> 10: 17.89 18.17 17.72
#>