{"id":75,"date":"2012-04-25T22:33:47","date_gmt":"2012-04-26T02:33:47","guid":{"rendered":"http:\/\/r4stats.wordpress.com\/?page_id=75"},"modified":"2022-08-25T07:45:08","modified_gmt":"2022-08-25T11:45:08","slug":"statistics","status":"publish","type":"page","link":"https:\/\/r4stats.com\/examples\/statistics\/","title":{"rendered":"Statistics"},"content":{"rendered":"<p>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.<\/p>\n<p>The practice data set is shown <a href=\"https:\/\/r4stats.com\/examples\/mydata\">here<\/a>. The programs and the data they use are also available for download <a title=\"Downloads\" href=\"https:\/\/r4stats.com\/downloads\/\" target=\"_blank\" rel=\"noopener\">here<\/a>. Detailed step-by-step explanations are in the books, along with the output of each analysis.<\/p>\n<p style=\"text-align: center;\"><strong>Analysis of Variance<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nmyModel &amp;lt;- aov(posttest ~ workshop,\n  data = mydata100)\nsummary(myModel)\npairwise.t.test(posttest, workshop)\nTukeyHSD(myModel, &quot;workshop&quot;)\nplot(TukeyHSD(myModel, &quot;workshop&quot;))\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC GLM;\n  CLASS workshop;\n  MODEL posttest = workshop;\n  MEANS workshop \/ TUKEY;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nUNIANOVA posttest  BY workshop\n  \/POSTHOC = workshop ( TUKEY )\n  \/PRINT = ETASQ HOMOGENEITY\n  \/DESIGN = workshop.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nanova posttest workshop\n<\/pre>\n<p style=\"text-align: center;\"><strong>Correlate, Pearson<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\ncor( mydata&#x5B;3:6],\n  method = &quot;pearson&quot;,\n     use = &quot;pairwise&quot;)\ncor.test(mydata$q1,\n  mydata$q2, use = &quot;pairwise&quot;)\n\n# Again, adjusting p-values for multiple testing.\nlibrary(&quot;Rcmdr&quot;)\nrcorr.adjust( mydata&#x5B;3:6] )\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC CORR;\n  VAR q1-q4;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nCORRELATIONS\n  \/VARIABLES=q1 TO q4.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\ncorrelate q*\n<\/pre>\n<p style=\"text-align: center;\"><strong>Correlate, Spearman<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\ncor( mydata&#x5B;3:6],\n  method = &quot;spearman&quot;,\n  use = &quot;pairwise&quot;)\ncor.test(mydata$q1,\n  mydata$q2,\n  use = &quot;pairwise&quot;)\n\n# Again, adjusting p-values for multiple testing.\nlibrary(&quot;Rcmdr&quot;)\nrcorr.adjust(mydata&#x5B;3:6], type = &quot;spearman&quot;)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC CORR SPEARMAN;\n  VAR q1-q4;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nNONPAR CORR\n  \/VARIABLES=q1 to q4\n  \/PRINT=SPEARMAN.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nspearman q*\n<\/pre>\n<p style=\"text-align: center;\"><strong>Crosstabulation &amp; Chi-squared <\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nmyWG &amp;lt;- table(workshop, gender)\nchisq.test(myWG)\n\nlibrary(&quot;gmodels&quot;)\nCrossTable(workshop, gender,\n  chisq = TRUE,\n  format = &quot;SAS&quot;)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC FREQ;\n  TABLES workshop*gender \/ CHISQ;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nCROSSTABS\n  \/TABLES=workshop BY gender\n  \/FORMAT= AVALUE TABLES\n  \/STATISTIC=CHISQ\n  \/CELLS= COUNT ROW\n  \/COUNT ROUND CELL\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\ntab gender workshop, row col exact\n<\/pre>\n<p style=\"text-align: center;\"><strong>Descriptive Statistics<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nsummary(mydata)\n\nlibrary(&quot;Hmisc&quot;)\ndescribe(mydata)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC MEANS;\nVAR q1--posttest;\n\nPROC UNIVARIATE; VAR q1--posttest;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nDESCRIPTIVES VARIABLES=q1 to posttest\n  \/STATISTICS=MEAN STDDEV VARIANCE\n   MIN MAX SEMEAN.\n\nEXAMINE VARIABLES=q1 to posttest\n  \/PLOT BOXPLOT STEMLEAF NPPLOT\n  \/COMPARE GROUP\n  \/STATISTICS DESCRIPTIVES EXTREME\n  \/MISSING PAIRWISE.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nsummary q*\n\nsummary q*, detail\n<\/pre>\n<p style=\"text-align: center;\"><strong>Frequencies<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nsummary(mydata)\n\nlibrary(&quot;Deducer&quot;)\nfrequencies(mydata)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC FREQ;\n  TABLES workshop--q4;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nFREQUENCIES VARIABLES= workshop TO q4.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\ntab1 workshop gender q*\n<\/pre>\n<p style=\"text-align: center;\"><strong>Kruskal-Wallis<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nkruskal.test(posttest ~\n  workshop)\n\npairwise.wilcox.test(posttest,\n  workshop)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC npar1way;\n  CLASS workshop;\n  VAR posttest;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nNPAR TESTS\n  \/K-W=posttest BY\n   workshop(1 3).\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nkwallis q1, by(gender)\n<\/pre>\n<p style=\"text-align: center;\"><strong>Linear Regression<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nmyModel &amp;lt;- lm(q4 ~ q1 + q2 + q3, data = mydata100)\nsummary(myModel)\nplot(myModel)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC REG;\n  MODEL q4 = q1-q3;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nREGRESSION\n  \/MISSING LISTWISE\n  \/STATISTICS COEFF OUTS R ANOVA\n  \/CRITERIA=PIN(.05) POUT(.10)\n  \/NOORIGIN\n  \/DEPENDENT q4\n  \/METHOD=ENTER q1 q2 q3.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nregress q4 q1-q3\nlvr2plot\n<\/pre>\n<p style=\"text-align: center;\"><strong>Sign Test<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nlibrary(&quot;PASWR&quot;)\nSIGN.test(posttest, pretest,\n  conf.level = .95)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nmyDiff=posttest-pretest;\nPROC UNIVARIATE;\n  VAR myDiff;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nNPTESTS\n  \/RELATED TEST(q1 q2) SIGN\n  \/MISSING SCOPE=ANALYSIS USERMISSING=EXCLUDE\n  \/CRITERIA ALPHA=0.05\n   CILEVEL=95.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nbitest posttest &amp;amp;gt;; pretest\n<\/pre>\n<p style=\"text-align: center;\"><strong>t-Test, Independent<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nt.test(q1 ~ gender,\n  data = mydata100)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC TTEST;\n  CLASS gender;\n  VAR q1;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nT-TEST\n  GROUPS = gender('m' 'f')\n  \/VARIABLES = q1.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nttest gender=q1, unpair unequ\n<\/pre>\n<p style=\"text-align: center;\"><strong>t-Test, Paired<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\n\n\tt.test(posttest, pretest,\n  paired = TRUE)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC TTEST;\n  PAIRED pretest*posttest;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nT-TEST\n  PAIRS=pretest WITH\n  posttest (PAIRED).\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nanova posttest workshop\n<\/pre>\n<p style=\"text-align: center;\"><strong>Variance Test<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nt.test(posttest, pretest,\n  paired = TRUE)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<p>It&#8217;s built into other procedures, such as GLM.<\/p>\n<p><strong>SPSS<\/strong><\/p>\n<p>It&#8217;s built into other procedures, such as GLM.<\/p>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nrobvar posttest, by(gender)\n\n* Or...\nsdtest posttest = gender\n<\/pre>\n<p style=\"text-align: center;\"><strong>Wilcoxon Rank Sum (Mann-Whitney)<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nwilcox.test(q1 ~ gender,\n  data = mydata100)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nPROC NPAR1WAY;\n  CLASS gender;\n  VAR q1;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nNPTESTS\n  \/RELATED TEST(pretest posttest) SIGN WILCOXON.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nranksum posttest, by(gender)\n<\/pre>\n<p style=\"text-align: center;\"><strong>Wilcoxon Signed Rank (Paired)<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>R<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nwilcox.test(posttest, pretest, paired = TRUE)\n<\/pre>\n<p><strong>SAS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nmyDiff=posttest-pretest;\nPROC UNIVARIATE;\n  VAR myDiff;\n  RUN;\n<\/pre>\n<p><strong>SPSS<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nNPTESTS\n  \/RELATED TEST(q1 q2) WILCOXON\n  \/MISSING SCOPE=ANALYSIS USERMISSING=EXCLUDE\n  \/CRITERIA ALPHA=0.05 CILEVEL=95.\n<\/pre>\n<p><strong>Stata<\/strong><\/p>\n<pre><pre class=\"brush: r; title: ; notranslate\" title=\"\">\nsignrank q1 = gender\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/r4stats.com\/examples\/statistics\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Statistics<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":58,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"class_list":["post-75","page","type-page","status-publish","hentry"],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P6TIhK-1d","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/pages\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":6,"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/pages\/75\/revisions"}],"predecessor-version":[{"id":4146,"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/pages\/75\/revisions\/4146"}],"up":[{"embeddable":true,"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/pages\/58"}],"wp:attachment":[{"href":"https:\/\/r4stats.com\/wp-json\/wp\/v2\/media?parent=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}