Design-based versions of k-sample rank tests. The built-in tests are all for location hypotheses, but the user could specify others.

svyranktest(formula, design, 
  test = c("wilcoxon", "vanderWaerden", "median","KruskalWallis"), ...)

Arguments

formula

Model formula y~g for outcome variable y and group g

design

A survey design object

test

Which rank test to use: Wilcoxon, van der Waerden's normal-scores test, Mood's test for the median, or a function f(r,N) where r is the rank and N the estimated population size. "KruskalWallis" is a synonym for "wilcoxon" for more than two groups.

...

for future expansion

Details

These tests are for the null hypothesis that the population or superpopulation distributions of the response variable are different between groups, targeted at population or superpopulation alternatives. The 'ranks' are defined as quantiles of the pooled distribution of the variable, so they do not just go from 1 to N; the null hypothesis does not depend on the weights, but the ranks do.

The tests reduce to the usual Normal approximations to the usual rank tests under iid sampling. Unlike the traditional rank tests, they are not exact in small samples.

Value

Object of class htest

Note that with more than two groups the statistic element of the return value holds the numerator degrees of freedom and the parameter element holds the test statistic.

References

Lumley, T., & Scott, A. J. (2013). Two-sample rank tests under complex sampling. BIOMETRIKA, 100 (4), 831-842.

See also

Examples


data(api)
dclus1<-svydesign(id=~dnum, weights=~pw, fpc=~fpc, data=apiclus1)

svyranktest(ell~comp.imp, dclus1)
#> 
#> 	Design-based KruskalWallis test
#> 
#> data:  ell ~ comp.imp
#> t = 2.1367, df = 13, p-value = 0.05221
#> alternative hypothesis: true difference in mean rank score is not equal to 0
#> sample estimates:
#> difference in mean rank score 
#>                     0.1363158 
#> 
svyranktest(ell~comp.imp, dclus1, test="median")
#> 
#> 	Design-based median test
#> 
#> data:  ell ~ comp.imp
#> t = 1.6866, df = 13, p-value = 0.1155
#> alternative hypothesis: true difference in mean rank score is not equal to 0
#> sample estimates:
#> difference in mean rank score 
#>                     0.1914286 
#> 


svyranktest(ell~stype, dclus1)
#> 
#> 	Design-based KruskalWallis test
#> 
#> data:  ell ~ stype
#> df = 2, Chisq = 18.31, p-value = 0.003851
#> 
svyranktest(ell~stype, dclus1, test="median")
#> 
#> 	Design-based median test
#> 
#> data:  ell ~ stype
#> df = 2, Chisq = 15.792, p-value = 0.006481
#> 

str(svyranktest(ell~stype, dclus1))
#> List of 6
#>  $ parameter: num [1, 1] 18.3
#>   ..- attr(*, "names")= chr "Chisq"
#>  $ statistic: Named num 2
#>   ..- attr(*, "names")= chr "df"
#>  $ ddf      : num 12
#>  $ p.value  : num [1, 1] 0.00385
#>  $ method   : chr "Design-based KruskalWallis test"
#>  $ data.name: chr "ell ~ stype"
#>  - attr(*, "class")= chr "htest"

## upper quartile
svyranktest(ell~comp.imp, dclus1, test=function(r,N) as.numeric(r>0.75*N))
#> 
#> 	Design-based rank test
#> 
#> data:  ell ~ comp.imp
#> t = 2.0564, df = 13, p-value = 0.0604
#> alternative hypothesis: true difference in mean rank score is not equal to 0
#> sample estimates:
#> difference in mean rank score 
#>                     0.1732331 
#> 


quantiletest<-function(p){
    rval<-function(r,N) as.numeric(r>(N*p))
    attr(rval,"name")<-paste(p,"quantile")
    rval
  }
svyranktest(ell~comp.imp, dclus1, test=quantiletest(0.5))
#> 
#> 	Design-based 0.5 quantile test
#> 
#> data:  ell ~ comp.imp
#> t = 1.6866, df = 13, p-value = 0.1155
#> alternative hypothesis: true difference in mean rank score is not equal to 0
#> sample estimates:
#> difference in mean rank score 
#>                     0.1914286 
#> 
svyranktest(ell~comp.imp, dclus1, test=quantiletest(0.75))
#> 
#> 	Design-based 0.75 quantile test
#> 
#> data:  ell ~ comp.imp
#> t = 2.0564, df = 13, p-value = 0.0604
#> alternative hypothesis: true difference in mean rank score is not equal to 0
#> sample estimates:
#> difference in mean rank score 
#>                     0.1732331 
#> 

## replicate weights

rclus1<-as.svrepdesign(dclus1)
svyranktest(ell~stype, rclus1)
#> 
#> 	Design-based KruskalWallis test
#> 
#> data:  ell ~ stype
#> df = 2, Chisq = 18.31, p-value = 0.003851
#>