How to understand the formula：patient score = ∑PC1A−∑PC1B? Today I read a paper (doi: 10.1016/j.omtn.2020.08.030), in this paper, they used many methods and finally they got a matrix, and each row represents a gene, each column represents a patient sample. The genes were split into two groups, called gene set A and gene set B. Then they used the PCA(Principal component analysis) to give each patient a score, and the formula is as followed: patient score = ∑PC1A−∑PC1B, the PC1A represents the first component of gene set A, and PC1B represents the first component of gene set B. So how can I understand this formula, and if I also have a matrix like this, how to get the score using R language? You can find the article in

First, unsupervised clustering was employed to categorize the patients in TCGA as per the DEG [differentially expressed gene] values. Furthermore, DEG values that were positively and negatively correlated with the clusters signature were termed as the ICI gene signatures A and B, respectively. Furthermore, the Boruta algorithm was employed for the dimension reduction of the ICI gene signatures A and B, and principal component 1 was extracted as the signature score by employing the PCA. Lastly, we applied a method similar to Gene expression grade index to define the ICI score of each patient:

$$\text{ICI score} = \sum \text{PC1}_A -\sum \text{PC1}_B $$
The above describes how they get the score using PCA, but it's hard for me to understand.
 A: As far as I can tell, the ICI score is computed by subsetting the data to Gene Set A features, performing PCA, and using the PC1 values as PC1A. They then do the same with Gene Set B, and use the PC1 value of that decomposition as PC1B. The sample-wise difference of these scores is the ICI score per sample. In R, it would look something like this:
pca_a = prcomp(t(data[geneSetA,]))
pc1_a = pca_a$x[,1]

pca_b = prcomp(t(data[geneSetB,]))
pc1_b = pca_b$x[,1]

iciScore = pc1_a - pc1_b

I can't wrap my head around the sum notation, as I understand PC1A and PC1B to be single numbers that summarize sample-level expression of Gene Sets A and B. It makes no sense to sum PC1A and PC1B values across the cohort, since the ICI score is a sample-level value, and PC values typically sum to zero (or if not, some arbitrary value) anyway. We're trying to compute the ICI score for each sample, and each sample has exactly one value of PC1A and PC1B - there's nothing to sum at a sample level. The sum notation might make sense if the Gene Set scores were a sum or average over the individual genes' expression levels, but the PCA decomposition already summarizes each gene set as a single number.
A: This is just a complement to @NuclearHoagie's answer. The paper referenced by the OP in turn references the Gene  Expression  Grade  Index from Sotiriou C et 2006 as the basis for their ICI score. The gene expression index is (apologies about pasting a screenshot):

With ICI score the authors apply something similar to GGI to only one "gene" in each set, that "gene" being the first PC, so the summation is redundant in such case.
