DirichReg {DirichletReg}R Documentation

Fitting a Dirichlet Regression


This function allows for fitting Dirichlet regression models using two different parametrizations.


DirichReg(formula, data, model = c("common", "alternative"),
          subset, sub.comp, base, weights, control, verbosity = 0)



the model formula (for different specifications see “Details”)


a data.frame containing independent and dependent variables


specifies whether the "common" (\alpha\mathrm{s}) or "alternative" (\mu/\phi) parametrization is employed (see “Details”)


estimates the model for a subset of the data


analyze a subcomposition by selecting specific components (see “Details”)


redefine the base variable


frequency weights


a list containing control parameters used for the optimization


prints information about the function's progress, see Details


Formula Specification and Models

formula determines the used predictors. The responses must be prepared by DR_data and can be optionally stored in the object containing all covariates which is then specified as the argument data. (Although “on-the-fly” processing of DR_data in a formula works, it is only intended for testing purposes and may be removed at any time – use at your own risk.)

There are two different parametrization (controlled by the argument model, see below):

As the two models offer different modeling strategies, the specification of their formulae differ:

Formulae for the “Common” Model

The simplest possible model here is to include only an intercept for all components. If DV is the ‘dependent variable’ (i.e., compositional data) with three components, we can request this null-model by DV ~ 1. We always have at least two dependent variables, so simple formulae as the one given above will be expanded to DV ~ 1 | 1 | 1, because DV hast three components. Likewise, it is possible to specify a common set of predictors for all components, as in DV ~ p1 * p2, where p1 and p2 are predictors.

If the covariates of the components shall differ, one has to set up a complete formula for each subcomposition, using | as separators between the components, for example, DV ~ p1 | p1 + p2 | p1 * p2 will lead to a model where the first response in DV will be modeled using p1, the second will be predicted by p1 + p2 and the third by p1 * p2. Note that if you use the latter approach, the predictors have to be stated explicitly for all response variables.

Formulae for the “Alternative” Model

The simplest possible model here is to include an intercept for all components (except the base) and an intercept for precision. This can be achieved by DV ~ 1, which is expanded to DV ~ 1 | 1. The part modeling the ‘mean’ (first element on the right-hand side) is mandatory, if no specification for precision is included, an intercept will be added. Note that you need to set model = "alternative" to use this parametrization!

The alternative parametrization consists of two parts: modeled expected values (\mu) and their ‘precision’ (\phi). As in multinomial logistic regression, one response variable is omitted (by default the first, but this can be changed by the base argument in DR_data or DirichReg) and for the rest a set of predictors is used with a multinomial logit-link. For precisions, a different set of predictors can be set up using a log-link.

DV ~ p1 * p2 | p1 + p2 will set up a model where the expected values are predicted by p1 * p2 and precision are modeled using p1 + p2.

Data Preparation

The data argument accepts a data.frame that must include the dependent variable as a named element (see examples how to do this).

Changing the Base Component and Analyzing Subcompositions

The base-component (i.e., omitted component) is initially set during the stage of data preparation DR_data, but can easily be changed using the argument base which takes integer values from 1 to the maximum number of components.

If a data set contains a large number of components, of which only a few are relevant, the latter can be ‘sorted out’ and the irrelevant (i.e., not selected) components will be aggregated into a single variable (row sums) that automatically becomes the base category for the model, unless specified otherwise by base. The positioning of variables will necessarily change: the aggregated variable takes the first column and the others are appended in their order of selection.

Subsets and Weights

Using subset, the model can be fitted only to a part of the data, for more information about this functionality, see subset.
Note that, unlike in glm, weights are not treated as prior weights, but as frequency weights!

Optimization and Verbosity

Using the control argument, the settings passed to the optimizers can be altered. This argument takes a named list. To supply user-defined starting values, use control = list(sv=c(...)) and supply a vector containing initial values for all parameters. Optimizer-specific options include the number of iterations (iterlim = 1000) and convergence criteria for the BFGS- and NR-optimization ((tol1 = 1e-5) and (tol2 = 1e-10)).

Verbosity takes integer values from 0 to 4. 0, no information is printed (default). 1 prints information about 3 stages (preparation, starting values, estimation). 2 prints little information about optimization (verbosity values greater than one are passed to print.default = verbosity - 1 of maxBFGS and maxNR). 3 prints more information about optimization. 4 prints all information about optimization.



[language] function call


[character] used parametrization


[character] components' names


[numeric] vector with the number of parameters per set of predictors


[numeric] number of components


[numeric] used components


[numeric list] sets of predictors


[numeric list] sets of predictors (only for the alternative parametrization)


[numeric] vector of single components


[numeric] base (only for the alternative parametrization)


[numeric] vector of frequency weights


[DirichletRegData] the original response


[data.frame] original data


[data.frame] used data


[Formula] expanded formula


[language] expression for generating the model frame


[numeric] number of parameters


[numeric] named vector of parameters


[character] names of the parameters


[list of matrices] list containing alpha's, mu's, phi's for the observations


[numeric] the log-likelihood


[matrix] covariance-matrix of parameter estimates


[matrix] (observed) Hessian


[numeric] vector of standard errors


[list] contains details about the optimization process provided by maxBFGS and maxNR


Marco J. Maier


ALake <- ArcticLake
ALake$Y <- DR_data(ALake[,1:3])

# fit a quadratic Dirichlet regression models ("common")
res1 <- DirichReg(Y ~ depth + I(depth^2), ALake)

# fit a Dirichlet regression with quadratic predictor for the mean and
# a linear predictor for precision ("alternative")
res2 <- DirichReg(Y ~ depth + I(depth^2) | depth, ALake, model="alternative")

# test both models
anova(res1, res2)


[Package DirichletReg version 0.7-1 Index]