簡體   English   中英

比較 expss 表中的兩個變量(數字或兩個因子)

[英]Compare two variables (both numeric or both factors) in expss tables

I am digging deeper and deeper into the expss package, and face one of the examples mentioned here --> https://gdemin.github.io/expss/#example_of_data_processing_with_multiple-response_variables (more particularly the last table of the section.

考慮以下數據框:

vecA <- factor(c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10)),levels=c(1,2,3,4,5))
vecB <- factor(c(rep(1,20),rep(2,20),rep(NA,10)),levels=c(1,2,3,4,5))
df_fact <- data.frame(vecA, vecB)

vecA_num <- as.numeric(c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10)))
vecB_num <- as.numeric(c(rep(1,20),rep(2,20),rep(NA,10)))
df_num <- data.frame(vecA, vecB)

嚴格復制建議的代碼(上面的 URL),這是我的表格的樣子:

df_fact %>%
  tab_cols(total(label = "#Total| |")) %>% 
  tab_cells(list(vecA)) %>%
  tab_stat_cpct(label="vecA", total_row_position="above", total_statistic="u_cases") %>%
  tab_cells(list(vecB)) %>% 
  tab_stat_cpct(label="vecB", total_row_position="above", total_statistic="u_cases") %>%
  tab_pivot(stat_position = "inside_columns") %>%  
  recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy)

與數字示例略有不同的過程:

df_num %>%
  tab_cols(total(label = "#Total| |")) %>% 
  tab_cells(vecA_num, vecB_num) %>%
  tab_stat_valid_n(label = "Valid N") %>%
  tab_stat_mean(label="Mean") %>%
  tab_pivot(stat_position = "inside_columns") %>%  
  recode(as.criterion(is.numeric) & is.na ~ 0, TRUE ~ copy) %>%
  tab_transpose()

問題從這里開始,因為這些復雜的結構是……復雜的!

1)我想包括 tab_last_sig* 系列函數,但我不知道如何去做(當變量是因素時,可能還有小計/網)

2) 包括多個統計數據(案例、百分比、平均值……)是一個挑戰

3)最后,我不清楚我應該在哪里寫統計名稱/變量名稱

我還沒有找到這些構造的詳細文檔,因此這個消息在一個瓶子里:)

  1. 很遺憾,但目前僅支持獨立樣本的顯着性檢驗。 在您的示例中,您希望比較相關樣本的統計信息。 您可以對獨立比例進行顯着性計算,但結果將不准確。
  2. 包含多個統計信息並不困難 - 您只需按順序寫入tab_stat_ 但復雜的表格布局確實是一個挑戰:(
  3. statistic 的變量名總是應該寫在tab_cells中。 之后,您可以使用tab_stat_meantab_stat_cpct等編寫統計函數。您可以通過在 R 控制台中打印?tab_pivot來查找文檔。 這是獲取 R 功能手冊的標准方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM