# PCA with nested/hierarchical data

I have data collected on trees. The nature of the study was hierarchical - we took data on 5 leaves per branch, two branches per tree, and whole tree measurements as well. There were a number of measurements conducted at each level of that hierarchy. So, let's say for example we have leaf area and nitrogen for each leaf, wood density for each branch, and crown size for each tree. (This is a gross simplification, but hope it will serve for the discussion).

Thus, if we think of a data frame or spreadsheet of data with one row for each observation of the lowest level (leaf in this case), some data will be repeated. For example, branch wood density will be repeated for each leaf associated with that branch, while leaf area and nitrogen will vary within that branch. And so on.

The question is: what are the implications of running a PCA on data when some data are being repeated across rows?

If this is not "legit", I can aggregate data up to the highest level (tree in this case), taking means of lower-level data. But if there's a way to avoid throwing away variation like this, I'd prefer to keep it in there.

Thanks for any thoughts!

a quick illustration of example data:

treenum branchnum leafnum crown wood area n
1       1         1       .5    .2   .8   1.2
1       1         2       .5    .2   .6   0.7
1       2         1       .5    .4   .6   0.2
1       2         2       .5    .4   .2   0.6
2       1         1       .8    .5   .2   0.1
2       1         2       .8    .5   .4   0.5
2       2         1       .8    .9   .3   0.7
2       2         2       .8    .9   .5   0.1

• There are PCA-like methods for hierarchical data that may be of interest to you. For instance, Hierarchical Multiple Factor Analysis (HMFA) could be helpful – Riff May 15 '17 at 12:40

Why do you want to do PCA?

PCA is for dimensionality reduction and getting rid of linear correlation among features.

So if you have a lot of repeated data PCA will mistakenly think two features are linearly correlated and share information.

Using your example, if you have only one tree and two branches, but say 90% of your measurements are from brachnum 1 and the rest are branchum 2, any linear correlation test will tell you that treenum has a 90% correlation to branchnum, although this correlation doesn't make sense.

In your example data set you have 50% from branch 1 and 50% from branch 2, but still this number doesn't make sense.

So basically PCA will probably not be a good idea, but it really depends on the task.

Perhaps you can elaborate, as I mentioned, on what is the goal of the PCA.

• Thanks user... The "num" columns are for reference only - they're not included in the PCA analysis. Only the last 4 columns would be included. I'm interested in PCA to understand the underlying dimensionality of our data - we have many more measurements than those listed here. Given that, my thinking is that, if there is indeed an underlying relationship between branch wood density ("wood") and leaf nitrogen ("n") say, that correlation would bear out in the PCA analysis. Perhaps an implication is that the true variability of higher levels (branch, tree, etc) would be underrepresented... – Alexander Shenkin Sep 21 '16 at 16:21
• I see. So I think if you want to see the underlying dimensionality and to use PCA then you should not have repeating data. If you want to check the relationship between wood density and leaf nitrogen then you should have multiple rows that contain the same measurement of both wood and leaf nitrogen. Repeating data will definitely affect the output of the PCA, so basically you need to either not have it, or if you decide you only care about analyzing a subset of the features, make sure there is no repeating data for those features. – user3494047 Sep 23 '16 at 7:35
• Thanks user. I accept that the repeating data will affect the PCA. While I may go ahead and take means for lower level data in the end, I'd like to explore how the repeating data may affect the PCA first. Each leaf with its N measurement does, in the end, come from that branch with that wood density. There would be no problem regressing N vs wood density, for example. But this isn't regression. So, does repeating data result in fewer PCA axes explaining more variation in the data than it should? The more I think about it, the less sure I am there's a problem, but my mind is open... – Alexander Shenkin Sep 23 '16 at 13:03
• By the way, came across this discussion that might point a way forward, if straight PCA on nested data is really uncool. stats.stackexchange.com/questions/53414/… – Alexander Shenkin Sep 23 '16 at 13:15
• Regarding your comment of will the PCA find fewer axes explaining more variation than they should- I am not sure. On the one hand repeated data reduces variation, on the other hand there will be increased linear correlation. I am not sure what would happen, and I think the best thing to do is try it if it isnt too difficult, but what I am worried will happen is that it will not be necessarily true that it will find fewer axes that explain more variation than they should, but it will get rid of some axes and attribute less variation than it should to those. – user3494047 Sep 23 '16 at 17:19