2016-11-23 3 views
0

Gibt es ein Äquivalent von Rs Funktion predict(model, data) in SAS?Wie wird das Vorhersagemodell ausgeführt?

Zum Beispiel, wie würden Sie das untenstehende Modell auf einen großen Testdatensatz anwenden, bei dem die Antwortvariable "Age" unbekannt ist?

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

Ich verstehe Sie die Formel = Alter Intercept extrahieren + Höhe (Estimate_height) + Gewicht (Estimate_weight) aus dem Fenster Ergebnisse und manuell vorhersagen „Alter“ für unbekannte Beobachtungen, aber das ist nicht sehr effizient.

Antwort

1

SAS tut dies an sich. Solange das Modell über genügend Datenpunkte verfügt, wird der vorhergesagte Wert ausgegeben. Ich habe proc glm verwendet, aber Sie können eine beliebige Modellprozedur verwenden, um diese Art von Ausgabe zu erstellen.

/* 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; 
Verwandte Themen