[banner]

Summary and Analysis of Extension Program Evaluation in R

Salvatore S. Mangiafico

Sign Test for Two-sample Paired Data

The sign test for two-sample paired data can be used for a similar purpose as the paired rank-sum test in cases where the distribution of the differences is not symmetrical. 

 

The SIGN.test function in the BSDA package requires the data to be separated into two variables, each of which is ordered so that the first observation of each are paired, and so on.  Information on options for the function can be viewed with ?SIGN.test.  The SignTest function in the DescTools package is similar.

 

For appropriate plots see the Two-sample Paired Rank-sum Test chapter.

 

Appropriate data

•  Two-sample paired data.  That is, one-way data with two groups only, where the observations are paired between groups.

•  Dependent variable is ordinal, interval, or ratio

•  Independent variable is a factor with two levels.  That is, two groups

 

Hypotheses

•  Null hypothesis:  The median of the differences between pairs in group A and group B is zero.

•  Alternative hypothesis (two-sided): The median of the differences between pairs in group A and group B is not zero.

 

Interpretation

Significant results can be reported as “There was a significant difference in values between group A and group B.”

 

Packages used in this chapter

 

The packages used in this chapter include:

•  psych

•  BSDA

•  DescTools

 

The following commands will install these packages if they are not already installed:


if(!require(psych)){install.packages("psych")}
if(!require(BSDA)){install.packages("BSDA")}
if(!require(DescTools)){install.packages("DescTools")}


Sign test for paired two-sample data example


Input =("
 Speaker  Time  Student  Likert
 Pooh      1     a        1      
 Pooh      1     b        4      
 Pooh      1     c        3       
 Pooh      1     d        3      
 Pooh      1     e        3      
 Pooh      1     f        3      
 Pooh      1     g        4      
 Pooh      1     h        3       
 Pooh      1     i        3      
 Pooh      1     j        3      
 Pooh      2     a        4
 Pooh      2     b        5
 Pooh      2     c        4
 Pooh      2     d        5
 Pooh      2     e        4
 Pooh      2     f        5
 Pooh      2     g        3
 Pooh      2     h        4
 Pooh      2     i        3
 Pooh      2     j        4     
")

Data = read.table(textConnection(Input),header=TRUE)


###  Check the data frame

library(psych)

headTail(Data)

str(Data)

summary(Data)


### Remove unnecessary objects

rm(Input)


Two-sample sign test with BSDA package


Time.1 = Data$Likert [Data$Time == 1]
Time.2 = Data$Likert [Data$Time == 2]

library(BSDA)

SIGN.test(x = Time.1,
          y = Time.2,
          alternative = "two.sided",
          conf.level = 0.95)

 

Dependent-samples Sign-Test

S = 1, p-value = 0.03906

   ### p-value reported above

95 percent confidence interval:
 -2.0000000 -0.3244444

sample estimates:
median of x-y
           -1

   ### median of differences and confidence interval of differences


Two-sample sign test with DescTools package


Time.1 = Data$Likert [Data$Time == 1]
Time.2 = Data$Likert [Data$Time == 2]

library(DescTools)

SignTest(x = Time.1,
         y = Time.2)

Dependent-samples Sign-Test

S = 1, number of differences = 9, p-value = 0.03906

   ### p-value reported above

alternative hypothesis: true median difference is not equal to 0

97.9 percent confidence interval:
 -2  0

sample estimates:
median of the differences
                       -1

   ### median of differences and confidence interval of differences