Proc Reg与Proc PLM生成置信区间的兼容性问题咨询
I ran into exactly this issue recently: when I fit a linear regression with PROC REG, stored the model, then used PROC PLM to score a test dataset, all the confidence interval (LCLM/UCLM) and prediction interval (LCL/UCL) fields came up blank. But when I did the exact same workflow with PROC GLM, the intervals populated perfectly—even though the model parameter estimates from both procedures were identical.
The Root Cause: Model Metadata Differences
This isn't a compatibility bug—it's a deliberate difference in how PROC REG and PROC GLM store model metadata:
PROC GLM: When you use theSTOREstatement, it saves all auxiliary statistics needed to compute intervals, including residual sums of squares, degrees of freedom for error (DFE), mean squared error (MSE), and the inverse of the X'X matrix.PROC PLMrelies on these values to calculate confidence/prediction bounds.PROC REG: The defaultSTOREoutput only saves the parameter estimates (coefficients) of the model. It does not include the variance-related statistics required for interval calculations. Even if you useOUTEST=orTABLEOUT, those outputs are separate from the stored model object—PROC PLMcan't access them directly from the.itemstorefile.
Verifying with Your Code
If you run the SAS code you provided, check the output datasets:
Pred(from the GLM model) will have fully populatedlower_confidence_int,upper_confidence_int,lower_pred_int, andupper_pred_intcolumns.Pred_lin_reg(from the REG model) will leave those columns empty—precisely because the stored REG model lacks the MSE and DFE valuesPROC PLMneeds to compute the intervals.
Solutions
1. Switch to PROC GLM (Simplest Fix, When Possible)
If you're fitting a standard linear regression (no need for PROC REG-specific features like stepwise selection, ridge regression, or leverage diagnostics), just use PROC GLM to fit and store your model. As your code demonstrates, this works seamlessly with PROC PLM for interval generation.
2. Manual Interval Calculation (If You Must Use PROC REG)
If you need to stick with PROC REG (e.g., using its unique regression tools), you can compute the intervals manually by extracting the necessary stats from PROC REG outputs:
Extract key statistics using
ODS OUTPUT:ods output FitStatistics=RegFitStats ParameterEstimates=RegParams; proc reg data=A outest=RegOut tableout; model y = x; store work.proc_reg_model; quit;RegFitStatswill contain MSE and DFE.RegOut(fromTABLEOUT) includes the inverse of the X'X matrix (look for variables starting withXPX_).
Compute intervals using the standard formulas:
- Confidence interval for the mean response:
$\hat{y} \pm t_{\alpha/2, DFE} \times \sqrt{MSE} \times \sqrt{x'(X'X)^{-1}x}$ - Prediction interval for an individual response:
$\hat{y} \pm t_{\alpha/2, DFE} \times \sqrt{MSE} \times \sqrt{1 + x'(X'X)^{-1}x}$
You can implement this in a
DATAstep or usingPROC IMLfor matrix operations.- Confidence interval for the mean response:
内容的提问来源于stack exchange,提问作者asdiuh

