BookmarkSubscribeRSS Feed
N_Hirabayashi
Calcite | Level 5
お世話になります。
proc glmselect
data=cars outdesign(addinputvars fullmodel)=SplineBasis; effect spl = spline(weight / naturalcubic basis=tpf(noint) knotmethod=percentiles(5)); model mpg_city = spl / selection=none; quit; proc reg data=SplineBasis; model mpg_city = spl_:; output out=out predicted=fit; run;
proc sgplot data=out noautolegend;
   scatter x=weight y=mpg_city;
   series x=weight y=Fit / lineattrs=(thickness=3 color=red);
run;
といった重回帰分析のsplineの図示ですが、 model mpg_city = spl / selection=none;  → model mpg_city = spl age/ selection=none;
というように調整因子を入れたものがうまくいきません。
ご教示いただけますと幸いです。
何卒よろしくお願い致します。
7 REPLIES 7
Ksharp
Super User
Add PROC SORT before PROC SGPLOT.


proc sort data=out out=out1;by weight;run;

proc sgplot data=out1 noautolegend;
   scatter x=weight y=mpg_city;
   series x=weight y=Fit / lineattrs=(thickness=3 color=red);
run;
N_Hirabayashi
Calcite | Level 5

Thank you for your reply.

I added proc sort.

 
The figure is the same with or without adjustment factor as shown below.
 
model oxygen = Weight_spl Age/ selection=none ; or 
model oxygen = Weight_spl / selection=none ;
 
If I make the program as shown below, the figure bends squishy.
 
proc reg data=SplineBasis;
model mpg_city = spl_: Age;
output out=out predicted=fit;
run;
 
Are there any good solutions?
 
 
model oxygen = Weight_spl Age/ selection=none ;
model oxygen = Weight_spl / selection=none ;
 とAgeという調整因子を入れる入れないで、figureが同じようです。
 
そこで、下記のようなプログラムにすると、figureの回帰直線ががたがたになってしまいます。解決策はあるでしょうか。
proc reg data=SplineBasis;
model mpg_city = spl_: Age;
output out=out predicted=fit;
run;
yu_sas
SAS Employee

ageを追加したいとのことですが、どのようなグラフを作成されることを意図されているのでしょうか。REGプロシジャのMODELステートメントにageを追加した場合、それぞれのオブザベーションが持つspl1-4とageの値を用いた予測値が出力されることになります。

 

例えば等高線プロットであればPLMプロシジャのEFFECTPLOTステートメントで描画が可能です。

 

proc glmselect data=sashelp.cars outdesign(addinputvars fullmodel)=SplineBasis;
   effect spl = spline(weight / naturalcubic basis=tpf(noint) knotmethod=percentiles(5));
   model mpg_city = spl  length / selection=none;  
   store spl;
quit;

proc plm restore=spl;
effectplot;
run;
N_Hirabayashi
Calcite | Level 5

ご返事ありがとうございます。

下記のURLにWeightとMPGの関係がスプラインで図示されていますが、これを他の変数を調整したうえで(かつ95%信頼区間をつけて)図示したいというのが目的です。

お手数をおかけします。

 

 

https://blogs.sas.com/content/iml/2019/02/18/regression-restricted-cubic-splines-sas.html

yu_sas
SAS Employee

他の変数を調整するというのは具体的にどのような処理を指しているのでしょうか。もう少し詳細な内容を頂ければ何かご案内できるかもしれません。

N_Hirabayashi
Calcite | Level 5

言葉足らずですみません。

例えば 血圧 = BMI の関係 で年齢が交絡因子になるので、年齢を調整したいとします。

XBMIYが血圧の回帰直線を年齢の影響を除いて書きたいと思っています。

そのうえで、それをspline(+95%信頼区間)で書きたいと思っています。

 

上記の投稿で勘違いしておりましたが、

血圧 =切片 + β1×BMI + β2×年齢

で、年齢調整後、図示するとき、おそらくβ2は用いないですね

 

proc glmselect data=cars outdesign(addinputvars fullmodel)=SplineBasis;

   effect BMI_spl = spline(BMI / naturalcubic basis=tpf(noint) knotmethod=percentiles(5));

   model SBP = BMI_spl AGE/ selection=none; 

quit;

 

このモデルでどのようにして、XBMIYが血圧の回帰直線を年齢の影響を除いて書けるかで悩んでいます。

yu_sas
SAS Employee

例えば平均値のような特定の値における予測値を算出するのであれば以下のような

記述ができるかと思います。

 

proc glmselect data=sashelp.cars outdesign(addinputvars fullmodel)=SplineBasis;
   effect spl = spline(weight / naturalcubic basis=tpf(noint) knotmethod=percentiles(5));
   model mpg_city = spl  length / selection=none;  
   store spl;
quit;

data cars2;
set sashelp.cars;
length=186;
run;

proc plm restore=spl;
score data=cars2 out=out;
run;

proc sort data=out;
by weight;
run;
proc sgplot data=out;
series x=weight y=predicted;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Discussion stats
  • 7 replies
  • 1715 views
  • 0 likes
  • 3 in conversation