<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I plot a spline in a Cox Regression model (PROC PHREG) in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827440#M40968</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;It's not clear to me what you are trying to achieve.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sgplot data=pre5_m1;
	loess x=age y=beta / interpolation=cubic clm nomarkers;
	xaxis grid;
	yaxis grid label='log Hazard of hypertension';
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2022 20:30:24 GMT</pubDate>
    <dc:creator>pravleen_SAS</dc:creator>
    <dc:date>2022-08-05T20:30:24Z</dc:date>
    <item>
      <title>How do I plot a spline in a Cox Regression model (PROC PHREG)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827279#M40964</link>
      <description>&lt;P&gt;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 &lt;A href="https://blogs.sas.com/content/iml/2019/10/16/visualize-regression-splines.html" target="_blank" rel="noopener"&gt;this&lt;/A&gt; SAS blog and used the code from it as below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I get an "&lt;FONT face="courier new,courier" color="#339966"&gt;&lt;SPAN&gt;Assuming the symbol OUT was misspelled as outdesign&lt;/SPAN&gt;&lt;/FONT&gt;" warning but it seems to work. But in the next step (PROC IML), I get an error message after &lt;FONT face="courier new,courier"&gt;pred=X*b&lt;/FONT&gt; (&lt;FONT face="courier new,courier" color="#FF0000"&gt;&lt;SPAN&gt;ERROR: (execution) Matrices do not conform to the operation.&lt;/SPAN&gt;&lt;/FONT&gt;)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="splineEffects3.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74174i3E8D086EE58DB69C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="splineEffects3.png" alt="splineEffects3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 01:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827279#M40964</guid>
      <dc:creator>pravleen_SAS</dc:creator>
      <dc:date>2022-08-05T01:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I plot a spline in a Cox Regression model (PROC PHREG)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827324#M40965</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2017/12/20/create-sliced-fit-plot-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/12/20/create-sliced-fit-plot-sas.html&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 11:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827324#M40965</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-08-05T11:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I plot a spline in a Cox Regression model (PROC PHREG)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827440#M40968</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;It's not clear to me what you are trying to achieve.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sgplot data=pre5_m1;
	loess x=age y=beta / interpolation=cubic clm nomarkers;
	xaxis grid;
	yaxis grid label='log Hazard of hypertension';
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 20:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827440#M40968</guid>
      <dc:creator>pravleen_SAS</dc:creator>
      <dc:date>2022-08-05T20:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I plot a spline in a Cox Regression model (PROC PHREG)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827462#M40969</link>
      <description>&lt;P&gt;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.&amp;nbsp; In other words, get rid of the other variables such as sbp1, dbp1, bmi, etc.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2022 11:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-plot-a-spline-in-a-Cox-Regression-model-PROC-PHREG/m-p/827462#M40969</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-08-06T11:12:43Z</dc:date>
    </item>
  </channel>
</rss>

