c("coin", "DescTools")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
Two-sided test
set.seed(123)
30
medH0 <- sample(0:100, 20, replace=TRUE)
DV <-
library(DescTools)
SignTest(DV, mu=medH0)
One-sample Sign-Test
data: DV
S = 15, number of differences = 20, p-value = 0.04139
alternative hypothesis: true median is not equal to 30
95.9 percent confidence interval:
33 89
sample estimates:
median of the differences
54
c(99, 131, 118, 112, 128, 136, 120, 107, 134, 122)
IQ <- 110 medH0 <-
wilcox.test(IQ, alternative="greater", mu=medH0, conf.int=TRUE)
Wilcoxon signed rank test
data: IQ
V = 48, p-value = 0.01855
alternative hypothesis: true location is greater than 110
95 percent confidence interval:
113.5 Inf
sample estimates:
(pseudo)median
121
c(20, 30)
Nj <- rnorm(Nj[1], mean= 95, sd=15)
DVa <- rnorm(Nj[2], mean=100, sd=15)
DVb <- data.frame(DV=c(DVa, DVb),
wIndDf <-IV=factor(rep(1:2, Nj), labels=LETTERS[1:2]))
Looks at the number of cases in each group which are below or above the median of the combined data.
library(coin)
median_test(DV ~ IV, distribution="exact", data=wIndDf)
Exact Median Test
data: DV by IV (A, B)
Z = 1.1431, p-value = 0.3868
alternative hypothesis: true mu is not equal to 0
wilcox.test(DV ~ IV, alternative="less", conf.int=TRUE, data=wIndDf)
Wilcoxon rank sum test
data: DV by IV
W = 202, p-value = 0.02647
alternative hypothesis: true location shift is less than 0
95 percent confidence interval:
-Inf -1.770728
sample estimates:
difference in location
-9.761436
library(coin)
wilcox_test(DV ~ IV, alternative="less", conf.int=TRUE,
distribution="exact", data=wIndDf)
Exact Wilcoxon Mann-Whitney Rank Sum Test
data: DV by IV (A, B)
Z = -1.9407, p-value = 0.02647
alternative hypothesis: true mu is less than 0
95 percent confidence interval:
-Inf -1.770728
sample estimates:
difference in location
-9.761436
20
N <- rnorm(N, mean= 95, sd=15)
DVpre <- rnorm(N, mean=100, sd=15)
DVpost <- data.frame(id=factor(rep(1:N, times=2)),
wDepDf <-DV=c(DVpre, DVpost),
IV=factor(rep(0:1, each=N), labels=c("pre", "post")))
Two-sided test
0
medH0 <- aggregate(DV ~ id, FUN=diff, data=wDepDf)
DVdiff <-
library(DescTools)
SignTest(DVdiff$DV, mu=medH0)
One-sample Sign-Test
data: DVdiff$DV
S = 13, number of differences = 20, p-value = 0.2632
alternative hypothesis: true median is not equal to 0
95.9 percent confidence interval:
-1.255058 27.268025
sample estimates:
median of the differences
8.47604
wilcoxsign_test(DV ~ IV | id, alternative="greater",
distribution="exact", data=wDepDf)
Exact Wilcoxon-Signed-Rank Test
data: y by x (neg, pos)
stratified by block
Z = 2.128, p-value = 0.01638
alternative hypothesis: true mu is greater than 0
try(detach(package:DescTools))
try(detach(package:coin))
try(detach(package:survival))
try(detach(package:splines))
R markdown - markdown - R code - all posts