# Comparing complex proportions between groups

I have a set of data where cells were collected from a number of subjects and phenotypically categorized (sample data below). I'm interested in asking how sets of antigen-specific cells change in phenotype between groups of subjects (i.e. healthy vs. affected). Separately, I'd also like to look at how phenotypes change between antigen-specific sets.

subject phenotype_category  Ag1_count_in_pheno  Ag2_count_in_pheno  total_cell_count_in_pheno   subject_group
1a_015  3   4   3   4352    affected
1a_015  6   2   2   2429    affected
1a_015  4   0   0   1688    affected
1a_015  7   1   6   2296    affected
1a_015  1   2   10  6041    affected
1a_015  2   2   18  2910    affected
1a_015  8   0   3   352 affected
1a_015  5   3   7   9487    affected
1a_016  3   0   5   7286    healthy
1a_016  6   1   2   10771   healthy
1a_016  4   0   0   4062    healthy
1a_016  7   2   13  8306    healthy
1a_016  1   7   40  11679   healthy
1a_016  2   3   13  4406    healthy
1a_016  8   0   0   0   healthy
1a_016  5   7   26  36925   healthy
1a_017  3   2   6   6360    affected
1a_017  6   0   0   0   affected
1a_017  4   0   2   3065    affected
1a_017  7   4   1   2069    affected
1a_017  1   1   26  3832    affected
1a_017  2   3   33  1443    affected
1a_017  8   0   0   659 affected
1a_017  5   3   14  14812   affected


This might be a red herring, but each subject in our study had a varying number of total cells (10k - 100k) collected and a varying number of cells belonging to the antigen-specific subset (0 - 100) collected. The number of antigen-specific cells sampled is partially, but not entirely, reliant upon the number of total cells sampled. The distribution of total or antigen-specific cells in each nominal phenotypic category isn't particularly stable from subject to subject, and I am tempted to discount the phenotypic distribution of poorly-sampled antigen-specific cells.

I assume that I need to use a method that is suitable for count proportions, since I'll likely be looking at a proportion of cells in each category. I also assume that Chi-square independence tests aren't ideal, since (i) I would like to preserve the granularity of the data at a per-subject level rather than lumping everything into a summary statistic and (ii) I'm unsure whether to or how to account for the variation in total # of cells here.

What's the best way to approach the data in R? Some type of logistic regression seems like it should work. Is it reasonable to ignore the variation in total cell phenotypes (or run these cells in a separate model for comparison)?

I've had some luck mutating the data, subsetting to show one phenotype at a time, and applying a logistic model, as below.

subject phenotype   Ag1_in_pheno    total_Ag1   cells_in_pheno  total_cells group
1a_015  1   2   14  6041    29555   affected
1a_016  1   7   20  11679   83435   healthy
1a_017  1   1   13  3832    32240   affected

glm(cbind(Ag1_in_pheno,total_Ag1-Ag1_in_pheno)~group,
family=binomial(logit),
data=cell_counting)

glm(cbind(Ag1_in_pheno,total_Ag1-Ag1_in_pheno)~group+cells_in_pheno/total_cells,
family=binomial(logit),
data=cell_counting)


Should I run each phenotype separately like this, or is there a more appropriate way to run all phenotypes together, since the cell distribution in each is dependent upon the cell distribution in the others?

Thanks very much!