小计对 expss 表中显着性检验的影响
Influence of subtotals on significance tests in expss tables
R/expss 专家您好!这是这个问题的后续问题 -->
.
我使用出色的 expss 包将小计添加到已经很复杂的 tables 中,它适用于大多数任务(计数、比例、均值...)。然而,我发现统计测试评估在没有小计的 table 和完全相同的小计之间存在差异。
@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)
不知道怎么回事,这次显着性检验的结果不一样。此外,我觉得在两个小计行上没有计算显着性检验。
有什么见解吗?
对于百分比之间的显着性检验,我们需要总统计量中的个案。所以我们将用两行进行总统计。在所有具有总个案的操作行之后将被删除。
significance_cpct
使用 #
符号检测总行数。 #
在小计中导致不正确的结果。
考虑到以上所有因素:
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
# note additional total statistic
tab_stat_cpct(label="%Col.", total_row_position="above", total_statistic= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "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= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "TOTAL")) %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(compare_type="first_column", mode="replace") %>%
tab_pivot(stat_position="inside_columns") %>%
# drop row with TO_DELETE
where(!grepl("TO DELETE", row_labels)) %>%
# converts NA to zero
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
example2 <- example2[,-c(4,5)]
print(example2)
更新 net
列:
data(infert)
example2 <- infert %>%
apply_labels(
education = "Education"
) %>%
tab_significance_options(sig_level=0.2, keep="none", sig_labels=NULL, subtable_marks="greater", mode="append") %>%
tab_cols(total(), net(education, "LESS THAN 12 Y.O."=levels(education)[1:2])) %>%
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
# note additional total statistic
tab_stat_cpct(label="%Col.", total_row_position="above", total_statistic= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "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= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "TOTAL")) %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(compare_type="first_column", mode="replace") %>%
tab_pivot(stat_position="inside_columns") %>%
# drop row with TO_DELETE
where(!grepl("TO DELETE", row_labels)) %>%
# converts NA to zero
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
example2 <- example2[,-c(4,5)]
print(example2)
R/expss 专家您好!这是这个问题的后续问题 -->
我使用出色的 expss 包将小计添加到已经很复杂的 tables 中,它适用于大多数任务(计数、比例、均值...)。然而,我发现统计测试评估在没有小计的 table 和完全相同的小计之间存在差异。 @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)
不知道怎么回事,这次显着性检验的结果不一样。此外,我觉得在两个小计行上没有计算显着性检验。 有什么见解吗?
对于百分比之间的显着性检验,我们需要总统计量中的个案。所以我们将用两行进行总统计。在所有具有总个案的操作行之后将被删除。
significance_cpct
使用 #
符号检测总行数。 #
在小计中导致不正确的结果。
考虑到以上所有因素:
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
# note additional total statistic
tab_stat_cpct(label="%Col.", total_row_position="above", total_statistic= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "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= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "TOTAL")) %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(compare_type="first_column", mode="replace") %>%
tab_pivot(stat_position="inside_columns") %>%
# drop row with TO_DELETE
where(!grepl("TO DELETE", row_labels)) %>%
# converts NA to zero
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
example2 <- example2[,-c(4,5)]
print(example2)
更新 net
列:
data(infert)
example2 <- infert %>%
apply_labels(
education = "Education"
) %>%
tab_significance_options(sig_level=0.2, keep="none", sig_labels=NULL, subtable_marks="greater", mode="append") %>%
tab_cols(total(), net(education, "LESS THAN 12 Y.O."=levels(education)[1:2])) %>%
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
# note additional total statistic
tab_stat_cpct(label="%Col.", total_row_position="above", total_statistic= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "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= c("u_cases", "u_cpct"),
total_label=c("TO DELETE", "TOTAL")) %>%
tab_last_add_sig_labels() %>%
tab_last_sig_cpct(compare_type="first_column", mode="replace") %>%
tab_pivot(stat_position="inside_columns") %>%
# drop row with TO_DELETE
where(!grepl("TO DELETE", row_labels)) %>%
# converts NA to zero
recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)
example2 <- example2[,-c(4,5)]
print(example2)