【问题标题】:Run a series of post-hoc t-tests ANOVAs in R在 R 中运行一系列事后 t 检验方差分析
【发布时间】:2021-09-13 10:04:51
【问题描述】:

我运行了一系列方差分析,检查组成员资格与一系列因变量之间的联系,生成的数据框包含每个方差分析模型的结果(一行 = 一个方差分析模型)。我现在想根据我生成的因变量-自变量组合列表运行一系列事后测试,这些组合在多重比较校正中幸存下来。我尝试编写一个函数,将这些 DV-IV 组合中的每一个提交到 pairwise.t.test,尽管我的代码目前没有按预期工作。请在下面查看这段代码的摘录和模拟数据:

# simulated data
df = data.frame(ID = c(1001, 1002, 1003, 1004, 1005, 1006,1007, 1008, 1009,   1010, 1011),
                    Group = as.numeric(c('0','1','2','0','2','1','0','2','0','1','0')),
                    testscore_1 = as.numeric(c('23','28','30','15','7','18','29','27','14','22','24')),
                    testscore_2 = as.numeric(c('1','3','2','5','8','2','5','6','7','8','2')),
                    testscore_3 = as.numeric(c('18','20','19','15','20','23','19','25','10','14','12')))

# df containing combination of IV and DV that survived multiple comparison correction 
df_results = data.frame(Independent_variable = c("Group", "Group"), Dependent_variable=c("testscore_1", "testscore_2"))

dvs_ivs <- paste0("x = df$", df_results$Group, "g = df$", df_results$Dependent_variable)

posthoc_t_test_results <- lapply(dvs_ivs, function(x) {
    pairwise.t.test(print.noquote(x), p.adjust.method = "none")
})

Error message :  Error in factor(g) : argument "g" is missing, with no default "

有什么建议吗?

【问题讨论】:

    标签: r anova m t-test posthoc


    【解决方案1】:

    您可以尝试使用Map -

    Map(function(x, y) pairwise.t.test(df[[x]], df[[y]], p.adjust.method = "none"),
      df_results$Dependent_variable, df_results$Independent_variable)
    
    #$testscore_1
    
    #   Pairwise comparisons using t tests with pooled SD 
    
    #data:  df[[x]] and df[[y]] 
    
    #     0    1   
    #1 0.79 -   
    #2 0.96 0.85
    
    #P value adjustment method: none 
    
    #$testscore_2
    #
    #   Pairwise comparisons using t tests with pooled SD 
    
    #data:  df[[x]] and df[[y]] 
    
    #     0    1   
    #1 0.88 -   
    #2 0.53 0.67
    
    #P value adjustment method: none 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      相关资源
      最近更新 更多