R vs SAS Correlation
Codes
The following table shows the three different types of correlations considered, their functions in each language and whether the results match
Correlation coefficient | R code | SAS code | Results match |
---|---|---|---|
Pearson | cor.test(x,y,method="pearson") |
|
Yes |
Spearman | cor.test(x,y,method="spearman") |
|
Yes |
Kendall | cor.test(x,y,method="kendall") |
|
Yes |
‘x’ and ‘y’ are variables in the dataset “data” for which we determine the correlation.
Comparison Results
Example: Lung Cancer Data
Data source: Loprinzi CL. Laurie JA. Wieand HS. Krook JE. Novotny PJ. Kugler JW. Bartel J. Law M. Bateman M. Klatt NE. et al. Prospective evaluation of prognostic variables from patient-completed questionnaires. North Central Cancer Treatment Group. Journal of Clinical Oncology. 12(3):601-7, 1994.
Survival in patients with advanced lung cancer from the North Central Cancer Treatment Group. Performance scores rate how well the patient can perform usual daily activities. Correlation was observed between age and meal.cal variables in the dataset.
Correlation coefficient | Sample estimates in R | p-value in R | Sample estimate in SAS | p-value in SAS |
---|---|---|---|---|
Pearson | -0.2314107 | 0.001722 | -0.23141 | 0.0017 |
Spearman | -0.2073639 | 0.005095 | -0.20736 | 0.0051 |
Kendall | -0.1443877 | 0.00524 | -0.14439 | 0.0052 |
Please note that the results in SAS are rounded at 5 decimals for sample estimates and 4 decimals for p-values.
Summary
Comparisons between SAS and R yield identical results for the tested dataset. R outputs test statistic values and p-values, whereas SAS offers descriptive statistics (N, mean, standard deviation, sum, minimum, maximum) for each variable, but does not display the test statistic values.