使用文本而不是带标签的数字作为输入时,如何在自定义表中显示出显着差异? (在每个单元格中应为+或–)。
#Generate data
aw = function(n) {
sample(x = c("Aware","Consider","Buy"), n, replace = T, prob = c(0.1, 0.4, 0.5))
}
awa<-aw(3000)
gen = function(n) {
sample(x = c("Male","Female"), n, replace = T, prob = c(0.8, 0.2))
}
gende<-gen(3000)
ag = function(n) {
sample(x = c("<20","20 to 50","50+"), n, replace = T, prob = c(0.3, 0.2, 0.5))
}
age<-ag(3000)
data<-data.frame(awa,gende,age)
#Banner create
banner = calc(data, list(total(), gende,age))
#Custom table with significant differences calculated relative to total
data %>%
tab_significance_options(compare_type = "adjusted_first_column",subtable_marks = "both",sig_labels_first_column = c("-", "+"),mode = c("append")) %>%
tab_cells(awa) %>%
tab_cols(banner) %>%
tab_stat_cpct() %>%
tab_pivot()
答案 0 :(得分:0)
有一个函数tab_last_sig_cpct
,用于计算最后一次统计的重要性。统计信息应为列百分比。
library(expss)
#Generate data
aw = function(n) {
sample(x = c("Aware","Consider","Buy"), n, replace = T, prob = c(0.1, 0.4, 0.5))
}
awa<-aw(3000)
gen = function(n) {
sample(x = c("Male","Female"), n, replace = T, prob = c(0.8, 0.2))
}
gende<-gen(3000)
ag = function(n) {
sample(x = c("<20","20 to 50","50+"), n, replace = T, prob = c(0.3, 0.2, 0.5))
}
age<-ag(3000)
data<-data.frame(awa,gende,age)
#Banner create
banner = calc(data, list(total(), gende,age))
#Custom table with significant differences calculated relative to total
data %>%
tab_significance_options(compare_type = "adjusted_first_column",subtable_marks = "both",sig_labels_first_column = c("-", "+"),mode = c("append")) %>%
tab_cells(awa) %>%
tab_cols(banner) %>%
tab_stat_cpct() %>%
tab_last_sig_cpct(mode = "replace") %>%
tab_pivot()
# | | | #Total | Female | Male | <20 | 20 to 50 | 50+ |
# | --- | ------------ | ------ | ------ | ------ | ------ | -------- | ---- |
# | awa | Aware | 10.0 | 7.0 - | 10.8 + | 9.5 | 10.3 | 10.2 |
# | | Buy | 51.1 | 53.8 | 50.4 | 48.6 | 51.4 | 52.5 |
# | | Consider | 38.8 | 39.1 | 38.8 | 41.9 + | 38.3 | 37.3 |
# | | #Total cases | 3000 | 611 | 2389 | 884 | 601 | 1515 |