Principal Component Analysis (PCA) seems great to reduce the number of variables, but is it also good to reduce the number of observations?

Here is an example: reflectance measurements were taken from the same plant at a given time. Measurements were taken from different wavelengths. There are missing values in the data because something doesn't look right in 20 reflectance measurements. Missing values were omitted.

  my.data<-data.frame(wavelength=351:1350, reflectance=c(runif(980), rep(NA,20))) # There are missing values in my data
    # summary(my.data)
    # plot(my.data)
  save.pca<-prcomp(!is.na(my.data$reflectance), center = TRUE, scale. = TRUE)

The ultimate idea is transforming the reflectance data from thousands of wavelengths into one or few PCs. Then, someone could use it as a response variable: PCA1 ~ treatment.

  big.data<-data.frame(plant=rep(c(1:4),2), date=c(1,1,1,1,2,2,2,2),
                      treatment=rep(c("A","B"),4)) # There are missing values in my data
  big.data[,c(paste("wave", 351:1350, sep=""))]<-c(c(runif(980), rep(NA,20)), rep(runif(1000),7))
    # summary(big.data[,1:4])
    # plot(big.data[,3:7])

  pca.function<- function(x){ prcomp(!is.na(x), center = TRUE, scale. = TRUE) }
  apply(big.data[,c(paste("wave", 351:1350, sep=""))], 1, pca.function)

The idea is having a data frame like:

      plant date treatment PCA1
      1    1         A   y1
      2    1         B   y2
      3    1         A   y3
      4    1         B   y4
      1    2         A   y5
      2    2         B   y6
      3    2         A   y7
      4    2         B   y8


fm <- lme(PCA1 ~ treatment, data=big.data, random = ~ 1|  Plant, method="ML")

Can PCA be used for something like that? Is there any better approach to reduce the number of observations?

  • 1
    $\begingroup$ If you have 20 measures of the same plant, in a fairly real sense you have 20 variables not 1. But why not just use all the measures in a mixed effects model? I'm not sure what's gained here. $\endgroup$ Commented Jan 18, 2016 at 20:02
  • $\begingroup$ @gung I would suggest that for such 'signal processing' data which is (I assume smooth, and therefore correlated) pca will pick the 'signal' and throw away the independent noise in each wavelength $\endgroup$
    – seanv507
    Commented Jan 18, 2016 at 20:37
  • $\begingroup$ It looks like you have around 1000 variables per plant/timepoint/condition. So what you want to do is to reduce the number of "variables", and I am not sure why you call it "observations". Also, each measured spectrum is one observation, so for many plants and treatments you have many observations. Does this describe your situation correctly? $\endgroup$
    – amoeba
    Commented Jan 18, 2016 at 21:57

2 Answers 2


If I understand correctly, the system your describing is actually a single observation (i.e. spectrum) with the amplitude at each wavelength a variable. Thus, you have just a single observation with ~1000 variables!

Typically, spectroscopic analysis uses the amplitude (in your case reflectance) of certain parts of the spectrum to predict some quantity. What you need to do however is "teach" the algorithm what the spectrum looks like when you vary your target variable.

For example, assume you were using the spectrum to understand the water content of the plant. The first thing you would want to do is amass a spectra set of the plant's reflectance when the plant has various levels of water concentration. Once you had this spectra set, you could then use PCA to find the proper wavelengths that predict the water content, effectively reducing your variables.

  • $\begingroup$ These are good points so +1, but note that (i) the question suggests that the OP wants to use "reduced spectrum" as dependent variables (i.e. to model how it depends on the treatment) and not as independent variables as in the example you describe; and (ii) as there are probably many plants in the dataset, there are probably many observations with ~1000 variables (many measured spectra), not only one. $\endgroup$
    – amoeba
    Commented Jan 18, 2016 at 21:50
  • $\begingroup$ If I misunderstood I apologize, but it sounded like the author was confusing a variable for an observation. I'm not sure what is gained spectroscopically if each wavelength is an observation. What would you be predicting in this case? In fact what is the independent variable? To your second point, I have no idea how much data they have and was just making a purely academic example. $\endgroup$ Commented Jan 18, 2016 at 21:59
  • $\begingroup$ In my understanding of the question, independent variable is "treatment" (e.g. if a plant is fertilized or not or something like that) and dependent variables (~1000 of them) are given by the reflectance spectrum. $\endgroup$
    – amoeba
    Commented Jan 18, 2016 at 22:10
  • $\begingroup$ Ah I see. Yes I suppose you could look at it that way as well. I guess it's all a matter of what you are measuring and what you are predicting. $\endgroup$ Commented Jan 18, 2016 at 22:34

I don't completely understand your question, but I'll take a stab at some parts.

  1. Can PCA scores be used as response variables against a categorical independent variable (treatment in your case)? Absolutely, that's very common.

  2. Can PCA scores be used as the response variable in different types of linear models? Yes, that's very common too. It's usually called principal components regression.

  3. I don't understand what you mean by "reducing the number of observations". Nothing else you discuss seems to deal with that.

I would add that for further investigation, it sounds like you are dealing with the area of chemometrics (even if you are coming from a biology point of view). There is a package called chemometrics that can do some of what you seem to be considering.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.