11# # Create AICc tables for PERMANOVA output.
2+
23require(vegan )
34require(tibble )
5+ require(stringr )
6+
47
58# # -- For two variables: ------------------------------------
69
@@ -178,7 +181,7 @@ AICc.table.all <- function(sig.vars, control.var.char = NULL, matrix.char, perm
178181 for (i in 1 : length(extra.var.char )) {
179182 temp <- AICc.table.Nvar(sig.vars = extra.var.char [i ], control.var.char = control.var.char ,
180183 matrix.char = matrix.char , n.var = 1 , composite = TRUE ,
181- type = type , method = method )
184+ type = type , method = method , perm = perm )
182185
183186 varcomb.all <- rbind(varcomb.all , temp )
184187
@@ -191,15 +194,63 @@ AICc.table.all <- function(sig.vars, control.var.char = NULL, matrix.char, perm
191194 varcomb.all $ `Relative Likelihood` <- exp((min(varcomb.all $ AICc.values ) -
192195 varcomb.all $ AICc.values )/ 2 )
193196
194-
197+ # exp( -0.5 * ∆AIC score for that model)
195198
196199 return (varcomb.all )
197200
198201}
199202
200203
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+
201243
202244
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+
203254
204255
205256
0 commit comments