通过变量将Dunnett检验的P值提取到表中

通过变量将Dunnett检验的P值提取到表中

本文介绍了通过变量将Dunnett检验的P值提取到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由Dunnett测试按组(4个级别)测试的25列的列表.我能够使用sapply函数使Dunnett按组用于所有列,并且在将p值拉入表时遇到了一些麻烦.下面是使用虹膜数据集的示例.

I have a list of 25 columns that I am testing to by group (4 levels) through a Dunnett test. I was able to use the sapply function to get the Dunnett to work for all the columns by group and am having some trouble pulling the p-values into a table. Below is an example of what I am trying to do using the iris dataset.

iris <- iris

iris$group <- ifelse(iris$Species =='setosa', 1,
               ifelse(iris$Species =='versicolor', 2,
               ifelse(iris$Species =='virginica', 3,
               0)))

iris$group <- as.factor(iris$group)
summary(glht(aov(Sepal.Length ~ group, iris), linfct=mcp(group="Dunnett" )))
test

iris$Species

dunnet_model_iris <- sapply(iris[-c(5,6)], function(y, f) summary(glht(aov(y ~ f, iris), linfct=mcp(f="Dunnett"))), f = iris$Species)

names(dunnet_model_iris[[10]]$pvalues)

p_value <- dunnet_model[[10]]$pvalues
p_value

我能够通过dunnet_model [[10]] $ pvalues获得每一列的p值(每列相隔10行(例如:第二列将是dunnet_model [[20]] $ pvalues)总的来说,我的数据集有25列,所以我会从10-250列中拉出.我想创建一个像这样的表:

I am able to get the p-values for each column through dunnet_model[[10]]$pvalues (with each column being 10 rows apart (for example: the second column would be dunnet_model[[20]]$pvalues). In total, my data set has 25 columns so I would pull from 10-250. I would like to create a table like this:

                2-1       3-1
Sepal.Length  1.44E-15  2.22E-16
Sepal.Width   1.44E-15  2.22E-16
Petal.Length  1.44E-15  2.22E-16

问题:如何将每一列的所有Dunnett比较P值提取到一个表中?

我在寻找答案时遇到了一些麻烦.如果有人有什么建议,将不胜感激.我不希望有任何代码,只是一些想法可以帮助我了解情况.

I am having some trouble searching for the answer. If anyone has some suggestions that would be greatly appreciated. I am not expecting any code, just some ideas to help shine some light on my situation.

推荐答案

在使用lapply

library(multcomp)
dunnet_model_iris <- lapply(iris[-c(5,6)], function(y, f)
      summary(glht(aov(y ~ f, iris), linfct=mcp(f="Dunnett"))), f = iris$Species)
t(sapply(dunnet_model_iris, function(x) x$test$pvalues))
#                      [,1]         [,2]
#Sepal.Length  1.443290e-15 2.220446e-16
#Sepal.Width   5.551115e-16 9.074667e-10
#Petal.Length  1.110223e-16 2.220446e-16
#Petal.Width  -2.220446e-16 1.110223e-16


或使用OP创建'dunnet_model_iris'的方法


Or using the OP's method of creating the 'dunnet_model_iris'

t(sapply(dunnet_model_iris["test",], `[[`, "pvalues"))

这篇关于通过变量将Dunnett检验的P值提取到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:57