有没有办法将 2 个“ftable”粘贴到目的?

发布于 2025-01-16 19:48:58 字数 2172 浏览 2 评论 0原文

我使用survey中的svyby来制作一些加权比率及其标准差和变异系数,我使用下面的代码生成一个三向表,它为我提供了男性远程工作者 Hombre_subocup/ocup、女性远程工作者 Mujer_subocup/ocupsubocupocup 的比率对于非远程工作者的男性和女性来说完全相同。

tasasub_tele_sex319<-ftable(svyby(~subocup, by= ~ tele_sinco11 + SEX, subset(sd319, EDA >= 15 & POS_OCU != "Trabajadores sin pago"), denominator = ~ocup, deff= T, level = 0.9, vartype = c("cv", "se"), na.rm.by =  T,svyratio))

tasasub_tele_sex319

并得到:

                        SEX_
tele_sinco11_             Hombre_subocup/ocup Mujer_subocup/ocup
  No teletrabaja_svyratio         0.084149460        0.080230723
  No teletrabaja_cv               0.001782653        0.002152965
  No teletrabaja_SE               0.021184369        0.026834665
  No teletrabaja_DEff             3.896438704        3.593164119
  Teletrabaja_svyratio            0.036515518        0.027384514
  Teletrabaja_cv                  0.003075113        0.002250647
  Teletrabaja_SE                  0.084213867        0.082186856
  Teletrabaja_DEff                2.325352651        2.039503624

但我还需要比率的总值(没有性别),所以我使用此代码并得到以下输出:

tasasub_tele_tot319<-ftable(svyby(~subocup, by= ~ tele_sinco11, subset(sd319, EDA >= 15 & POS_OCU != "Trabajadores sin pago"), denominator = ~ocup, deff= T, level = 0.9, vartype = c("cv", "se"), na.rm.by =  T,svyratio))

tasasub_tele_tot319

>tasasub_tele_tot319

                        subocup/ocup
tele_sinco11                         
No teletrabaja svyratio   0.082730583
               cv         0.001537011
               SE         0.018578512
               DEff       4.722529515
Teletrabaja    svyratio   0.031475714
               cv         0.001902234
               SE         0.060434971
               DEff       2.299934447

这将是没有任何层的比率值(一个简单的双向表)。

我想要做的是将最后一个输出粘贴到前者,这样我就可以在同一个表中得到男性比例列、女性比例列和总比例列,所以或多或少应该如下所示:

在此处输入图像描述< /a>

我不会请注意“总计”列是否先行。

I`m using svyby from survey to make some weighted ratios with their standard deviation and coefficient of variation, I use the code below to generate a three way table which provide me the ratio of subocup compared to ocup for male teleworker Hombre_subocup/ocup, female teleworkers Mujer_subocup/ocup and the exact same for non teleworkers males and females.

tasasub_tele_sex319<-ftable(svyby(~subocup, by= ~ tele_sinco11 + SEX, subset(sd319, EDA >= 15 & POS_OCU != "Trabajadores sin pago"), denominator = ~ocup, deff= T, level = 0.9, vartype = c("cv", "se"), na.rm.by =  T,svyratio))

tasasub_tele_sex319

And get:

                        SEX_
tele_sinco11_             Hombre_subocup/ocup Mujer_subocup/ocup
  No teletrabaja_svyratio         0.084149460        0.080230723
  No teletrabaja_cv               0.001782653        0.002152965
  No teletrabaja_SE               0.021184369        0.026834665
  No teletrabaja_DEff             3.896438704        3.593164119
  Teletrabaja_svyratio            0.036515518        0.027384514
  Teletrabaja_cv                  0.003075113        0.002250647
  Teletrabaja_SE                  0.084213867        0.082186856
  Teletrabaja_DEff                2.325352651        2.039503624

But I also need the total value of the ratio (without SEX), so I use this code and get this output:

tasasub_tele_tot319<-ftable(svyby(~subocup, by= ~ tele_sinco11, subset(sd319, EDA >= 15 & POS_OCU != "Trabajadores sin pago"), denominator = ~ocup, deff= T, level = 0.9, vartype = c("cv", "se"), na.rm.by =  T,svyratio))

tasasub_tele_tot319

>tasasub_tele_tot319

                        subocup/ocup
tele_sinco11                         
No teletrabaja svyratio   0.082730583
               cv         0.001537011
               SE         0.018578512
               DEff       4.722529515
Teletrabaja    svyratio   0.031475714
               cv         0.001902234
               SE         0.060434971
               DEff       2.299934447

This would be the value of the ratio without any strata (a simple two way table).

What I want to do is to paste the last output to the former, so I get a male ratio column, female ratio column and total ratio column in the same table, so more or less it should look like this:

enter image description here

I wouldn't mind if the "total" columns goes first.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻梦旅人 2025-01-23 19:48:58

解决方案是先组合,然后ftable。让我们使用内置数据集来完成此操作:

> a<-svyby(~api.stu,denom=~enroll, ~stype+sch.wide, dclus1,svyratio)
> b<-svyby(~api.stu,denom=~enroll, ~stype, dclus1,svyratio)
> a
      stype sch.wide api.stu/enroll se.api.stu/enroll
E.No      E       No      0.8794583        0.01429043
H.No      H       No      0.8386232        0.01170588
M.No      M       No      0.8390440        0.01478048
E.Yes     E      Yes      0.8508618        0.01231925
H.Yes     H      Yes      0.8286597        0.01622480
M.Yes     M      Yes      0.8589915        0.01272169
> b
  stype api.stu/enroll se.api.stu/enroll
E     E      0.8532672        0.01253361
H     H      0.8300683        0.01472607
M     M      0.8536738        0.01114203

它们具有不同的列名称,但我们可以修复它

>  b$sch.wide<-"Total"
> b
  stype api.stu/enroll se.api.stu/enroll sch.wide
E     E      0.8532672        0.01253361    Total
H     H      0.8300683        0.01472607    Total
M     M      0.8536738        0.01114203    Total

现在将它们组合起来

> ftable(rbind(a,b))
               sch.wide             No            Yes          Total
                        api.stu/enroll api.stu/enroll api.stu/enroll
stype                                                               
E     svyratio              0.87945833     0.85086183     0.85326723
      SE                    0.01429043     0.01231925     0.01253361
H     svyratio              0.83862316     0.82865975     0.83006825
      SE                    0.01170588     0.01622480     0.01472607
M     svyratio              0.83904396     0.85899149     0.85367375
      SE                    0.01478048     0.01272169     0.01114203

The solution is to combine first, then ftable. Let's do this with a built-in data set:

> a<-svyby(~api.stu,denom=~enroll, ~stype+sch.wide, dclus1,svyratio)
> b<-svyby(~api.stu,denom=~enroll, ~stype, dclus1,svyratio)
> a
      stype sch.wide api.stu/enroll se.api.stu/enroll
E.No      E       No      0.8794583        0.01429043
H.No      H       No      0.8386232        0.01170588
M.No      M       No      0.8390440        0.01478048
E.Yes     E      Yes      0.8508618        0.01231925
H.Yes     H      Yes      0.8286597        0.01622480
M.Yes     M      Yes      0.8589915        0.01272169
> b
  stype api.stu/enroll se.api.stu/enroll
E     E      0.8532672        0.01253361
H     H      0.8300683        0.01472607
M     M      0.8536738        0.01114203

These have different column names, but we can fix that

>  b$sch.wide<-"Total"
> b
  stype api.stu/enroll se.api.stu/enroll sch.wide
E     E      0.8532672        0.01253361    Total
H     H      0.8300683        0.01472607    Total
M     M      0.8536738        0.01114203    Total

And now combine them

> ftable(rbind(a,b))
               sch.wide             No            Yes          Total
                        api.stu/enroll api.stu/enroll api.stu/enroll
stype                                                               
E     svyratio              0.87945833     0.85086183     0.85326723
      SE                    0.01429043     0.01231925     0.01253361
H     svyratio              0.83862316     0.82865975     0.83006825
      SE                    0.01170588     0.01622480     0.01472607
M     svyratio              0.83904396     0.85899149     0.85367375
      SE                    0.01478048     0.01272169     0.01114203
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文