Different Results in General Linear Models: SAS vs R
In statistics, General Linear Models (GLMs) are widely used to analyze the relationship between a continuous response variable and one or more explanatory variables. SAS and R are two popular programming languages used for statistical analysis, and it is not uncommon to find differences in the results obtained from these two systems. In this article, we will explore the reasons behind these differences in the context of GLMs, specifically when computing least square means.
General Linear Models: A Brief Overview
GLMs are a generalization of linear regression models that allow for response variables with error distribution models other than a normal distribution. They also allow for the inclusion of both continuous and categorical predictor variables. The least square means (LSMeans) is a population average that represents the expected value of the response variable for a given level of a categorical predictor variable, adjusted for the other predictor variables in the model.
Comparing SAS and R: The Problem
When comparing SAS and R for GLM analysis, one might expect to obtain identical results, given that both systems use similar algorithms for model estimation. However, this is not always the case. A user reported trying to convert SAS code that computes LSMeans for a GLM to R and found that the results were not identical. The user had not yet figured out the reason for this discrepancy, but suspected it might be due to differences in the algorithms used by SAS and R for marginal modeling.
Potential Reasons for Differences in Results
There are several potential reasons for differences in results obtained from SAS and R for GLM analysis. Some of these include:
Differences in the algorithms used for model estimation: SAS and R use different algorithms for model estimation, which can lead to differences in the results obtained. For example, SAS uses a ridge regression approach for GLM estimation, while R uses a maximum likelihood approach.
Differences in the default settings for options: SAS and R have different default settings for various options, which can affect the results obtained. For example, SAS uses a default contrast type of "simple" for categorical predictor variables, while R uses a default contrast type of "treatment".
Differences in the handling of missing values: SAS and R handle missing values differently, which can affect the results obtained. For example, SAS uses listwise deletion of cases with missing values, while R uses pairwise deletion.
Addressing the Problem
To address the problem of differences in results obtained from SAS and R for GLM analysis, users can take several steps. These include:
Checking the documentation for both systems to ensure that the same options and settings are being used.
Comparing the output from both systems to identify any discrepancies and attempting to determine the cause of these discrepancies.
Consulting the literature or reaching out to experts in the field for guidance on how to address any differences in results obtained.
While SAS and R are both popular programming languages used for statistical analysis, they can sometimes produce different results for GLM analysis. This can be due to differences in the algorithms used for model estimation, default settings for options, and the handling of missing values. To address this problem, users can take several steps, including checking the documentation, comparing the output from both systems, and consulting the literature or experts in the field. By taking these steps, users can ensure that they are obtaining accurate and reliable results from their GLM analysis.
References
SAS Institute Inc. (2021). General Linear Models Procedure. SAS
R Core Team (2021). A Language and Environment for Statistical Computing. R Foundation for Statistical Computing.
Fox, J. (2016). Applied Regression Analysis and Generalized Linear Models. Sage Publications.