Stanford University, Spring 2016, STATS 205
\(t\)-distribution with 5 degrees of freedom and
a true shift parameter \(\Delta\) was set at the value \(8\)
n1 = 11 n2 = 9 delta = 8 x = round(rt(n1,5)*10+42,1) y = round(rt(n2,5)*10+42+delta,1) sort(x)
## [1] 20.0 27.5 29.7 36.5 41.7 42.1 45.5 46.6 47.9 49.0 50.6
sort(y)
## [1] 25.7 32.4 37.6 38.0 39.4 52.6 55.0 59.7 80.4
Estimate of shift parameter \(\Delta\) and confidence intervals:
wilcox.test(y,x,conf.int=TRUE)
## ## Wilcoxon rank sum test ## ## data: y and x ## W = 60, p-value = 0.4561 ## alternative hypothesis: true location shift is not equal to 0 ## 95 percent confidence interval: ## -9 18 ## sample estimates: ## difference in location ## 6
Contaminated normal \((0 < \epsilon < 0.5, \sigma_c > 1)\): \[F(x) = (1 − \epsilon) \Phi(x) + \epsilon \Phi(x/\sigma_c)\]
n = 10000 sigmaC = 3 epsilon = 0.25 sample = c(rnorm((1-epsilon)*n,0,1),rnorm(epsilon*n,0,sigmaC))
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] ## epsilon 0.000 0.010 0.02 0.030 0.050 0.100 0.150 0.250 ## ARE(Hodges–Lehmann,LS) 0.955 1.009 1.06 1.108 1.196 1.373 1.497 1.616
Monte Carlo simulation of distibution of \(U\) under the null
n1 = length(hg); n2 = length(lg); n = n1+n2; nSim = 10000 Shuffle = replicate(nSim,sample(n,n,replace = FALSE)) Xi = Shuffle[1:n1,] Yj = Shuffle[(n1+1):n,] U = function(Xi,Yj) { Pi = function(i) { sum(Yj < Xi[i]) }; Qj = function(j) { sum(Xi < Yj[j]) } P = sapply(1:n1,Pi); Q = sapply(1:n2,Qj) Phat = mean(P); Qhat = mean(Q) V1 = sum((P-Phat)^2); V2 = sum((Q-Qhat)^2) (sum(Q)-sum(P))/(2*sqrt(V1+V2+Phat*Qhat)) } UNull = rep(0,nSim) for(trial in 1:nSim) { UNull[trial] = U(Xi[,trial],Yj[,trial]) }
Test statistic of our sample
ranks = rank(c(hg,lg)) XiObsv = ranks[1:n1] YjObsv = ranks[(n1+1):n] UObsv = U(XiObsv,YjObsv) UObsv
## [1] 1.467599
pvalue = mean(UNull >= UObsv) pvalue
## [1] 0.0814
From Monte Carlo simulation: