【问题标题】:How to run prediction model如何运行预测模型
【发布时间】:2016-11-25 11:10:42
【问题描述】:

在 SAS 中是否存在与 R 的函数 predict(model, data) 等效的函数?

例如,您如何将以下模型应用于响应变量“年龄”未知的大型测试数据集?

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

我知道您可以从结果窗口中提取公式 Age = Intercept + Height(Estimate_height) + Weight(Estimate_weight) 并手动预测未知观察的“年龄”,但这不是很有效。

【问题讨论】:

    标签: sas predict


    【解决方案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;
    

    【讨论】:

      猜你喜欢
      • 2020-03-08
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      相关资源
      最近更新 更多