3
3
# # adjusting pseudo-F values. Also calculates multivariate dispersion for
4
4
# # categorical variables.
5
5
6
+ require(vegan )
7
+ require(tibble )
8
+
6
9
# First, a quick function to calculate omega squared based on:
7
10
# https://academic.oup.com/bioinformatics/article/31/15/2461/188732
8
11
# http://www.real-statistics.com/multiple-regression/other-measures-effect-size-anova/
@@ -42,7 +45,7 @@ PERMANOVA.omega2 <- function(adonis2.object, num.control.vars) {
42
45
# # by.adonsi2 is to pass through for the by = argument in adonis2
43
46
44
47
45
- group.PERMANOVA <- function (var.names , var.table , var.table.c , control.vars = " " , species.table , species.table.c , num.control.vars = 0 , by.adonis2 = " terms" , perms = 99999 , method = " bray" ) {
48
+ group.PERMANOVA <- function (var.names , var.table , var.table.c , control.vars = " " , species.table , species.table.c , num.control.vars = 0 , by.adonis2 = " terms" , AIC.type = " AICc " , perms = 99999 , method = " bray" ) {
46
49
47
50
# # need to order columns otherwise the order of the columns and the order of col.numbers is incorrect.
48
51
@@ -51,14 +54,16 @@ group.PERMANOVA <- function(var.names, var.table, var.table.c, control.vars = ""
51
54
52
55
53
56
54
- output <- data.frame ( row .names = var.names ,
57
+ output <- tibble( var .names = var.names ,
55
58
var.explnd = rep(NA , times = length(var.names )),
56
59
avg.var.explnd = rep(NA ),
57
60
pseudo.F = rep(NA ),
58
61
F .pval = rep(NA ),
59
62
adj.F.pval = rep(NA ),
60
63
disp.F.pval = rep(NA ),
61
- adj.disp.F.pval = rep(NA )
64
+ adj.disp.F.pval = rep(NA ),
65
+ omega2 = rep(NA ),
66
+ AIC.stat = rep(NA )
62
67
)
63
68
col.numbers <- which(colnames(var.table ) %in% var.names )
64
69
@@ -93,7 +98,8 @@ group.PERMANOVA <- function(var.names, var.table, var.table.c, control.vars = ""
93
98
output $ omega2 [i ] <- PERMANOVA.omega2(temp , num.control.vars )
94
99
output $ pseudo.F [i ] <- temp $ F [num.control.vars + 1 ]
95
100
output $ F .pval [i ] <- temp $ `Pr(>F)` [num.control.vars + 1 ]
96
-
101
+ output $ AIC.stat [i ] <- AICc.PERMANOVA2(temp )[[AIC.type ]]
102
+
97
103
98
104
99
105
# the ordering is so that col.names[i] works!
@@ -128,6 +134,8 @@ group.PERMANOVA <- function(var.names, var.table, var.table.c, control.vars = ""
128
134
p.adjust(p = output $ F .pval , method = " holm" )
129
135
output $ adj.disp.F.pval <-
130
136
p.adjust(p = output $ disp.F.pval , method = " holm" )
137
+ output $ AIC.delta <-
138
+ output $ AIC.stat - min(output $ AIC.stat )
131
139
132
140
return (output )
133
141
@@ -136,7 +144,7 @@ return(output)
136
144
}
137
145
138
146
139
- group.univ.PERMANOVA <- function (var.names , var.table , var.table.c , control.vars = " " , species.vector , species.vector.c , num.control.vars = 0 , by.adonis2 = " terms" , perms = 99999 , method = " euclid" ) {
147
+ group.univ.PERMANOVA <- function (var.names , var.table , var.table.c , control.vars = " " , species.vector , species.vector.c , num.control.vars = 0 , by.adonis2 = " terms" , perms = 99999 , method = " euclid" , AIC.type = " AICc " ) {
140
148
141
149
# # need to order columns otherwise the order of the columns and the order of col.numbers is incorrect.
142
150
@@ -145,13 +153,14 @@ group.univ.PERMANOVA <- function(var.names, var.table, var.table.c, control.vars
145
153
146
154
147
155
148
- output <- data.frame ( row .names = var.names ,
156
+ output <- tibble( var .names = var.names ,
149
157
var.explnd = rep(NA , times = length(var.names )),
150
158
avg.var.explnd = rep(NA ),
151
159
pseudo.F = rep(NA ),
152
160
F .pval = rep(NA ),
153
161
adj.F.pval = rep(NA ),
154
- AICc = rep(NA )
162
+ omega2 = rep(NA ),
163
+ AIC.stat = rep(NA )
155
164
)
156
165
col.numbers <- which(colnames(var.table ) %in% var.names )
157
166
@@ -188,7 +197,7 @@ group.univ.PERMANOVA <- function(var.names, var.table, var.table.c, control.vars
188
197
output $ omega2 [i ] <- PERMANOVA.omega2(temp , num.control.vars )
189
198
output $ pseudo.F [i ] <- temp $ F [num.control.vars + 1 ]
190
199
output $ F .pval [i ] <- temp $ `Pr(>F)` [num.control.vars + 1 ]
191
- output $ AICc [i ] <- AICc.PERMANOVA2(temp )[3 ]
200
+ output $ AIC.stat [i ] <- AICc.PERMANOVA2(temp )[[ AIC.type ] ]
192
201
193
202
194
203
@@ -198,6 +207,8 @@ group.univ.PERMANOVA <- function(var.names, var.table, var.table.c, control.vars
198
207
}
199
208
200
209
output $ adj.F.pval <- p.adjust(p = output $ F .pval , method = " holm" )
210
+ output $ delta.aic <- output $ AIC.stat - min(output $ AIC.stat )
211
+
201
212
202
213
return (output )
203
214
0 commit comments