# Statistics

Below is a comparison of the commands used to perform various statistical analyses in R, SAS, SPSS, and Stata. For R functions that are not included in base R, the library() function loads the package that contains the function right before it is used. The variables gender and workshop are categorical factors, and q1 to q4, pretest and posttest are considered continuous and normally distributed.

The practice data set is shown here. The programs and the data they use are also available for download here. Detailed step-by-step explanations are in the books, along with the output of each analysis.

Analysis of Variance

R

```myModel &lt;- aov(posttest ~ workshop,
data = mydata100)
summary(myModel)
pairwise.t.test(posttest, workshop)
TukeyHSD(myModel, "workshop")
plot(TukeyHSD(myModel, "workshop"))

SAS
PROC GLM;
CLASS workshop;
MODEL posttest = workshop;
MEANS workshop / TUKEY;
RUN;

SPSS
UNIANOVA posttest  BY workshop
/POSTHOC = workshop ( TUKEY )
/PRINT = ETASQ HOMOGENEITY
/DESIGN = workshop.

Stata
anova posttest workshop

Correlate, Pearson
cor( mydata[3:6],
method = "pearson",
use = "pairwise")
cor.test(mydata\$q1,
mydata\$q2, use = "pairwise")

# Again, adjusting p-values for multiple testing.
library("Rcmdr")

SAS
PROC CORR;
VAR q1-q4;
RUN;

SPSS
CORRELATIONS
/VARIABLES=q1 TO q4.

Stata
correlate q*

Correlate, Spearman
R
cor( mydata[3:6],
method = "spearman",
use = "pairwise")
cor.test(mydata\$q1,
mydata\$q2,
use = "pairwise")

# Again, adjusting p-values for multiple testing.
library("Rcmdr")

SAS
PROC CORR SPEARMAN;
VAR q1-q4;
RUN;

SPSS
NONPAR CORR
/VARIABLES=q1 to q4
/PRINT=SPEARMAN.

Stata
spearman q*

Crosstabulation & Chi-squared
R
myWG &lt;- table(workshop, gender)
chisq.test(myWG)

library("gmodels")
CrossTable(workshop, gender,
chisq = TRUE,
format = "SAS")

SAS
PROC FREQ;
TABLES workshop*gender / CHISQ;
RUN;

SPSS
CROSSTABS
/TABLES=workshop BY gender
/FORMAT= AVALUE TABLES
/STATISTIC=CHISQ
/CELLS= COUNT ROW
/COUNT ROUND CELL

Stata
tab gender workshop, row col exact

Descriptive Statistics
R
summary(mydata)

library("Hmisc")
describe(mydata)

SAS
PROC MEANS;
VAR q1--posttest;

PROC UNIVARIATE; VAR q1--posttest;

SPSS
DESCRIPTIVES VARIABLES=q1 to posttest
/STATISTICS=MEAN STDDEV VARIANCE
MIN MAX SEMEAN.

EXAMINE VARIABLES=q1 to posttest
/PLOT BOXPLOT STEMLEAF NPPLOT
/COMPARE GROUP
/STATISTICS DESCRIPTIVES EXTREME
/MISSING PAIRWISE.

Stata
summary q*

summary q*, detail

Frequencies
R
summary(mydata)

library("Deducer")
frequencies(mydata)

SAS
PROC FREQ;
TABLES workshop--q4;
RUN;

SPSS
FREQUENCIES VARIABLES= workshop TO q4.

Stata
tab1 workshop gender q*

Kruskal-Wallis
R
kruskal.test(posttest ~
workshop)

pairwise.wilcox.test(posttest,
workshop)

SAS
PROC npar1way;
CLASS workshop;
VAR posttest;

SPSS
NPAR TESTS
/K-W=posttest BY
workshop(1 3).

Stata
kwallis q1, by(gender)

Linear Regression
R
myModel &lt;- lm(q4 ~ q1 + q2 + q3, data = mydata100)
summary(myModel)
plot(myModel)

SAS
PROC REG;
MODEL q4 = q1-q3;

SPSS
REGRESSION
/MISSING LISTWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT q4
/METHOD=ENTER q1 q2 q3.

Stata
regress q4 q1-q3
lvr2plot

Sign Test
R
library("PASWR")
SIGN.test(posttest, pretest,
conf.level = .95)

SAS
myDiff=posttest-pretest;
PROC UNIVARIATE;
VAR myDiff;
RUN;

SPSS
NPTESTS
/RELATED TEST(q1 q2) SIGN
/MISSING SCOPE=ANALYSIS USERMISSING=EXCLUDE
/CRITERIA ALPHA=0.05
CILEVEL=95.

Stata
bitest posttest &amp;gt;; pretest

t-Test, Independent
R
t.test(q1 ~ gender,
data = mydata100)

SAS
PROC TTEST;
CLASS gender;
VAR q1;
RUN;

SPSS
T-TEST
GROUPS = gender('m' 'f')
/VARIABLES = q1.

Stata
ttest gender=q1, unpair unequ

t-Test, Paired
R

t.test(posttest, pretest,
paired = TRUE)

SAS
PROC TTEST;
PAIRED pretest*posttest;
RUN;

SPSS
T-TEST
PAIRS=pretest WITH
posttest (PAIRED).

Stata
anova posttest workshop

Variance Test
R
t.test(posttest, pretest,
paired = TRUE)

SAS
It’s built into other procedures, such as GLM.
SPSS
It’s built into other procedures, such as GLM.
Stata
robvar posttest, by(gender)

* Or...
sdtest posttest = gender

Wilcoxon Rank Sum (Mann-Whitney)
R
wilcox.test(q1 ~ gender,
data = mydata100)

SAS
PROC NPAR1WAY;
CLASS gender;
VAR q1;
RUN;

SPSS
NPTESTS
/RELATED TEST(pretest posttest) SIGN WILCOXON.

Stata
ranksum posttest, by(gender)

Wilcoxon Signed Rank (Paired)
R
wilcox.test(posttest, pretest, paired = TRUE)

SAS
myDiff=posttest-pretest;
PROC UNIVARIATE;
VAR myDiff;
RUN;

SPSS
NPTESTS
/RELATED TEST(q1 q2) WILCOXON
/MISSING SCOPE=ANALYSIS USERMISSING=EXCLUDE
/CRITERIA ALPHA=0.05 CILEVEL=95.

Stata
signrank q1 = gender

Share this:Click to email a link to a friend (Opens in new window)Click to share on LinkedIn (Opens in new window)Click to share on Reddit (Opens in new window)Click to share on Twitter (Opens in new window)Click to share on Facebook (Opens in new window)MoreClick to share on Telegram (Opens in new window)Click to share on Tumblr (Opens in new window)Click to share on Pinterest (Opens in new window)Click to share on WhatsApp (Opens in new window)Click to share on Pocket (Opens in new window)Like this:Like Loading...			```

This site uses Akismet to reduce spam. Learn how your comment data is processed.