2016-11-23 12 views
0

SASにRの関数predict(model, data)と同等のものがありますか?予測モデルの実行方法

たとえば、応答変数「年齢」が不明な大規模なテストデータセットに、以下のモデルをどのように適用しますか?

proc reg data=sashelp.class; 
    model Age = Height Weight ; 
run; 

は、私はあなたが、未知の観測のための「年齢」を予測し、手動で結果ウィンドウから公式年齢=インターセプト+高さ(Estimate_height)+重量(Estimate_weight)を抽出することができ理解し、それは非常に効率的ではありません。

答えて

1

SASはこれを単独で行います。モデルに十分なデータポイントがある限り、予測値が出力されます。私はproc glmを使いましたが、どのようなモデル手続きを使ってもこの種の出力を作成できます。

/* this is a sample dataset */ 
data mydata; 
input age weight dataset $; 
cards; 
1 10 mydata 
2 11 mydata 
3 12 mydata 
4 15 mydata 
5 12 mydata 
; 
run; 

/* this is a test dataset. It needs to have all of the variables that you'll use in the model */ 
data test; 
input weight dataset $; 
cards; 
6 test 
7 test 
10 test 
; 
run; 
/* append (add to the bottom) the test to the original dataset */ 
proc append data=test base=mydata force; run; 

/* you can look at mydata to see if that worked, the dependent var (age) should be '.' */ 
/* do the model */ 
proc glm data=mydata; 
model age = weight/p clparm; /* these options after the '/' are to show predicte values in results screen - you don't need it */ 
output out=preddata predicted=pred lcl=lower ucl=upper; /* this line creates a dataset with the predicted value for all observations */ 
run; 
quit; 

/* look at the dataset (preddata) for the predicted values */ 
proc print data=preddata; 
where dataset='test'; 
run; 
関連する問題