1

I know this might be a pretty simple automatic iterative question.

I am running a PLS regression by using geomorph.

This function requires two 3D arrays inside it (A1 and A2), as can be seen in the documentation in the previous link.

Basically the function would be:

two.b.pls(A1, A2, iter = 999)

The point is that I am having 8 different 3D matrix arrays and want to run the PLS analysis for any possible combination.

More explicitly, if my arrays are named Group_1, Group_2... Group_8, what I need is to iteratively analyse these combinations:

two.b.pls(Group_1, Group_2, iter = 999)
two.b.pls(Group 1, Group 3, iter = 999)
...
two.b.pls(Group_7, Group_8, iter = 999)
antecessor
  • 2,688
  • 6
  • 29
  • 61

1 Answers1

1

If we have object names in a vector, use combn to return the pairwise combinations, get the values and pass them into two.b.pls function

nm1 <- c('Frontal', 'Face', 'Parietal_L', 'Parietal_R', 'Temporal_L', 'Temporal_R', 'Occipital', 'Sphenoid')
out <- combn(nm1, 2, FUN = function(x)
     two.b.pls(get(x[1]), get(x[2]), iter = 999), simplify = FALSE)

If we want to get the combination name, an option is to name the list elements with combn output of the vector

names(out) <- combn(nm1, 2, FUN = paste, collapse="_")
akrun
  • 874,273
  • 37
  • 540
  • 662
  • Thanks @akrun, however you are right, the names are different and not `Group_x`. They are all named differently. How can I proceed then? They are named `c(Frontal, Face, Parietal_L, Parietal_R, Temporal_L, Temporal_R, Occipital, Sphenoid)` – antecessor Sep 15 '21 at 21:15
  • @antecessor then get the names of that object in a vector and use that in combn i.e. `nm1 <- c("a1", "group1", "hello", "away"); combn(nm1, 2, FUN = ...` – akrun Sep 15 '21 at 21:17
  • I tried this: `out <- combn(c(Frontal, Face, Parietal_L, Parietal_R, Temporal_L, Temporal_R, Occipital, Sphenoid), 2, FUN = function(x) two.b.pls(get(x[1]), get(x[2]), iter = 999), simplify = FALSE)` with no success. – antecessor Sep 15 '21 at 21:17
  • 1
    That's perfect. I forgot the quotation marks! – antecessor Sep 15 '21 at 21:20
  • Extra question @akrun. When I see the `out` output I cannot see which is the combitation employed in each iteration. How could I proceed? – antecessor Sep 15 '21 at 21:22
  • @antecessor you can named it with the combn of the object names as in the updated post – akrun Sep 15 '21 at 21:24
  • @antecessor have you tried this step `names(out) <- combn(nm1, 2, FUN = paste, collapse="_")` then the `out` will have names instead of unnamed list – akrun Sep 15 '21 at 21:31
  • SOmetimes the html won't update if it is not refreshed – akrun Sep 15 '21 at 21:32