整洁的多个方差分析
Tidy multiple anovas
我整理了数据,照样做了。
在我的办公室电脑上工作,不在我的家用电脑上工作。现在我得到:
Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
is.atomic(x) is not TRUE
In addition: Warning messages:
1: Data frame tidiers are deprecated and will be removed in an upcoming release of broom.
2: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
3: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
4: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion
代码:
res = Raw.data %>% group_by(Gene) %>%
do(Model = aov(log2(FC) ~ Treatment, data=.))
tidy(res, Model)
问题出在 tidy(res, Model)
上,因为我使用 summary(res[[2]][[1]])
等
得到了很好的统计数据
我真的很喜欢 tidy 在办公室工作时给我输出的方式。
数据:
Number Treatment Gene FC
1 2 Control mTOR 1.28999546
2 3 Control mTOR 1.62429990
3 4 Control mTOR 1.31081235
4 10 Control mTOR 0.65558902
5 14 Control mTOR 0.49470104
6 18 Control mTOR 1.12261436
7 6 Treatment mTOR 1.34369529
8 7 Treatment mTOR 0.58483880
9 8 Treatment mTOR 0.51403301
10 9 Treatment mTOR 1.47711406
11 11 Treatment mTOR 2.05220846
12 12 Treatment mTOR 0.20960123
13 13 Treatment mTOR 1.11679544
14 15 Treatment mTOR 1.35787956
15 16 Treatment mTOR 0.74617363
16 17 Treatment mTOR 1.68791400
17 20 Treatment mTOR 2.04683987
18 21 Treatment mTOR 0.21358785
19 22 Treatment mTOR 0.98309230
20 24 Treatment mTOR 0.65445858
21 25 Treatment mTOR 0.77690342
22 26 Treatment mTOR 0.35951121
23 2 Control Raptor 0.82422904
24 3 Control Raptor 1.29085590
25 4 Control Raptor 0.55457309
26 10 Control Raptor 1.36949046
27 14 Control Raptor 0.90613140
28 18 Control Raptor 1.36573152
29 6 Treatment Raptor 0.40208821
30 7 Treatment Raptor 1.42850190
31 8 Treatment Raptor 0.47058962
32 9 Treatment Raptor 1.53576947
33 11 Treatment Raptor 2.08432767
34 12 Treatment Raptor 0.28285010
35 13 Treatment Raptor 1.28948941
36 15 Treatment Raptor 1.55241563
37 16 Treatment Raptor 1.03140971
38 17 Treatment Raptor 1.16624466
39 20 Treatment Raptor 0.25957711
40 21 Treatment Raptor 1.93043388
41 22 Treatment Raptor 2.71472997
42 24 Treatment Raptor 0.71381887
43 25 Treatment Raptor 1.47245399
44 26 Treatment Raptor 0.51014311
45 2 Control Rictor 0.76958681
46 3 Control Rictor 0.96147713
47 4 Control Rictor 0.89860880
48 10 Control Rictor 3.12117681
49 14 Control Rictor 0.32683138
50 18 Control Rictor 1.47431619
51 6 Treatment Rictor 0.02552013
52 7 Treatment Rictor 6.09665587
53 8 Treatment Rictor 1.00468371
54 9 Treatment Rictor 0.36000695
55 11 Treatment Rictor 1.54380977
56 12 Treatment Rictor 2.00068407
57 13 Treatment Rictor 0.40089656
58 15 Treatment Rictor 0.60702662
59 16 Treatment Rictor 1.06833716
60 17 Treatment Rictor 0.20441144
61 20 Treatment Rictor 1.18198006
62 21 Treatment Rictor 0.78789596
63 22 Treatment Rictor 0.04089405
64 24 Treatment Rictor 0.93654515
65 25 Treatment Rictor 0.80949506
66 26 Treatment Rictor 0.45670381
67 2 Control mLST8 1.12922200
68 3 Control mLST8 0.63262968
69 4 Control mLST8 0.68963219
70 10 Control mLST8 1.89325536
71 14 Control mLST8 0.95387898
72 18 Control mLST8 1.12396065
73 6 Treatment mLST8 0.25950270
74 7 Treatment mLST8 2.03655754
75 8 Treatment mLST8 0.87489857
76 9 Treatment mLST8 0.51938390
77 11 Treatment mLST8 0.31708484
78 12 Treatment mLST8 0.28315297
79 13 Treatment mLST8 0.35406819
80 15 Treatment mLST8 0.47686481
81 16 Treatment mLST8 0.24946641
82 17 Treatment mLST8 0.31349415
83 20 Treatment mLST8 0.46643244
84 21 Treatment mLST8 0.56343498
85 22 Treatment mLST8 0.40902527
86 24 Treatment mLST8 0.53124407
87 25 Treatment mLST8 1.23766868
88 26 Treatment mLST8 1.16274782
如有任何帮助,我们将不胜感激!
家用电脑和工作电脑的区别可能与 dplyr
and/or broom
?
的版本有关
尝试在嵌套数据的每一行上使用 nest_by
(dplyr
版本 1.0.0)和 运行 而不是 group_by
。使用 nest_by
将创建一个新的临时列表列 data
。它类似于以前使用 nest
和 rowwise
。该模型也需要在 list
中。
library(dplyr)
library(broom)
Raw.data %>%
nest_by(Gene) %>%
mutate(Model = list(aov(log2(FC) ~ Treatment, data = data))) %>%
summarise(tidy(Model))
这应该允许您 运行 aov
分别针对不同的基因并给出相似的输出。
输出
Gene term df sumsq meansq statistic p.value
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 mLST8 Treatment 1 4.03 4.03 6.02 0.0235
2 mLST8 Residuals 20 13.4 0.670 NA NA
3 mTOR Treatment 1 0.376 0.376 0.403 0.533
4 mTOR Residuals 20 18.7 0.934 NA NA
5 Raptor Treatment 1 0.0253 0.0253 0.0279 0.869
6 Raptor Residuals 20 18.1 0.906 NA NA
7 Rictor Treatment 1 2.88 2.88 0.902 0.354
8 Rictor Residuals 20 63.9 3.20 NA NA
我整理了数据,照样做了
在我的办公室电脑上工作,不在我的家用电脑上工作。现在我得到:
Error in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
is.atomic(x) is not TRUE
In addition: Warning messages:
1: Data frame tidiers are deprecated and will be removed in an upcoming release of broom.
2: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
3: In mean.default(X[[i]], ...) :
argument is not numeric or logical: returning NA
4: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion
代码:
res = Raw.data %>% group_by(Gene) %>%
do(Model = aov(log2(FC) ~ Treatment, data=.))
tidy(res, Model)
问题出在 tidy(res, Model)
上,因为我使用 summary(res[[2]][[1]])
等
我真的很喜欢 tidy 在办公室工作时给我输出的方式。
数据:
Number Treatment Gene FC
1 2 Control mTOR 1.28999546
2 3 Control mTOR 1.62429990
3 4 Control mTOR 1.31081235
4 10 Control mTOR 0.65558902
5 14 Control mTOR 0.49470104
6 18 Control mTOR 1.12261436
7 6 Treatment mTOR 1.34369529
8 7 Treatment mTOR 0.58483880
9 8 Treatment mTOR 0.51403301
10 9 Treatment mTOR 1.47711406
11 11 Treatment mTOR 2.05220846
12 12 Treatment mTOR 0.20960123
13 13 Treatment mTOR 1.11679544
14 15 Treatment mTOR 1.35787956
15 16 Treatment mTOR 0.74617363
16 17 Treatment mTOR 1.68791400
17 20 Treatment mTOR 2.04683987
18 21 Treatment mTOR 0.21358785
19 22 Treatment mTOR 0.98309230
20 24 Treatment mTOR 0.65445858
21 25 Treatment mTOR 0.77690342
22 26 Treatment mTOR 0.35951121
23 2 Control Raptor 0.82422904
24 3 Control Raptor 1.29085590
25 4 Control Raptor 0.55457309
26 10 Control Raptor 1.36949046
27 14 Control Raptor 0.90613140
28 18 Control Raptor 1.36573152
29 6 Treatment Raptor 0.40208821
30 7 Treatment Raptor 1.42850190
31 8 Treatment Raptor 0.47058962
32 9 Treatment Raptor 1.53576947
33 11 Treatment Raptor 2.08432767
34 12 Treatment Raptor 0.28285010
35 13 Treatment Raptor 1.28948941
36 15 Treatment Raptor 1.55241563
37 16 Treatment Raptor 1.03140971
38 17 Treatment Raptor 1.16624466
39 20 Treatment Raptor 0.25957711
40 21 Treatment Raptor 1.93043388
41 22 Treatment Raptor 2.71472997
42 24 Treatment Raptor 0.71381887
43 25 Treatment Raptor 1.47245399
44 26 Treatment Raptor 0.51014311
45 2 Control Rictor 0.76958681
46 3 Control Rictor 0.96147713
47 4 Control Rictor 0.89860880
48 10 Control Rictor 3.12117681
49 14 Control Rictor 0.32683138
50 18 Control Rictor 1.47431619
51 6 Treatment Rictor 0.02552013
52 7 Treatment Rictor 6.09665587
53 8 Treatment Rictor 1.00468371
54 9 Treatment Rictor 0.36000695
55 11 Treatment Rictor 1.54380977
56 12 Treatment Rictor 2.00068407
57 13 Treatment Rictor 0.40089656
58 15 Treatment Rictor 0.60702662
59 16 Treatment Rictor 1.06833716
60 17 Treatment Rictor 0.20441144
61 20 Treatment Rictor 1.18198006
62 21 Treatment Rictor 0.78789596
63 22 Treatment Rictor 0.04089405
64 24 Treatment Rictor 0.93654515
65 25 Treatment Rictor 0.80949506
66 26 Treatment Rictor 0.45670381
67 2 Control mLST8 1.12922200
68 3 Control mLST8 0.63262968
69 4 Control mLST8 0.68963219
70 10 Control mLST8 1.89325536
71 14 Control mLST8 0.95387898
72 18 Control mLST8 1.12396065
73 6 Treatment mLST8 0.25950270
74 7 Treatment mLST8 2.03655754
75 8 Treatment mLST8 0.87489857
76 9 Treatment mLST8 0.51938390
77 11 Treatment mLST8 0.31708484
78 12 Treatment mLST8 0.28315297
79 13 Treatment mLST8 0.35406819
80 15 Treatment mLST8 0.47686481
81 16 Treatment mLST8 0.24946641
82 17 Treatment mLST8 0.31349415
83 20 Treatment mLST8 0.46643244
84 21 Treatment mLST8 0.56343498
85 22 Treatment mLST8 0.40902527
86 24 Treatment mLST8 0.53124407
87 25 Treatment mLST8 1.23766868
88 26 Treatment mLST8 1.16274782
如有任何帮助,我们将不胜感激!
家用电脑和工作电脑的区别可能与 dplyr
and/or broom
?
尝试在嵌套数据的每一行上使用 nest_by
(dplyr
版本 1.0.0)和 运行 而不是 group_by
。使用 nest_by
将创建一个新的临时列表列 data
。它类似于以前使用 nest
和 rowwise
。该模型也需要在 list
中。
library(dplyr)
library(broom)
Raw.data %>%
nest_by(Gene) %>%
mutate(Model = list(aov(log2(FC) ~ Treatment, data = data))) %>%
summarise(tidy(Model))
这应该允许您 运行 aov
分别针对不同的基因并给出相似的输出。
输出
Gene term df sumsq meansq statistic p.value
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 mLST8 Treatment 1 4.03 4.03 6.02 0.0235
2 mLST8 Residuals 20 13.4 0.670 NA NA
3 mTOR Treatment 1 0.376 0.376 0.403 0.533
4 mTOR Residuals 20 18.7 0.934 NA NA
5 Raptor Treatment 1 0.0253 0.0253 0.0279 0.869
6 Raptor Residuals 20 18.1 0.906 NA NA
7 Rictor Treatment 1 2.88 2.88 0.902 0.354
8 Rictor Residuals 20 63.9 3.20 NA NA