1
1
# # Create AICc tables for PERMANOVA output.
2
+
2
3
require(vegan )
3
4
require(tibble )
5
+ require(stringr )
6
+
4
7
5
8
# # -- For two variables: ------------------------------------
6
9
@@ -178,7 +181,7 @@ AICc.table.all <- function(sig.vars, control.var.char = NULL, matrix.char, perm
178
181
for (i in 1 : length(extra.var.char )) {
179
182
temp <- AICc.table.Nvar(sig.vars = extra.var.char [i ], control.var.char = control.var.char ,
180
183
matrix.char = matrix.char , n.var = 1 , composite = TRUE ,
181
- type = type , method = method )
184
+ type = type , method = method , perm = perm )
182
185
183
186
varcomb.all <- rbind(varcomb.all , temp )
184
187
@@ -191,15 +194,63 @@ AICc.table.all <- function(sig.vars, control.var.char = NULL, matrix.char, perm
191
194
varcomb.all $ `Relative Likelihood` <- exp((min(varcomb.all $ AICc.values ) -
192
195
varcomb.all $ AICc.values )/ 2 )
193
196
194
-
197
+ # exp( -0.5 * ∆AIC score for that model)
195
198
196
199
return (varcomb.all )
197
200
198
201
}
199
202
200
203
204
+ # # -- Sum of AIC Weights by Var: ---------------------------------------------------
205
+
206
+ # This requires an AIC/AICc table output from one of the above functions. The
207
+ # rationalle behind this approach can be found in Arnold, T. W. (2010).
208
+ # Uninformative parameters and model selection using Akaike's Information
209
+ # Criterion. The Journal of Wildlife Management, 74(6), 1175-1178.
210
+
211
+ # Calculation method from http://brianomeara.info/tutorials/aic
212
+
213
+
214
+ AICc.weights.byvar <- function (sig.vars , AIC.table.output ){
215
+
216
+ results.table <- tibble(" Significant Variable" = sig.vars ,
217
+ " Summed AIC Weight" = rep(0 ))
218
+
219
+ for (i in 1 : length(sig.vars )){
220
+
221
+ summed.weight = 0
222
+
223
+ for (j in 1 : nrow(AIC.table.output )){
224
+
225
+ if (grepl(AIC.table.output $ variables [j ], pattern = sig.vars [i ], fixed = TRUE )) {
226
+
227
+ summed.weight <- summed.weight + AIC.table.output $ `Relative Likelihood` [j ]
228
+
229
+ } else summed.weight <- summed.weight
230
+
231
+
232
+ }
233
+ # sig vars loop
234
+
235
+ results.table [i , 2 ] <- summed.weight
236
+
237
+ }
238
+ # function loop
239
+
240
+ return (results.table )
241
+ }
242
+
201
243
202
244
245
+ # create a table with sig vars fed into the table + AIC weight sum column
246
+ #
247
+ # for each significant variable,
248
+ # for each row
249
+ # check each row to see if there is a pattern match
250
+ # add the relative likelihood to sum if so
251
+ #
252
+ # report
253
+
203
254
204
255
205
256
0 commit comments