-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapply_thr.Rd
136 lines (121 loc) · 5.62 KB
/
apply_thr.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Quality_checking.R
\name{apply_thr}
\alias{apply_thr}
\title{Apply Thresholds}
\usage{
apply_thr(
x,
thr,
name_out = "-",
flag = c("higher", "outside", "between", "lower"),
angles = FALSE
)
}
\arguments{
\item{x}{A numeric atomic type with \code{NULL} \code{\link{dim}}ensions.}
\item{thr}{A numeric vector of length two or list with two numeric vectors of
length two. If vector, first (second) element provides lower (upper)
boundary threshold for quality control flag 2. If list, first (second)
element provides lower (upper) boundary threshold for quality control flag
1 and 2. This is reversed for \code{flag = "lower"}. See examples.}
\item{name_out}{A character string providing \code{varnames} attribute value
of the output.}
\item{flag}{A character string. Selects one of the available flagging
approaches. Can be abbreviated. See 'Details'.}
\item{angles}{A logical value. Choose if \code{x} represents angles.}
}
\value{
An integer vector with the same length as \code{x}. Its
\code{varnames} and \code{units} attributes are set to \code{name_out} and
\code{"-"} values, respectively.
}
\description{
Values of \code{x} are checked against the specified thresholds to obtain
their quality control (QC) flags.
}
\details{
This function is called by \code{\link{extract_QC}} but can be useful on its
own when filtering values of variable according to the 0 - 2 QC flag scheme.
Obtained QC flags are assigned in the range 0 - 2 according to these rules:
For \code{flag = "higher"} \itemize{ \item If \code{x <= thr[1]}, QC flag =
0. \item If \code{x > thr[1] & x <= thr[2]}, QC flag = 1. \item If \code{x >
thr[2]}, QC flag = 2.}
For \code{flag = "outside"} (\code{thr} supplied as vector) \itemize{ \item
If \code{x >= thr[1] & x <= thr[2]}, QC flag = 0. \item If \code{x < thr[1] |
x > thr[2]}, QC flag = 2.}
For \code{flag = "outside"} (\code{thr} supplied as list) \itemize{ \item If
\code{x >= thr[[1]][2] & x <= thr[[2]][1]}, QC flag = 0. \item If \code{x <
thr[[1]][2] | x > thr[[2]][1]}, QC flag = 1. \item If \code{x < thr[[1]][1] |
x > thr[[2]][2]}, QC flag = 2.}
For \code{flag = "between"} (\code{thr} supplied as vector) \itemize{ \item
If \code{x <= thr[1] | x >= thr[2]}, QC flag = 0. \item If \code{x > thr[1] &
x < thr[2]}, QC flag = 2. }
For \code{flag = "between"} (\code{thr} supplied as list) \itemize{ \item If
\code{x <= thr[[1]][1] | x >= thr[[2]][2]}, QC flag = 0. \item If \code{x >
thr[[1]][1] & x < thr[[2]][2]}, QC flag = 1. \item If \code{x > thr[[1]][2] &
x < thr[[2]][1]}, QC flag = 2.}
For \code{flag = "lower"} \itemize{ \item If \code{x >= thr[1]}, QC flag = 0.
\item If \code{x < thr[1] & x >= thr[2]}, QC flag = 1. \item If \code{x <
thr[2]}, QC flag = 2.}
In case of \code{angles = TRUE}, conditions are appropriately implemented on
the circular scale. Angles are expected to be within the range [0, 360)
degrees and corrected otherwise. Notice that using \code{flag = "higher"} or
\code{flag = "lower"} might not be very useful on the circular scale.
}
\examples{
# flag defaults to "higher"
apply_thr(1:10, c(3, 6), "example")
# comparison of flag types
xx <- data.frame(var = 1:10)
xx$higher <- apply_thr(xx$var, c(3, 6), "higher", flag = "higher")
xx$outside_c <- apply_thr(xx$var, c(4, 6), "outside_c", flag = "outside")
xx$outside_l <- apply_thr(xx$var, list(c(2, 4), c(6, 8)), "outside_l",
flag = "outside")
xx$between_c <- apply_thr(xx$var, c(4, 6), "between_c", flag = "between")
xx$between_l <- apply_thr(xx$var, list(c(2, 4), c(6, 8)), "between_l",
flag = "between")
xx$lower <- apply_thr(xx$var, c(6, 3), "lower", flag = "lower")
xx
str(xx)
# flagging for angles
# - 'higher' and 'lower' flags are problematic on a circular scale
yy <- data.frame(var = 170:180)
# expected results because thresholds are not crossing zero (360 deg)
yy$higher <- apply_thr(yy$var, c(172, 176), "higher", flag = "higher",
angle = TRUE)
yy$outside_c <- apply_thr(yy$var, c(174, 176), "outside_c", flag = "outside",
angle = TRUE)
yy$outside_l <- apply_thr(yy$var, list(c(172, 174), c(176, 178)), "outside_l",
flag = "outside", angle = TRUE)
yy$between_c <- apply_thr(yy$var, c(174, 176), "between_c", flag = "between",
angle = TRUE)
yy$between_l <- apply_thr(yy$var, list(c(172, 174), c(176, 178)), "between_l",
flag = "between", angle = TRUE)
# expected results because thresholds are not crossing zero (360 deg)
yy$lower <- apply_thr(yy$var, c(176, 172), "lower", flag = "lower",
angle = TRUE)
yy
str(yy)
# flagging for angles with thresholds crossing zero (360 deg)
zz <- data.frame(var = c(355:359, 0:5))
# thresholds crossing zero (360 deg) - not useful (but valid) results
zz$higher <- apply_thr(zz$var, c(357, 1), "higher", flag = "higher",
angle = TRUE)
zz$outside_c <- apply_thr(zz$var, c(359, 1), "outside_c", flag = "outside",
angle = TRUE)
zz$outside_l <- apply_thr(zz$var, list(c(357, 359), c(1, 3)), "outside_l",
flag = "outside", angle = TRUE)
zz$between_c <- apply_thr(zz$var, c(359, 1), "between_c", flag = "between",
angle = TRUE)
zz$between_l <- apply_thr(zz$var, list(c(357, 359), c(1, 3)), "between_l",
flag = "between", angle = TRUE)
# thresholds crossing zero (360 deg) - not useful (but valid) results
zz$lower <- apply_thr(zz$var, c(1, 357), "lower", flag = "lower",
angle = TRUE)
zz
str(zz)
}
\seealso{
\code{\link{extract_QC}}.
}