表中边际总计

发布于 2024-11-19 10:24:22 字数 1140 浏览 3 评论 0原文

我有一个数据框,其中包含从不同日期的临床分离株中识别出的许多感染。

到目前为止,我已将数据组织成我想要开始使用的形状。我正在尝试为报告的描述性统计准备一系列表格。

我一直在使用 ftable 并得到以下信息:

onset.types <- ftable(SAB$Onset,SAB$MRSA.Type,year(SAB$Collection.Date))
                             2005 2006 2007 2008 2009 2010

Community                     454  472  512  499  525  512
          AUS-2/3-like         28   23   27   29   32   38
          EMRSA-15-like         9    4    4    9    8    8
          nmMRSA               40   47   53   39   64   60
          Other mMRSA           1    3    3   11    5    9
          unclassified MRSA     0    2    0    0    1    1
Hospital                      163  163  156  164  149  165
          AUS-2/3-like         31   33   27   31   29   28
          EMRSA-15-like         3    8    5    9    4    3
          nmMRSA               10    9   13   17   13   12
          Other mMRSA           5    1    6    2    3   10
          unclassified MRSA     2    0    1    0    0    0

两个问题:

1:我如何计算边际总计

2:是否有一种简单的方法可以计算百分比以及再次使用边际总计进行计数

我尝试过 epitools我并没有发现它像我希望的那样有用。

非常感谢。

I have a data frame with a number of infections identified from clinical isolates at different dates.

So far I have organised the data into a shape that I want to start working with. I am trying to prepare a series of tables of tables for the descriptive statistics of the report.

I have been using ftable and get the following:

onset.types <- ftable(SAB$Onset,SAB$MRSA.Type,year(SAB$Collection.Date))
                             2005 2006 2007 2008 2009 2010

Community                     454  472  512  499  525  512
          AUS-2/3-like         28   23   27   29   32   38
          EMRSA-15-like         9    4    4    9    8    8
          nmMRSA               40   47   53   39   64   60
          Other mMRSA           1    3    3   11    5    9
          unclassified MRSA     0    2    0    0    1    1
Hospital                      163  163  156  164  149  165
          AUS-2/3-like         31   33   27   31   29   28
          EMRSA-15-like         3    8    5    9    4    3
          nmMRSA               10    9   13   17   13   12
          Other mMRSA           5    1    6    2    3   10
          unclassified MRSA     2    0    1    0    0    0

Two questions:

1: How would I calculate marginal totals

2: Is there an easy way to calculate percentages as well as counts again with marginal totals

I have tried epitools and I did not find it as useful as I would have liked.

Many thanks.

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

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

发布评论

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

评论(2

千仐 2024-11-26 10:24:22

要添加边距,请使用 addmargins()

addmargins(table(state.division, state.region))
                    state.region
state.division       Northeast South North Central West Sum
  New England                6     0             0    0   6
  Middle Atlantic            3     0             0    0   3
  South Atlantic             0     8             0    0   8
  East South Central         0     4             0    0   4
  West South Central         0     4             0    0   4
  East North Central         0     0             5    0   5
  West North Central         0     0             7    0   7
  Mountain                   0     0             0    8   8
  Pacific                    0     0             0    5   5
  Sum                        9    16            12   13  50

要计算百分比,请使用 prop.table()

prop.table(table(state.division, state.region))
                    state.region
state.division       Northeast South North Central West
  New England             0.12  0.00          0.00 0.00
  Middle Atlantic         0.06  0.00          0.00 0.00
  South Atlantic          0.00  0.16          0.00 0.00
  East South Central      0.00  0.08          0.00 0.00
  West South Central      0.00  0.08          0.00 0.00
  East North Central      0.00  0.00          0.10 0.00
  West North Central      0.00  0.00          0.14 0.00
  Mountain                0.00  0.00          0.00 0.16
  Pacific                 0.00  0.00          0.00 0.10

To add margins, use addmargins()

addmargins(table(state.division, state.region))
                    state.region
state.division       Northeast South North Central West Sum
  New England                6     0             0    0   6
  Middle Atlantic            3     0             0    0   3
  South Atlantic             0     8             0    0   8
  East South Central         0     4             0    0   4
  West South Central         0     4             0    0   4
  East North Central         0     0             5    0   5
  West North Central         0     0             7    0   7
  Mountain                   0     0             0    8   8
  Pacific                    0     0             0    5   5
  Sum                        9    16            12   13  50

To calculate percentages, use prop.table()

prop.table(table(state.division, state.region))
                    state.region
state.division       Northeast South North Central West
  New England             0.12  0.00          0.00 0.00
  Middle Atlantic         0.06  0.00          0.00 0.00
  South Atlantic          0.00  0.16          0.00 0.00
  East South Central      0.00  0.08          0.00 0.00
  West South Central      0.00  0.08          0.00 0.00
  East North Central      0.00  0.00          0.10 0.00
  West North Central      0.00  0.00          0.14 0.00
  Mountain                0.00  0.00          0.00 0.16
  Pacific                 0.00  0.00          0.00 0.10
月下客 2024-11-26 10:24:22

它还可以与调查包的 svytable() 配合使用。

addmargins(svytable(formula = ~x1+x2, design = df.w))

It also works with survey package's svytable().

addmargins(svytable(formula = ~x1+x2, design = df.w))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文