@@ -100,7 +100,7 @@ function(x, y = NULL, alternative = c("two.sided", "less", "greater"),
100
100
CINT <- .wilcox_test_one_cint_asymp(x , n ,
101
101
alternative ,
102
102
conf.level ,
103
- correct ,
103
+ correct > = 0 ,
104
104
tol.root ,
105
105
digits.rank )
106
106
if (exact && ZERO ) {
@@ -141,7 +141,7 @@ function(x, y = NULL, alternative = c("two.sided", "less", "greater"),
141
141
CINT <- .wilcox_test_two_cint_asymp(x , y , n.x , n.y ,
142
142
alternative ,
143
143
conf.level ,
144
- correct ,
144
+ correct > = 0 ,
145
145
tol.root ,
146
146
digits.rank )
147
147
}
@@ -204,12 +204,14 @@ function(STAT, n, alternative)
204
204
z <- STAT $ z
205
205
switch (alternative ,
206
206
" two.sided" = {
207
+ # # FIXME: Is the conditional distribution really
208
+ # # symmetric about its mean?
207
209
p <- if (q > (n * (n + 1 ) / 4 ))
208
- .psignrank(q - 1 , n , z , lower.tail = FALSE )
210
+ .psignrank(q - 1 / 4 , n , z , lower.tail = FALSE )
209
211
else .psignrank(q , n , z )
210
212
min(2 * p , 1 )
211
213
},
212
- " greater" = .psignrank(q - 1 , n , z , lower.tail = FALSE ),
214
+ " greater" = .psignrank(q - 1 / 4 , n , z , lower.tail = FALSE ),
213
215
" less" = .psignrank(q , n , z ))
214
216
}
215
217
@@ -222,6 +224,7 @@ function(x, n, z, alternative, conf.level)
222
224
alpha <- 1 - conf.level
223
225
diffs <- outer(x , x , `+` )
224
226
diffs <- sort(diffs [! lower.tri(diffs )]) / 2
227
+ # # Of course the 'diffs' are really the Walsh averages.
225
228
w <- if (is.null(z ))
226
229
(n * (n + 1 ) / 2 ) : 1L
227
230
else {
@@ -232,42 +235,46 @@ function(x, n, z, alternative, conf.level)
232
235
CONF.INT <-
233
236
switch (alternative ,
234
237
" two.sided" = {
238
+ # # FIXME: Is the conditional distribution really
239
+ # # symmetric about its mean?
235
240
qu <- .qsignrank(alpha / 2 , n , z )
236
241
ql <- n * (n + 1 ) / 2 - qu
237
242
lci <- if (qu < = min(w )) max(diffs )
238
243
else min(diffs [w < = qu ])
239
244
uci <- if (ql > = max(w )) min(diffs )
240
245
else max(diffs [w > ql ])
241
246
c(uci , lci )
242
- if (qu == 0 ) qu <- 1
243
247
achieved.alpha <-
244
- 2 * .psignrank(trunc( qu ) - 1 , n , z )
248
+ 2 * .psignrank(qu - 1 / 4 , n , z )
245
249
c(uci , lci )
246
250
},
247
251
" greater" = {
252
+ # # FIXME: Is the conditional distribution really
253
+ # # symmetric about its mean?
248
254
qu <- .qsignrank(alpha , n , z )
249
255
ql <- n * (n + 1 ) / 2 - qu
250
256
uci <- if (ql > = max(w )) min(diffs )
251
257
else max(diffs [w > ql ])
252
- if (qu == 0 ) qu <- 1
253
258
achieved.alpha <-
254
- .psignrank(trunc( qu ) - 1 , n , z )
259
+ .psignrank(qu - 1 / 4 , n , z )
255
260
c(uci , + Inf )
256
261
},
257
262
" less" = {
258
263
qu <- .qsignrank(alpha , n , z )
259
264
lci <- if (qu < = min(w )) max(diffs )
260
265
else min(diffs [w < = qu ])
261
- if (qu == 0 ) qu <- 1
262
266
achieved.alpha <-
263
- .psignrank(trunc( qu ) - 1 , n , z )
267
+ .psignrank(qu - 1 / 4 , n , z )
264
268
c(- Inf , lci )
265
269
})
266
270
if (achieved.alpha - alpha > alpha / 2 ){
267
271
warning(" requested conf.level not achievable" )
268
272
conf.level <- 1 - signif(achieved.alpha , 2 )
269
273
}
270
274
attr(CONF.INT , " conf.level" ) <- conf.level
275
+ # # FIXME: This is the Hodges-Lehmann estimate and not what is
276
+ # # suggested in Bauer (1972) (as in \CRANpkg{coin}: is this really
277
+ # # what we want?
271
278
ESTIMATE <- c(" (pseudo)median" = median(diffs ))
272
279
list (conf.int = CONF.INT , estimate = ESTIMATE )
273
280
}
@@ -360,6 +367,8 @@ function(x, n, alternative, conf.level, correct,
360
367
Wmumax <- if (! is.finite(Wmumin )) NA else W(mumax ) # if(): warn only once
361
368
}
362
369
if (n == 0 || ! is.finite(Wmumax )) { # incl. "all zero / ties" warning above
370
+ # # FIXME: in the one-sides cases this gives (-Inf, NaN) and
371
+ # # (NaN, Inf): is this really what we want?
363
372
CONF.INT <-
364
373
structure(c(if (alternative == " less" ) - Inf else NaN ,
365
374
if (alternative == " greater" ) + Inf else NaN ),
@@ -434,6 +443,8 @@ function(x, n, alternative, conf.level, correct,
434
443
})
435
444
attr(CONF.INT , " conf.level" ) <- conf.level
436
445
correct <- FALSE # for W(): no continuity correction for estimate
446
+ # # FIXME: Perhaps instead simply give the Hodges-Lehmann
447
+ # # estimate? In particular as we now use 'correct = FALSE'.
437
448
ESTIMATE <- c(" (pseudo)median" =
438
449
uniroot(W , lower = mumin , upper = mumax ,
439
450
tol = tol.root )$ root )
@@ -474,14 +485,16 @@ function(STAT, n.x, n.y, alternative)
474
485
z <- STAT $ z
475
486
switch (alternative ,
476
487
" two.sided" = {
488
+ # # FIXME: Is the conditional distribution really
489
+ # # symmetric about its mean?
477
490
p <- if (q > (n.x * n.y / 2 ))
478
- .pwilcox(q - 1 , n.x , n.y , z , lower.tail = FALSE )
491
+ .pwilcox(q - 1 / 4 , n.x , n.y , z , lower.tail = FALSE )
479
492
else
480
493
.pwilcox(q , n.x , n.y , z )
481
494
min(2 * p , 1 )
482
495
},
483
496
" greater" = {
484
- .pwilcox(q - 1 , n.x , n.y , z , lower.tail = FALSE )
497
+ .pwilcox(q - 1 / 4 , n.x , n.y , z , lower.tail = FALSE )
485
498
},
486
499
" less" = .pwilcox(q , n.x , n.y , z ))
487
500
}
@@ -504,25 +517,28 @@ function(x, y, n.x, n.y, z, alternative, conf.level)
504
517
CONF.INT <-
505
518
switch (alternative ,
506
519
" two.sided" = {
520
+ # # FIXME: Is the conditional distribution really
521
+ # # symmetric about its mean?
507
522
qu <- .qwilcox(alpha / 2 , n.x , n.y , z )
508
523
ql <- n.x * n.y - qu
509
524
lci <- if (qu < = min(w )) max(diffs )
510
525
else min(diffs [w < = qu ])
511
526
uci <- if (ql > = max(w )) min(diffs )
512
527
else max(diffs [w > ql ])
513
- if (qu == 0 ) qu <- 1
514
528
achieved.alpha <-
515
- 2 * .pwilcox(trunc( qu ) - 1 , n.x , n.y , z )
529
+ 2 * .pwilcox(qu - 1 / 4 , n.x , n.y , z )
516
530
c(uci , lci )
517
531
},
518
532
" greater" = {
533
+ # # FIXME: Is the conditional distribution really
534
+ # # symmetric about its mean?
519
535
qu <- .qwilcox(alpha , n.x , n.y , z )
520
536
ql <- n.x * n.y - qu
521
537
uci <- if (ql > = max(w )) min(diffs )
522
538
else max(diffs [w > ql ])
523
539
if (qu == 0 ) qu <- 1
524
540
achieved.alpha <-
525
- .pwilcox(trunc( qu ) - 1 , n.x , n.y , z )
541
+ .pwilcox(qu - 1 / 4 , n.x , n.y , z )
526
542
c(uci , + Inf )
527
543
},
528
544
" less" = {
@@ -531,14 +547,17 @@ function(x, y, n.x, n.y, z, alternative, conf.level)
531
547
else min(diffs [w < = qu ])
532
548
if (qu == 0 ) qu <- 1
533
549
achieved.alpha <-
534
- .pwilcox(trunc( qu ) - 1 , n.x , n.y , z )
550
+ .pwilcox(qu - 1 / 4 , n.x , n.y , z )
535
551
c(- Inf , lci )
536
552
})
537
553
if (achieved.alpha - alpha > alpha / 2 ) {
538
554
warning(" Requested conf.level not achievable" )
539
555
conf.level <- 1 - achieved.alpha
540
556
}
541
557
attr(CONF.INT , " conf.level" ) <- conf.level
558
+ # # FIXME: This is the Hodges-Lehmann estimate and not what is
559
+ # # suggested in Bauer (1972) (as in \CRANpkg{coin}: is this really
560
+ # # what we want?
542
561
ESTIMATE <- c(" difference in location" = median(diffs ))
543
562
list (conf.int = CONF.INT , estimate = ESTIMATE )
544
563
}
@@ -661,6 +680,8 @@ function(x, y, n.x, n.y, alternative, conf.level, correct,
661
680
})
662
681
attr(CONF.INT , " conf.level" ) <- conf.level
663
682
correct <- FALSE # for W(): no continuity correction for estimate
683
+ # # FIXME: Perhaps instead simply give the Hodges-Lehmann
684
+ # # estimate? In particular as we now use 'correct = FALSE'.
664
685
ESTIMATE <- c(" difference in location" =
665
686
uniroot(W , lower = mumin , upper = mumax ,
666
687
tol = tol.root )$ root )
@@ -721,6 +742,7 @@ function(x, m, n, z = NULL)
721
742
return (dwilcox(x , m , n ))
722
743
723
744
stopifnot(length(z ) == m + n )
745
+ # # FIXME: why floor() and not as.integer()?
724
746
if (! all(2 * z == floor(2 * z )) || any(z < 1 ))
725
747
stop(" 'z' is not a rank vector" )
726
748
@@ -730,8 +752,10 @@ function(x, m, n, z = NULL)
730
752
return (y )
731
753
732
754
# # scores can be x.5: in that case need to multiply by f=2.
755
+ # # FIXME: why floor() and not as.integer()?
733
756
f <- 2 - (max(z - floor(z )) == 0 )
734
757
d <- .Call(C_cpermdist2 ,
758
+ # # FIXME: why not sort(as.integer(f * z)) ?
735
759
as.integer(sort(floor(f * z ))),
736
760
as.integer(m ))
737
761
w <- seq_along(d )
@@ -755,11 +779,14 @@ function(q, m, n, z = NULL, lower.tail = TRUE)
755
779
756
780
# # Support of U
757
781
s <- (0 : (2 * m * n )) / 2
782
+ # # FIXME: can we simplify to 0 : (m * n) if z is all integer?
758
783
# # Density
759
784
d <- .dwilcox(s , m , n , z )
760
785
y [i ] <- vapply(q [i ],
761
- function (e )
762
- sum(d [s < e + sqrt(.Machine $ double.eps )]),
786
+ function (e ) {
787
+ # # FIXME: maybe use a smaller fuzz?
788
+ sum(d [s < e + sqrt(.Machine $ double.eps )])
789
+ },
763
790
0 )
764
791
if (lower.tail ) y else 1 - y
765
792
}
@@ -778,6 +805,7 @@ function(p, m, n, z = NULL, lower.tail = TRUE)
778
805
return (y )
779
806
780
807
s <- (0 : (2 * m * n )) / 2
808
+ # # FIXME: can we simplify to 0 : (m * n) if z is all integer?
781
809
v <- .pwilcox(s , m , n , z )
782
810
if (! lower.tail )
783
811
p <- 1 - p
@@ -794,14 +822,17 @@ function(x, n, z = NULL)
794
822
return (dsignrank(x , n ))
795
823
796
824
stopifnot(length(z ) == n )
825
+ # # FIXME: why floor() and not as.integer()?
797
826
if (! all(2 * z == floor(2 * z )) || any(z < 1 ))
798
827
stop(" 'z' is not a rank vector" )
799
828
y <- rep.int(NA_real_ , length(x ))
800
829
i <- which(! is.na(x ))
801
830
if (! any(i ))
802
831
return (y )
832
+ # # FIXME: why floor() and not as.integer()?
803
833
f <- 2 - (max(z - floor(z )) == 0 )
804
834
d <- .Call(C_cpermdist1 ,
835
+ # # FIXME: why not sort(as.integer(f * z)) ?
805
836
as.integer(sort(floor(f * z ))))
806
837
w <- seq.int(0 , length(d ) - 1L )
807
838
x <- f * x [i ]
@@ -813,8 +844,11 @@ function(x, n, z = NULL)
813
844
.psignrank <-
814
845
function (q , n , z = NULL , lower.tail = TRUE )
815
846
{
816
- if (is.null(z ))
817
- return (psignrank(q , n , lower.tail = lower.tail ))
847
+ if (is.null(z )) {
848
+ # # FIXME: currently
849
+ # # psignrank(2.5, 2) != psignrank(2, 2) ?
850
+ return (psignrank(trunc(q ), n , lower.tail = lower.tail ))
851
+ }
818
852
819
853
y <- rep.int(NA_real_ , length(q ))
820
854
i <- which(! is.na(q ))
@@ -823,11 +857,15 @@ function(q, n, z = NULL, lower.tail = TRUE)
823
857
824
858
# # Support of V
825
859
s <- seq.int(0 , n * (n + 1 )) / 2
860
+ # # FIXME: can we simplify to seq.int(0, n * (n + 1) / 2) is z is all
861
+ # # integer?
826
862
# # Density
827
863
d <- .dsignrank(s , n , z )
828
864
y [i ] <- vapply(q [i ],
829
- function (e )
830
- sum(d [s < e + sqrt(.Machine $ double.eps )]),
865
+ function (e ) {
866
+ # # FIXME: maybe use a smaller fuzz?
867
+ sum(d [s < e + sqrt(.Machine $ double.eps )])
868
+ },
831
869
0 )
832
870
if (lower.tail ) y else 1 - y
833
871
}
@@ -845,6 +883,8 @@ function(p, n, z = NULL, lower.tail = TRUE)
845
883
return (y )
846
884
847
885
s <- seq.int(0 , n * (n + 1 )) / 2
886
+ # # FIXME: can we simplify to seq.int(0, n * (n + 1) / 2) is z is all
887
+ # # integer?
848
888
v <- .psignrank(s , n , z )
849
889
if (! lower.tail )
850
890
p <- 1 - p
0 commit comments