The one-sample sign test compares the number of observations greater than or less than the default value without accounting for the magnitude of the difference between each observation and the default value. The test is similar in purpose to the one-sample Wilcoxon signed-rank test, but looks specifically at the median value, and is not affected by the distribution of the data.
The sign test is conducted with functions in the DescTools package, the nonpar package, or the BSDA package. These functions produce a p-value for the hypothesis, as well as the median and confidence interval of the median for the data.
The trinomial test is used in similar situations, but the test takes into account the zero-difference observations. That is, in the one-sample case, observations that are equal to zero, or to the default value, as the case may be. This can be important when there are many zero-difference observations.
At the time of writing, the only R implementation of the trinomial test I know of is in a GitHub repository by Douglas Whitaker.
Appropriate data
• One-sample data
• Data are ordinal, interval, or ratio
Hypotheses
• Null hypothesis: The median of the population from which the sample was drawn is equal to the default value.
• Alternative hypothesis (two-sided): The median of the population from which the sample was drawn is not equal to the default value.
Interpretation
Reporting significant results as e.g. “Likert scores were significantly different from a default value of 3” is acceptable. As is e.g. “Median Likert scores were significantly different from a default value of 3”
Packages used in this chapter
The packages used in this chapter include:
• BSDA
• DescTools
• rcompanion
• nonpar
The following commands will install these packages if they are not already installed:
if(!require(BSDA)){install.packages("BSDA")}
if(!require(DescTools)){install.packages("DescTools")}
if(!require(rcompanion)){install.packages("rcompanion")}
if(!require(nonpar)){install.packages("nonpar")}
One-sample sign test example
For appropriate plots and summary statistics, see the One-sample Wilcoxon Signed-rank Test chapter.
Data = read.table(header=TRUE, stringsAsFactors=TRUE, text="
Speaker Rater Likert
'Maggie Simpson' 1 3
'Maggie Simpson' 2 4
'Maggie Simpson' 3 5
'Maggie Simpson' 4 4
'Maggie Simpson' 5 4
'Maggie Simpson' 6 4
'Maggie Simpson' 7 4
'Maggie Simpson' 8 3
'Maggie Simpson' 9 2
'Maggie Simpson' 10 5
")
### Check the data frame
library(psych)
headTail(Data)
str(Data)
summary(Data)
Sign test with the DescTools package
Note that Data$Likert is the one-sample data, and mu=3 indicates the default value to compare to.
library(DescTools)
SignTest(Data$Likert,
mu = 3)
One-sample Sign-Test
S = 7, number of differences = 8, p-value = 0.07031
### Note the p-value in the output above
alternative hypothesis: true median is not equal to 3
97.9 percent confidence interval:
3 5
sample estimates:
median of the differences
4
### Median value and confidence interval
Sign test with the nonpar package
Note that Data$Likert is the one-sample data, and m=3 indicates the default value to compare to. At the time of writing, it appears that the exact=FALSE option actually produces the exact test.
library(nonpar)
signtest(Data$Likert, m=3, conf.level=0.95, exact=FALSE)
Exact Sign Test
The p-value is 0.07032
The 95 % confidence interval is [ 2 , 4 ].
Sign test with the BSDA package
Note that Data$Likert is the one-sample data, and md=3 indicates the default value to compare to.
library(BSDA)
SIGN.test(Data$Likert,
md = 3)
One-sample Sign-Test
s = 7, p-value = 0.07031
alternative hypothesis: true median is not equal to 3
### Note the p-value in the output above
95 percent confidence interval:
3.000000 4.675556
sample estimates:
median of x
4
### Median value and confidence interval
Effect size statistics
One way to assess the effect size after a one-sample sign test is to use a dominance statistic. This statistic simply looks at the proportion of observations greater than the default median value minus the proportion of observations less than the default median value. A value of 1 would indicate that all observations are greater than the default median, and a value of –1 would indicate that all observations are less than the default median. A value of 0 indicates that the number of observations greater than the default median are equal to the number that are less than the default median.
A VDA-like statistic can be calculated as Dominance / 2 + 0.5. This statistic varies from 0 to 1, with 0.5 being equivalent to a dominance value of 0.
Note that neither of these statistics take into account values tied to the default median value.
library(rcompanion)
oneSampleDominance(Data$Likert, mu=3)
n Median mu Less Equal Greater Dominance VDA
1 10 4 3 0.1 0.2 0.7 0.6 0.8
oneSampleDominance(Data$Likert, mu=3, ci=TRUE)
n Median mu Less Equal
Greater Dominance lower.ci upper.ci VDA lower.vda.ci upper.vda.ci
1 10 4 3 0.1 0.2 0.7 0.6 0.2 0.9 0.8
0.6 0.95
Manual calculations
Likert = c(3, 4, 5, 4, 4, 4, 4, 3, 2, 5)
Greater = sum(Likert > 3)
NotMedian = sum(Likert != 3)
binom.test(Greater, NotMedian)
Exact binomial test
number of successes = 7, number of trials = 8, p-value = 0.07031
MU = 3
N = length(Likert)
GreaterProp = sum(Likert > MU) / N
GreaterProp
0.7
LesserProp = sum(Likert < MU) / N
LesserProp
0.1
EqualProp = sum(Likert == MU) / N
EqualProp
0.2
Trinomial test for one-sample data
We’ll use the same Maggie Simpson data as above. Note that the trinomial test result here returns a p-value below 0.05, which the sign test did not.
It appears that in the one-sample case, it's necessary to include the default value—3 here—for the algorithm to return the correct result.
if(!require(remotes)){install.packages("remotes")}
library(remotes)
remotes::install_github("douglaswhitaker/GridItemTools")
Data = read.table(header=TRUE, stringsAsFactors=TRUE, text="
Speaker Rater Likert
'Maggie Simpson' 1 3
'Maggie Simpson' 2 4
'Maggie Simpson' 3 5
'Maggie Simpson' 4 4
'Maggie Simpson' 5 4
'Maggie Simpson' 6 4
'Maggie Simpson' 7 4
'Maggie Simpson' 8 3
'Maggie Simpson' 9 2
'Maggie Simpson' 10 5
")
str(Data)
summary(Data)
library(GridItemTools)
trinomial_test(Data$Likert, 3)
Trinomial Test (Ganesalingam, 1994; Bian et al., 2011)
statistic: 6
p-value: 0.0493617152
References
Trinomial test
Bian, G., M. McAleer, W.-K. Wong. 2011. A trinomial test for paired data when there are many ties. Mathematics and Computers in Simulation 81:6, 1153–1160.
Whitaker, D. 2022. GridItemTools: Grid Item Tools. rdrr.io/github/douglaswhitaker/GridItemTools/.