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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
R version 4.2.1 (2022-06-23 ucrt) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(classInt)
> set.seed(1)
> data_censored<-c(rep(0,10), rnorm(100, mean=20,sd=1),rep(26,10))
> cl2<-classIntervals(data_censored, n=4, style="fixed",dataPrecision=2,fixedBreaks=c(-1,1,19,25,30))
>
> print(cl2, unique=FALSE)
style: fixed
one of 166,650 possible partitions of this variable into 4 classes
[-1,1) [1,19) [19,25) [25,30]
10 11 89 10
> print(cl2, unique=TRUE)
style: fixed
one of 166,650 possible partitions of this variable into 4 classes
Class found with one single (possibly repeated) value: changed label
0 [1,19) [19,25) 26
10 11 89 10
>
> ### example from man page
> classIntervals(data_censored, n=5, style="fixed", fixedBreaks=c(15.57, 25, 50, 75, 100, 155.30))
style: fixed
one of 4,082,925 possible partitions of this variable into 5 classes
[15.57,25) [25,50) [50,75) [75,100) [100,155.3]
110 10 0 0 0
Warning message:
In classIntervals(data_censored, n = 5, style = "fixed", fixedBreaks = c(15.57, :
variable range greater than fixedBreaks
>
> print(classIntervals(data_censored, n=5, style="sd"), unique=FALSE)
style: sd
one of 79,208,745 possible partitions of this variable into 6 classes
[-5.126688,0.8860022) [0.8860022,6.898692) [6.898692,12.91138)
10 0 0
[12.91138,18.92407) [18.92407,24.93676) [24.93676,30.94945]
10 90 10
> print(classIntervals(data_censored, n=5, style="sd"), unique=TRUE)
style: sd
one of 79,208,745 possible partitions of this variable into 6 classes
Class found with one single (possibly repeated) value: changed label
0 [0.8860022,6.898692) [6.898692,12.91138)
10 0 0
[12.91138,18.92407) [18.92407,24.93676) 26
10 90 10
> print(classIntervals(data_censored, n=5, style="equal"), unique=TRUE)
style: equal
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [5.2,10.4) [10.4,15.6) [15.6,20.8) [20.8,26]
10 0 0 81 29
> print(classIntervals(data_censored, n=5, style="quantile"), unique=TRUE)
style: quantile
one of 4,082,925 possible partitions of this variable into 5 classes
[0,19.24129) [19.24129,19.87857) [19.87857,20.39315) [20.39315,21.07048)
24 24 24 24
[21.07048,26]
24
> set.seed(1)
> print(classIntervals(data_censored, n=5, style="kmeans"), unique=TRUE)
style: kmeans
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.11514) [19.11514,20.31048) [20.31048,24.20081)
10 12 43 45
26
10
> print(classIntervals(data_censored, n=5, style="hclust", method="complete"), unique=TRUE)
style: hclust
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.01088) [19.01088,21.00347) [21.00347,24.20081)
10 11 74 15
26
10
> print(classIntervals(data_censored, n=5, style="hclust", method="single"), unique=TRUE)
style: hclust
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,18.33574) [18.33574,21.78784) [21.78784,24.20081)
10 3 94 3
26
10
> print(classIntervals(data_censored, n=5, style="fisher"), unique=TRUE)
style: fisher
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.72123) [19.72123,20.85116) [20.85116,24.20081)
10 33 49 18
26
10
> print(classIntervals(data_censored, n=5, style="jenks"), unique=TRUE)
style: jenks
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 (0,19.69582] (19.69582,20.82122] (20.82122,22.40162]
10 33 49 18
26
10
>
> print(classIntervals(data_censored, n=5, style="fixed", fixedBreaks=c(15.57, 25, 50, 75, 100, 155.30)), unique=TRUE)
style: fixed
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
[15.57,25) 26 [50,75) [75,100) [100,155.3]
110 10 0 0 0
Warning message:
In classIntervals(data_censored, n = 5, style = "fixed", fixedBreaks = c(15.57, :
variable range greater than fixedBreaks
> print(classIntervals(data_censored, n=5, style="sd"), unique=TRUE)
style: sd
one of 79,208,745 possible partitions of this variable into 6 classes
Class found with one single (possibly repeated) value: changed label
0 [0.8860022,6.898692) [6.898692,12.91138)
10 0 0
[12.91138,18.92407) [18.92407,24.93676) 26
10 90 10
> print(classIntervals(data_censored, n=5, style="equal"), unique=TRUE)
style: equal
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [5.2,10.4) [10.4,15.6) [15.6,20.8) [20.8,26]
10 0 0 81 29
> print(classIntervals(data_censored, n=5, style="quantile"), unique=TRUE)
style: quantile
one of 4,082,925 possible partitions of this variable into 5 classes
[0,19.24129) [19.24129,19.87857) [19.87857,20.39315) [20.39315,21.07048)
24 24 24 24
[21.07048,26]
24
> set.seed(1)
> print(classIntervals(data_censored, n=5, style="kmeans"), unique=TRUE)
style: kmeans
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.11514) [19.11514,20.31048) [20.31048,24.20081)
10 12 43 45
26
10
> set.seed(1)
> print(classIntervals(data_censored, n=5, style="kmeans", intervalClosure="right"), unique=TRUE)
style: kmeans
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 (8.89265,19.11514] (19.11514,20.31048] (20.31048,24.20081]
10 12 43 45
26
10
> set.seed(1)
> print(classIntervals(data_censored, n=5, style="kmeans", dataPrecision=0), unique=TRUE)
style: kmeans
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [9,20) [20,21) [21,25) 26
10 12 43 45 10
> set.seed(1)
> print(classIntervals(data_censored, n=5, style="kmeans"), cutlabels=FALSE, unique=TRUE)
style: kmeans
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 8.89265 - 19.11514 19.11514 - 20.31048 20.31048 - 24.20081
10 12 43 45
26
10
> print(classIntervals(data_censored, n=5, style="hclust", method="complete"), unique=TRUE)
style: hclust
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.01088) [19.01088,21.00347) [21.00347,24.20081)
10 11 74 15
26
10
> print(classIntervals(data_censored, n=5, style="hclust", method="single"), unique=TRUE)
style: hclust
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,18.33574) [18.33574,21.78784) [21.78784,24.20081)
10 3 94 3
26
10
> print(classIntervals(data_censored, n=5, style="fisher"), unique=TRUE)
style: fisher
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.72123) [19.72123,20.85116) [20.85116,24.20081)
10 33 49 18
26
10
> print(classIntervals(data_censored, n=5, style="jenks"), unique=TRUE)
style: jenks
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 (0,19.69582] (19.69582,20.82122] (20.82122,22.40162]
10 33 49 18
26
10
> print(classIntervals(data_censored, style="headtails"), unique=TRUE)
style: headtails
one of 101 possible partitions of this variable into 2 classes
[0,18.92407) [18.92407,26]
20 100
> print(classIntervals(data_censored, style="headtails", thr = 1))
style: headtails
one of 166,650 possible partitions of this variable into 4 classes
[0,18.92407) [18.92407,20.86153) [20.86153,23.03872) [23.03872,26]
20 72 18 10
> print(classIntervals(data_censored, style="headtails", thr = 0))
style: headtails
one of 101 possible partitions of this variable into 2 classes
[0,18.92407) [18.92407,26]
20 100
> print(classIntervals(data_censored, style="box", iqr_mult = 0))
style: box
one of 79,208,745 possible partitions of this variable into 6 classes
[0,19.38567) [19.38567,19.38567) [19.38567,20.11391) [20.11391,20.77193)
30 0 30 30
[20.77193,20.77193) [20.77193,26]
0 30
> print(classIntervals(data_censored, style="box"))
style: box
one of 79,208,745 possible partitions of this variable into 6 classes
[0,17.30627) [17.30627,19.38567) [19.38567,20.11391) [20.11391,20.77193)
10 20 30 30
[20.77193,22.85133) [22.85133,26]
20 10
> x <- c(0, 0, 0, 1, 2, 50)
> print(classIntervals(x, n=3, style="fisher"), unique=TRUE)
style: fisher
one of 3 possible partitions of this variable into 3 classes
Class found with one single (possibly repeated) value: changed label
0 [0.5,26) 50
3 2 1
> print(classIntervals(x, n=3, style="jenks"), unique=TRUE)
style: jenks
one of 3 possible partitions of this variable into 3 classes
Class found with one single (possibly repeated) value: changed label
0 (0,2] 50
3 2 1
> if (getRversion() > "3.5.3") {
+ suppressWarnings(set.seed(1, sample.kind=c("Rounding")))
+ } else {
+ set.seed(1)
+ }
> print(classIntervals(data_censored, n=5, style="bclust", verbose=FALSE), unique=TRUE)
style: bclust
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.01088) [19.01088,21.00347) [21.00347,24.20081)
10 11 74 15
26
10
> print(classIntervals(data_censored, n=5, style="bclust", hclust.method="complete", verbose=FALSE), unique=TRUE)
style: bclust
one of 4,082,925 possible partitions of this variable into 5 classes
Class found with one single (possibly repeated) value: changed label
0 [8.89265,19.79106) [19.79106,21.28327) [21.28327,24.20081)
10 34 57 9
26
10
>
> # the log-likelihood returns a valid logLik object.
> stopifnot(
+ identical(
+ round(logLik(classIntervals(rep(1:3, each=10), n=2, style="jenks")), 5),
+ structure(-14.52876, df = 2, nobs = 30L, class = "logLik")
+ )
+ )
> # logLik for exact intervals (a single value is the unique member of an
> # interval) yields a likelihood of zero.
> stopifnot(
+ identical(
+ suppressWarnings(logLik(classIntervals(rep(1:3, each=10), n=3, style="jenks"))),
+ structure(0, df = 3, nobs = 30L, class = "logLik")
+ )
+ )
>
> proc.time()
user system elapsed
0.37 0.06 0.68
|