【问题标题】:How to add a custom fitted line to SAS SGplot Scatter如何将自定义拟合线添加到 SAS SGplot Scatter
【发布时间】:2017-12-11 01:15:03
【问题描述】:

我有一个简单的SAS data set 我正在绘制散点图,我的两个问题是:

  1. 我正在尝试在不排除 (0.02,51) 数据点的情况下调整 y 轴,但我需要 y 轴仅显示 60 到 160 x 20。当我定义它时,它会排除该特定数据点并且我不知道怎么解决。
  2. 我不知道如何添加自定义拟合曲线并显示公式。这是我的线:Y=(160.3*x)/(0.0477+x)

这是我的代码:

proc sgplot data=work.sas1;
title 'Puromycin Uptake Experiments';
scatter x=x y=y/ markerattrs=(color=black);
xaxis Label='Reactant Concentration X (mg/l)';
yaxis Label='Reaction Velocity Y (mg/s)' values=(60 to 160 by 20);
run;

有人可以帮忙吗?

【问题讨论】:

  • 如果 y 轴仅从 60 变为 160,那么绘图如何包含 y=51 的点?你想要一个延伸到 50 的 y 轴,但只标记到 60?

标签: sas sgplot


【解决方案1】:

尝试使用 OFFSETMIN= 将 yaxis 扩展到您的值之外。

使用公式的值添加一个新变量 y_hat。绘制它并适当地标记它。

data sas1;
x=.02; y=67; output;
x=.02; y=51; output;
x=.06; y=84; output;
x=.06; y=86; output;
x=.11; y=98; output;
x=.11; y=115; output;
x=.22; y=131; output;
x=.22; y=124; output;
x=.56; y=144; output;
x=.56; y=158; output;
x=1.1; y=160; output;
run;

data sas1;
set sas1;
Y_hat=(160.3*x)/(0.0477+x);
run;

proc sgplot data=work.sas1;
title 'Puromycin Uptake Experiments';
scatter x=x y=y/ markerattrs=(color=black);
series x=x y=y_hat / curvelabel="Y=(160.3*x)/(0.0477+x)";
xaxis Label='Reactant Concentration X (mg/l)';
yaxis Label='Reaction Velocity Y (mg/s)' offsetmin=.1 values=(60 to 160 by 20);
run;

产生:

【讨论】:

    【解决方案2】:

    y 轴

    有几个 y 轴选项可以影响轴渲染。考虑offsetminvalues= 中的调整列表

    公式行

    SGPLOT 中没有 formula 语句,因此您必须创建一个辅助列用于在 series 中绘制公式。有时您可以将数据的 x 与公式的 x 对齐。但是,对于需要更高密度的 x 公式的情况,您可以堆叠散点图和公式数据。 不要沉迷于大量缺失值和任何浪费的感觉。

    我不确定您的曲线拟合来自何处,但统计图形(SGPLOT 中的 SG)具有许多用于拟合内置数据的功能。

    * make some example data that looks something like the fit curve;
    data have;
      do x = 0.03 to 1 by 0.0125;
        y = ( 160.3 * x ) / ( 0.0477 + x ) ;
        y + round ( 4 * ranuni(123) - 8, 0.0001);
        output; 
        x = x * ( 1 + ranuni(123) );
      end;
    
      x = 0.02;
      y = 51;
      output;
    run;
    
    * generate the series data for drawing the fit curve;
    * for complicated formula you may want to adjust step during iteration;
    data fit;
      step = 0.001;
      do x = 0 to 1;
        y = ( 160.3 * x ) / ( 0.0477 + x ) ;
        output;
        * step = step + smartly-adjusted-x-increment;
        x + step;
      end;
      keep x y;
      rename x=xfit y=yfit;
    run;
    
    * stack the scatter data and the curve fit data;
    data have_stack_fit;
      set have fit;
    run;
    
    proc sgplot data=have_stack_fit;
      scatter x = x y = y;
      series  x = xfit y = yfit / legendlabel="( 160.3 * x ) / ( 0.0477 + x )";
    
      yaxis values = (0 60 to 160 by 20) ;
    run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2012-09-16
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      相关资源
      最近更新 更多