R/expss 专家您好!这是对此问题的后续问题-> 带有 expss 包的复杂表。
我使用出色的 expss 包将小计添加到已经很复杂的表中,它适用于大多数任务(计数、比例、平均值......)。然而,我发现统计测试评估在一个没有小计的表和完全相同的小计之间存在差异。@Gregory Demin,您的知识将不胜感激:)
一个例子来说明我的话,使用数据集包中可用的推断数据集:
example <- infert %>%
tab_significance_options(sig_level=0.2, keep="none", sig_labels=NULL, subtable_marks="greater", mode="append") %>%
tab_cols(total(), education) %>%
tab_cells(parity) %>%
# block for cases
tab_stat_cases(label="N", total_row_position="above", total_statistic="u_cases", total_label="TOTAL") %>%
tab_last_add_sig_labels() %>%
# block for percent statistic - Subtable tests
tab_stat_cpct(label="%Col.", total_row_position="above", total_statistic="u_cpct", total_label="TOTAL") %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(label="T.1", compare_type="subtable") %>%
# block for percent statistic - First column tests
tab_stat_cpct(label="T.2", total_row_position="above", total_statistic="u_cpct", total_label="TOTAL") %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(compare_type="first_column", mode="replace") %>%
tab_pivot(stat_position="inside_columns") %>%
# converts NA to zero
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
example <- example[,-c(4,5)]
print(example)
注意: sig_level 非常高(20%)来说明这个具体问题,不要惊慌 :) 这是起点,我很好。然后我们只添加小计(第 5 行):
example2 <- infert %>%
tab_significance_options(sig_level=0.2, keep="none", sig_labels=NULL, subtable_marks="greater", mode="append") %>%
tab_cols(total(), education) %>%
tab_cells(parity) %>%
tab_subtotal_cells("#FIRST 3"=c(1,2,3),"#LAST 3"=c(4,5,6), position = "above") %>%
# block for cases
tab_stat_cases(label="N", total_row_position="above", total_statistic="u_cases", total_label="TOTAL") %>%
tab_last_add_sig_labels() %>%
# block for percent statistic - Subtable tests
tab_stat_cpct(label="%Col.", total_row_position="above", total_statistic="u_cpct", total_label="TOTAL") %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(label="T.1", compare_type="subtable") %>%
# block for percent statistic - First column tests
tab_stat_cpct(label="T.2", total_row_position="above", total_statistic="u_cpct", total_label="TOTAL") %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(compare_type="first_column", mode="replace") %>%
tab_pivot(stat_position="inside_columns") %>%
# converts NA to zero
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
example2 <- example2[,-c(4,5)]
print(example2)
我不知道发生了什么,但是这次显着性检验的结果不一样。此外,我觉得没有对两个小计行计算显着性检验。有什么见解吗?