andersonwinkler / PermCCA

Permutation inference for Canonical Correlation Analysis
GNU General Public License v3.0
21 stars 6 forks source link

Error when using Z and Pset at the same time #5

Closed cyctbdbw closed 2 years ago

cyctbdbw commented 2 years ago

Dear Dr. Winkler,

Thank you for providing this wonderful and very useful code. But when I use it and add both Z and Pset at the same time, it shows error message

For this code: [pfwer,r,A,B,U,V] = permcca(Y,X,nP,Z,W,Sel,partial,Pset) Specifically, I have Y (1094 3 matrix), X (1094 11), nP = 1000, Z (1094 2; I'd like to use it for both sides), and Pset (1094 10000).

If I only use either Z or Pset, it works, but it can't work if I use both Z and Pset, i.e., [pfwer,r,A,B,U,V] = permcca(Y,X,nP,Z,[],[],[],Pset).

Error message: Index in position 1 exceeds array bounds (must not exceed 1092). Error in permcca (line 154) [~,~,rperm] = cca(Qz U(idxY,k:end),Qw V(idxX,k:end),R,S);

It also can't work if I changed to [pfwer,r,A,B,U,V] = permcca(Y,X,nP,Z,Z,[],[],Pset).

But it works if I use [pfwer,r,A,B,U,V] = permcca(Y,X,nP,[],Z,[],[],Pset).

Could you guild me how to use partial CCA with Pset? Thank you very much.

Best regards, Yu-Chi

andersonwinkler commented 2 years ago

Hi Yu-Chi,

Is there a reason why you must use Pset (as opposed to letting the algorithm permute all randomly)?

Recall from the paper the two methods for putting the data in a lower dimensional space: one is the Huh-Jhun, the other is Theil. Huh-Jhun is the easiest, but cannot be used with block permutation. Theil is more complicated in that it requires a selection matrix, but has the advantage that it can be used with exchangeability blocks.

So, if you really need Pset (because you have to permute in a particular way) you have to use Theil. To enable Theil, you have to provide the "Sel" variable (the 6th argument).

Hope this helps!

All the best,

Anderson

cyctbdbw commented 2 years ago

Hi Anderson,

Thank you for your reply. We use the HCP s1200 dataset for our study, so I think Pset should be unavoidable. Would you have any suggestions regarding how to generate the selection matrix? Is it just deleting some rows (by random?) from the Pset? It seems we can only permute fewer subjects if we use Theil, but I am confused about how to decide which subjects not to permute? Thank you again.

Best regards, Yu-Chi

andersonwinkler commented 2 years ago

Hi Yu-Chi,

You can delete participants randomly before generating Pset. However, to avoid needlessly reducing power, it is best to remove subjects that contribute little to the testing, such as those that are seldom (if ever) permuted. In the HCP case, you'd drop sibships that have unusual structure (e.g., half-sibs, or large sibships that are unique in the sample).

To find out who these subjects are, PALM offers a tool that draws the permutation tree, so it can be inspected visually. Please have a look in this link: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PALM/ExchangeabilityBlocks#Visualisation_of_the_block_structure

Once you have identified these subjects/sibships, you can provide the "Sel" argument as a matrix, or as a vector of indices or logicals.

Hope this helps!

All the best,

Anderson

cyctbdbw commented 2 years ago

Hi Anderson,

I understand. Thank you very much for your detailed explanation and suggestions.

Best regards, Yu-Chi