One-sample sign test in SAEPER
For a discussion of this test, see the corresponding chapter in Summary and Analysis of Extension Program Evaluation in R (rcompanion.org/handbook/F_03.html).
Importing packages in this chapter
The following commands will import required packages used in this chapter from libraries and assign them common aliases. You may need install these libraries first.
import io
import os
import numpy as np
import scipy.stats as stats
from statsmodels.stats.descriptivestats import sign_test
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
Setting your working directory
You may wish to set your working directory for exported plots.
os.chdir("C:/Users/Sal Mangiafico/Desktop")
print(os.getcwd())
Example of one-sample sign test
Data = pd.read_table(sep="\\s+", filepath_or_buffer=io.StringIO("""
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
"""))
### Convert Instructor and Location to category type
Data['Speaker'] = Data['Speaker'].astype('category')
### Display some summary statistics for the data frame
print(Data.info())
# # Column Non-Null Count Dtype
#--- ------ -------------- -----
# 0 Speaker 10 non-null category
# 1 Rater 10 non-null int64
# 2 Likert 10 non-null int64
One-sample sign test
sign_test(Data['Likert'], mu0=3)
(3.0, 0.0703125)
### p = 0.0703
### M, 3.0, is the a statistic related to dominance statistic used below.
### Specifically, it’s the number of obsevations greater than mu minus the
### number of obsevations less than mu, all divided by two.
Effect size
The following is a manual calculation of the dominance statistic and VDA-like statistic presented in SAEPER.
Likert = np.array([3, 4, 5, 4, 4, 4, 4, 3, 2, 5])
MU = 3
N = len(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
Dominance = GreaterProp - LesserProp
Dominance
0.6
VDA = Dominance / 2 + 0.5
VDA
0.8