带有expss包的复杂表 [英] Complex tables with expss package

查看:138
本文介绍了带有expss包的复杂表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向所有expss专家问好(@Gregory Demin,如果您阅读此消息!),几天后发现此软件包,我取得了不错的成绩,但仍然难以使用tab_ *系列函数创建复杂的交叉表,特别是创建具有显着性测试的组合.

Hello to all expss experts (@Gregory Demin, if you read this message!), after few days discovering this package, I achieved nice things but still struggle a bit to create complex crosstabs with the tab_* family of functions, especially to create combinations with significance tests.

让我们从参考手册上给出的示例开始:

Let's start with an example given on the reference manual:

library(expss)
mtcars %>%
  tab_significance_options(keep = "none", sig_labels = NULL, subtable_marks = "greater", mode = "append") %>%
  tab_cols(total(), vs, am) %>%
  tab_cells(cyl, gear) %>%
  tab_stat_cpct() %>%
  tab_last_add_sig_labels() %>%
  tab_last_sig_cpct() %>%
  tab_last_hstack("inside_columns") %>%
  tab_pivot(stat_position = "inside_rows")

从这一点来看,我不知道是否可以执行以下操作,如果可以,什么脚本可以解决问题:

From this point, I do not know if the following actions are possible, and if so what scripts would do the trick:

1)使用"fre"功能可以非常简单地并排显示计数和百分比,但仅限于此目的.我们如何将案例添加到交叉表? (以案例/百分比/测试的形式,在3个不同的列中显示)

1) It is quite simple with 'fre' function to display counts and percentages side by side, but is limited to this only purpose. How can we add the cases to the crosstab? (in the form of cases/percents/tests, in 3 distinct columns)

2)默认情况下,此示例中的显着性检验输出为LETTERS,处于0.05级别.这两个参数都可以更改.但是,是否可以在单个表计算中包括两个显着性水平?本着以下精神:

2) By default the significance tests output in this example is LETTERS, at 0.05 level. Both parameters can be changed. But is it possible to include two significance levels in a single table calculation? Something in the spirit of:

sig_level = c(0.01, 0.05)
sig_labels = c(LETTERS, letters)

3)最后(可能是一个简单的数字吗?),是否有可能强制显示零?我有频率为0的因子水平,在基数R表中以0s显示.使用expss时,标签会保留,但行/列仍为空.

3) Last (probably an easy one?), is there a possibility to force display of zeros? I have factor levels with frequencies=0, displayed with 0s in base R tables. With expss the label stays but the rows/columns remain empty.

再次,也许我要找的东西与expss不存在,但是至少我会确定. 谢谢!

Again, maybe what I am looking for does not exist with expss, but at least I will be sure of it. Thank you!

推荐答案

您的第二点(两级含义)目前无法实现.但是,您可以在经过特殊准备的表格上通过其他计算来添加第二级重要性. 1和3很简单:

Your second point (two-level significance) is not possible right now. However you can add second level significance with additional calculations on specially prepared table. 1 and 3 are quite easy:

library(expss)
data(mtcars)
mtcars %>%
    tab_significance_options(keep = "none", sig_labels = NULL, subtable_marks = "greater", mode = "append") %>%
    tab_cols(total(), vs, am) %>%
    tab_cells(cyl, gear) %>%
    # block for cases 
    tab_stat_cases(label = "cases") %>% 
    tab_last_add_sig_labels() %>%
    # block for percent statistic
    tab_stat_cpct(label = "%") %>% # percent
    tab_last_add_sig_labels() %>%
    tab_last_sig_cpct() %>%
    tab_pivot(stat_position = "inside_columns") %>% 
    # converts NA to zero
    recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)

更新: 您可以将链的各个部分指定为自定义函数,以避免重复:

UPDATE: You can specify parts of the chain as custom functions to avoid repetition:

library(expss)
data(mtcars)

### tab cols
my_banner = mtcars %>%
    tab_cols(total(), vs, am)

### table and formattig
my_custom_table = . %>% 
    tab_significance_options(keep = "none", sig_labels = NULL, subtable_marks = "greater", mode = "append") %>%
    # block for cases 
    tab_stat_cases(label = "cases") %>% 
    tab_last_add_sig_labels() %>%
    # block for percent statistic
    tab_stat_cpct(label = "%") %>% # percent
    tab_last_add_sig_labels() %>%
    tab_last_sig_cpct() %>%
    tab_pivot(stat_position = "inside_columns") %>% 
    # converts NA to zero
    recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)

 ### here we build table
 my_banner %>%
    tab_cells(cyl, gear) %>%
    my_custom_table()

这篇关于带有expss包的复杂表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆