R vs SAS One Sample T-Test

One Sample t-test Comparison

The following table shows the types of One Sample t-test analysis, the capabilities of each language, and whether or not the results from each language match.

Analysis Supported in R Supported in SAS Results Match Notes
One sample t-test, normal data Yes Yes Yes In Base R, use mu parameter on t.test() function to set null hypothesis value
One sample t-test, lognormal data Maybe Yes NA May be supported by envstats package

Comparison Results

Normal Data

Here is a table of comparison values between t.test(), proc_ttest(), and SAS PROC TTEST:

Statistic t.test() proc_ttest() PROC TTEST Match Notes
Degrees of Freedom 29 29 29 Yes
t value 2.364306 2.364306 2.364306 Yes
p value 0.0249741 0.0249741 0.0249741 Yes

Lognormal Data

Since there is currently no known support for lognormal t-test in R, this comparison is not applicable.

Summary and Recommendation

For normal data, the R one sample t-test capabilities are comparable to SAS. Comparison between SAS and R show identical results for the datasets tried. The procs package proc_ttest() function is very similar to SAS in the syntax and output produced. proc_ttest() also supports by groups, where t.test() does not.

For the lognormal version of the t-test, it does not appear to be supported in the stats or procs package. It may be supported in the envstats package. More exploration is needed to determine whether this package will produce the expected results, and whether the results will match SAS.

Also note that neither t.test() or proc_ttest() supports the “freq” option that is utilized on examples from the SAS documentation. Therefore, this option has been removed from this comparison. In R, the “freq” functionality could be performed by manipulating the data prior to sending to the t-test function.

References

R t.test() documentation: https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/t.test

R proc_ttest() documentation: https://procs.r-sassy.org/reference/proc_ttest.html

SAS PROC TTEST One Sample analysis documentation: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_ttest_syntax09.htm