Stata-散点图置信区间

CJ12

我试图连接两个点以表示以下数据集的置信区间。

Y          Y_upper_ci          Y_lower_ci           X
10           12                    8                1
20           22                    14               2
30           37                    22               3
40           42                    33               4
50           53                    48               5

我一直在使用以下内容。

twoway scatter Y Y_upper_ci Y_lower_ci X,  ///
  connect(l) sort ///
  title("Main Title") ///
  subtitle("Subtitle") ///
  ytitle(Y) ///
  xtitle(X)

我以为connect(l)会照顾这,但它只有Y,而不是连接Y_upper_ciY_lower_ci

另外,我如何让图例仅返回标签Y,而不返回Y_upper_ciY_lower_ci

马丁·布伊斯(Maarten Buis)

以下是几个选项:

// prepare some data
clear all
input Y          Y_upper_ci          Y_lower_ci           X
10           12                    8                1
20           22                    14               2
30           37                    22               3
40           42                    33               4
50           53                    48               5
end

// first graph
twoway rcap Y_upper_ci Y_lower_ci X, lstyle(ci) ||   ///
       scatter Y X, mstyle(p1)                       ///
       legend(order(2 "Y" ))                         ///
       note("with 95% confidence interval")          /// 
       name(rcap, replace)

在此处输入图片说明

// second graph
twoway rspike Y_upper_ci Y_lower_ci X, lstyle(ci) || ///
       scatter Y X, mstyle(p1)                       ///
       legend(order(2 "Y" ))                         ///
       note("with 95% confidence interval")          ///
       name(rspike, replace)

在此处输入图片说明

/// third graph
twoway rline Y_upper_ci Y_lower_ci X, lstyle(ci) ||  ///
       scatter Y X, mstyle(p1)                       ///
       legend(order(2 "Y" ))                         ///
       note("with 95% confidence interval")          ///
       name(rline, replace)

在此处输入图片说明

// fourth graph
twoway line Y_upper_ci Y_lower_ci X, lstyle(p2 p3) || ///
       scatter Y X, mstyle(p1)                        ///
       legend(order(3 "Y" ))                          ///
       note("with 95% confidence interval")          ///
       name(line, replace)

在此处输入图片说明

// fifth graph
twoway rarea Y_upper_ci Y_lower_ci X , astyle(ci) || ///
       scatter Y X, mstyle(p1)                       ///
       legend(order(2 "Y" ))                         ///
       note("with 95% confidence interval")          ///
       name(rarea, replace)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章