I'm using the EFFECT statement within PROC PHREG to create a spline for one of my model predictors. Is there a way to plot the spline? I would like to plot it against the log hazard of my outcome. I found this SAS blog and used the code from it as below:
proc phreg data=inefac_m1 outdesign=Splines;
class sex famhx(ref='No') smoking(ref='Never');
effect age_sp = spline(age / details naturalcubic basis=tpf(noint) knotmethod=list(25 35 50 60));
model personmonths*htn(0) = age_sp sex sbp1 dbp1 bmi famhx smoking alcohol dbp1|age_sp sex|age_sp sex|dbp1 /TIES=EFRON;
store parameter_dat5_m1;
output out=pre5_m1 survival=surv xbeta=beta;
ods select ParameterEstimates SplineKnots;
ods output ParameterEstimates=PE;
run;
I get an "Assuming the symbol OUT was misspelled as outdesign" warning but it seems to work. But in the next step (PROC IML), I get an error message after pred=X*b (ERROR: (execution) Matrices do not conform to the operation.)
proc iml;
use PE;
read all var "Estimate" into b;
close;
use Splines;
read all var {"age_sp1" "age_sp2" "age_sp3"} into X;
close;
pred = X*b;
create SplineFit var "Pred";
append;
close;
quit;
Can anyone help me troubleshoot this or point me in a different direction, please? The plot shown in the linked SAS blog is pretty much what I would want:
The vector of parameter estimates (b) contains one element for each regression parameter. It looks like your MODEL statement has 20 or more parameters. Your X matrix only has 3 columns, so the matrix operation X*b is not defined.
It's not clear to me what you are trying to achieve. You have a 20-dimensional model, so you can't plot the predicted values for AGE without specifying what values to use for the other variables. One way to do this is to fix the other variables at some values (often the mean or the reference level) and then create a "slice plot" that shows how the predicted values depend on AGE. See https://blogs.sas.com/content/iml/2017/12/20/create-sliced-fit-plot-sas.html
It's not clear to me what you are trying to achieve.
I basically want to make sure that my spline fits the data well. Before creating a spline, I used the following code to look at linearity for the variable age:
proc sgplot data=pre5_m1;
loess x=age y=beta / interpolation=cubic clm nomarkers;
xaxis grid;
yaxis grid label='log Hazard of hypertension';
run;
At first I used the same code as above after fitting the spline model but I thought maybe I need to be plotting age_sp instead of age, which led to this post.
I don't know what the BETA variable is, but your LOESS model is a one-dimensional model. If you want to create a similar model with cubic splines, use only the AGE_SP effect on the MODEL statement. Then your IML code (which forms the predictor from the spline bases) will make sense. In other words, get rid of the other variables such as sbp1, dbp1, bmi, etc.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.