I have a dataset containing multiple proportions that add up to 1. I am interested in the change of these proportions along a gradient (see below for example data).

gradient <- 1:99
A1 <- gradient * 0.005
A2 <- gradient * 0.004
A3 <- 1 - (A1 + A2)

df <- data.frame(gradient = gradient,
                 A1 = A1,
                 A2 = A2,
                 A3 = A3)

dfm <- melt(df, id = "gradient")
ggplot(dfm, aes(x = gradient, y = value, fill = variable)) +

enter image description here

Additional information: It need not be necessarily linear, I did this just for easiness of the example. The original counts from which these proportions are calculated are also available. The real dataset contains more variable adding up to 1 (e.g. B1, B2 & B3, C1 to C4, etc) - so a hint for a multivariate solution is would be also helpful... But for now I'll stick on the univariate side of statistics.

Question: How can one analyze such kind of data? I've read a little bit around, and perhaps a multinomial model or a glm is suited? - If I run 3 (or 2) glms, how can I incorporate the constraint that the predicted values sum up to 1? I don't want to only plot such kind of data, I also want to do a deeper regression like analysis. I preferably want to use R - how can I do this in R?

  • $\begingroup$ The command proprcspline in Stata might be what you're looking for (I know you want to use R, but maybe this could be a starting point): proprcspline computes a restricted cubic spline smooth of proportions of observations in each category of yvar given xvar, and graphs them as a stacked area plot. Optionally, these smoothed proportions can be adjusted for a set of control variables (cvars). $\endgroup$ – boscovich Mar 6 '12 at 13:02
  • $\begingroup$ Could you elaborate on what "interested in" means? Do you merely want to plot the proportions against gradient? Or do you have a deeper analysis in mind? If so, what is its nature--what precisely do you hope to learn from these data? Also, do you have the original counts available (which would be good) or only the proportions? Could you say a little more about what these data consist of and how they are collected? $\endgroup$ – whuber Mar 12 '12 at 21:39
  • 1
    $\begingroup$ @whuber: I want to do a deeper analysis with this data. My hypothesis is the proportions will change with the gradient. The counts are also available. $\endgroup$ – EDi Mar 12 '12 at 22:21
  • 1
    $\begingroup$ Sounds like you have compositional data. I don't know a lot about it, but Aitchison's work is the place to start. There's a package, compositions, on CRAN. $\endgroup$ – Aaron - Reinstate Monica Mar 13 '12 at 2:40

In one dimension, this sounds like a job for beta regression (with or without variable dispersion). This is a regression model with beta-distributed dependent variable, naturally 0-1 constrained. An R package is betareg and a paper describing its use is here.
For more than two proportions the usual extension of the Beta distribution leads to Dirichlet regression. An R package DirichletReg is available, described e.g. here.

There are some reasons not to use logit links and multinomial logistic regression for true compositional data, mostly to do with what strong assumptions they imply for the variance. However, if your data are all actually normalised counts (abundances?), those assumptions may be correct and Peter's suggestion would probably be the way to go.

  • $\begingroup$ Thank you for the links, i'll have a look at them. DirichletReg looks promising! For example Slide 3 of your link: "If the ‘probability’ of answering in a certain cateogory is spread across the choices, a Dirichlet approach is more informative." . Because i did not know how to do this with mlogit, because the choices need not to be unique. Also a good way of graphical respresentation - haven't thought about that... $\endgroup$ – EDi Mar 8 '12 at 14:42
  • $\begingroup$ For graphics you might find the R functions splineplot and cdplot helpful. Indeed if you just wanted the fitted lines and didn't need a lot of regression machinery then you could probably coax cdplot into giving you the relevant curves (it's only density underneath) $\endgroup$ – conjugateprior Mar 8 '12 at 21:27
  • $\begingroup$ Sorry, I meant to type spineplot above, obviously. $\endgroup$ – conjugateprior Mar 9 '12 at 13:29
  • $\begingroup$ Note that the DirichletReg package is now available on CRAN, and a vignette has been published. $\endgroup$ – jbaums Feb 27 '15 at 6:45

I am not sure exactly what you are trying to find out, but what about a multinomial logistic regression with gradient as the independent variable?

In R, one way to do this is the mlogit function in the mlogit library. See this vignette


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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