diff --git a/404.html b/404.html index b4fd8e3..dfb3d9d 100644 --- a/404.html +++ b/404.html @@ -5,17 +5,33 @@ -Page not found (404) • mclogit - - - + +Page not found (404) • mclogit + + - - + + + + + + + @@ -31,15 +47,48 @@ - mclogit - 0.9.6 + mclogit + 0.9.8 @@ -86,6 +139,7 @@

Page not found (404)

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/articles/approximations.html b/articles/approximations.html new file mode 100644 index 0000000..e9e0f62 --- /dev/null +++ b/articles/approximations.html @@ -0,0 +1,460 @@ + + + + + + + + +Approximate Inference for Multinomial Logit Models with Random Effects • mclogit + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +
+

The problem +

+

A crucial problem for inference about non-linear models with random +effects is that the likelihood function for such models involves +integrals for which no analytical solution exists.

+

For given values \(\boldsymbol{b}\) +of the random effects the likelihood function of a conditional logit +model (and therefore also of a baseline-logit model) can be written in +the form

+

\[ +\mathcal{L}_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b}) += +\exp\left(\ell_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b})\right) +=\exp +\left( +\ell(\boldsymbol{y}|\boldsymbol{b};\boldsymbol{\alpha}) +-\frac12\ln\det(\boldsymbol{\Sigma}) +-\frac12\boldsymbol{b}'\boldsymbol{\Sigma}^{-1}\boldsymbol{b} +\right) +\]

+

However, this “complete data” likelihood function cannot be used for +inference, because it depends on the unobserved random effects. To +arrive at a likelihood function that depends only on observed data, one +needs to used the following integrated likelihood function:

+

\[ +\mathcal{L}_{\text{obs}}(\boldsymbol{y}) += +\int +\exp\left(\ell_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b})\right) +\partial \boldsymbol{b} += +\int +\exp +\left( +\ell(\boldsymbol{y}|\boldsymbol{b};\boldsymbol{\alpha}) +-\frac12\ln\det(\boldsymbol{\Sigma}) +-\frac12\boldsymbol{b}'\boldsymbol{\Sigma}^{-1}\boldsymbol{b} +\right) +\partial \boldsymbol{b} +\]

+

In general, this integral cannot be “solved”, i.e. eliminated from +the formula by analytic means (it is “analytically untractable”). +Instead, one will compute it either using numeric techniques (e.g. using +numerical quadrature) or approximate it using analytical techniques. +Unless there is only a single level of random effects numerical +quadrature can become computationally be demanding, that is, the +computation of the (log-)likelihood function and its derivatives can +take a lot of time even on modern, state-of-the-art computer hardware. +Yet approximations based on analytical techniques hand may lead to +biased estimates in particular in samples where the number of +observations relative to the number of random offects is small, but at +least they are much easier to compute and sometimes making inference +possible after all.

+

The package “mclogit” supports to kinds of analytical approximations, +the Laplace approximation and what one may call the Solomon-Cox +appoximation. Both approximations are based on a quadratic expansion of +the integrand so that the thus modified integral does have a closed-form +solution, i.e. is analytically tractable.

+
+
+

The Laplace approximation and PQL +

+
+

Laplace approximation +

+

The (first-order) Laplace approximation is based on the quadratic +expansion the logarithm of the integrand, the complete-data +log-likelihood

+

\[ +\ell_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b})\approx +\ell(\boldsymbol{y}|\tilde{\boldsymbol{b}};\boldsymbol{\alpha}) +- +\frac12 +(\boldsymbol{b}-\tilde{\boldsymbol{b}})' +\tilde{\boldsymbol{H}} +(\boldsymbol{b}-\tilde{\boldsymbol{b}}) +-\frac12\ln\det(\boldsymbol{\Sigma}) +-\frac12(\boldsymbol{b}-\tilde{\boldsymbol{b}})'\boldsymbol{\Sigma}^{-1}(\boldsymbol{b}-\tilde{\boldsymbol{b}}) +\]

+

where \(\tilde{\boldsymbol{b}}\) is +the solution to

+

\[ +\frac{\partial\ell_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b})}{\partial\boldsymbol{b}} += 0 +\]

+

and \(\tilde{\boldsymbol{H}}=\boldsymbol{H}(\tilde{\boldsymbol{b}})\) +is the value of the negative Hessian with respect to \(\boldsymbol{b}\)

+

\[ +\boldsymbol{H}(\boldsymbol{b})=-\frac{\partial^2\ell(\boldsymbol{y}|\boldsymbol{b};\boldsymbol{\alpha})}{\partial\boldsymbol{b}\partial\boldsymbol{b}'} +\]

+

for \(\boldsymbol{b}=\tilde{\boldsymbol{b}}\).

+

Since this quadratic expansion—let us call it \(\ell^*_{\text{Lapl}}(\boldsymbol{y},\boldsymbol{b})\)—is +a (multivariate) quadratic function of \(\boldsymbol{b}\), the integral of its +exponential does have a closed-form solution (the relevant formula can +be found in harville:matrix.algebra).

+

For purposes of estimation, the resulting approximate log-likelihood +is more useful:

+

\[ +\ell^*_{\text{Lapl}} += +\ln\int \exp(\ell_{\text{Lapl}}(\boldsymbol{y},\boldsymbol{b})) +\partial\boldsymbol{b} += +\ell(\boldsymbol{y}|\tilde{\boldsymbol{b}};\boldsymbol{\alpha}) +- +\frac12\tilde{\boldsymbol{b}}'\boldsymbol{\Sigma}^{-1}\tilde{\boldsymbol{b}} +- +\frac12\ln\det(\boldsymbol{\Sigma}) +- +\frac12\ln\det\left(\tilde{\boldsymbol{H}}+\boldsymbol{\Sigma}^{-1}\right). +\]

+
+
+

Penalized quasi-likelihood (PQL) +

+

If one disregards the dependence of \(\tilde{\boldsymbol{H}}\) on \(\boldsymbol{\alpha}\) and \(\boldsymbol{b}\), then \(\tilde{\boldsymbol{b}}\) maximizes not only +\(\ell_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b})\) +but also \(\ell^*_{\text{Lapl}}\). This +motivates the following IWLS/Fisher scoring equations for \(\hat{\boldsymbol{\alpha}}\) and \(\tilde{\boldsymbol{b}}\) (see +breslow.clayton:approximate.inference.glmm and this page):

+

\[ +\begin{aligned} +\begin{bmatrix} +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X} & +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{Z} \\ +\boldsymbol{Z}'\boldsymbol{W}\boldsymbol{X} & +\boldsymbol{Z}'\boldsymbol{W}\boldsymbol{Z} + +\boldsymbol{\Sigma}^{-1}\\ +\end{bmatrix} +\begin{bmatrix} +\hat{\boldsymbol{\alpha}}\\ +\tilde{\boldsymbol{b}}\\ +\end{bmatrix} += +\begin{bmatrix} +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{y}^*\\ +\boldsymbol{Z}'\boldsymbol{W}\boldsymbol{y}^* +\end{bmatrix} +\end{aligned} +\]

+

where

+

\[ +\boldsymbol{y}^* = \boldsymbol{X}\boldsymbol{\alpha} + +\boldsymbol{Z}\boldsymbol{b} + +\boldsymbol{W}^{-}(\boldsymbol{y}-\boldsymbol{\pi}) +\]

+

is the IWLS “working dependend variable” with \(\boldsymbol{\alpha}\), \(\boldsymbol{b}\), \(\boldsymbol{W}\), and \(\boldsymbol{\pi}\) computed in an earlier +iteration.

+

Substitutions lead to the equations:

+

\[ +(\boldsymbol{X}\boldsymbol{V}^-\boldsymbol{X})\hat{\boldsymbol{\alpha}} += +\boldsymbol{X}\boldsymbol{V}^-\boldsymbol{y}^* +\]

+

and

+

\[ +(\boldsymbol{Z}'\boldsymbol{W}\boldsymbol{Z} + +\boldsymbol{\Sigma}^{-1})\boldsymbol{b} = +\boldsymbol{Z}'\boldsymbol{W}(\boldsymbol{y}^*-\boldsymbol{X}\boldsymbol{\alpha}) +\]

+

which can be solved to compute \(hat{\boldsymbol{\alpha}}\) and \(\tilde{\boldsymbol{b}}\) (for given \(\boldsymbol{\Sigma}\))

+

Here

+

\[ +\boldsymbol{V} = +\boldsymbol{W}^-+\boldsymbol{Z}\boldsymbol{\Sigma}\boldsymbol{Z}' +\]

+

and

+

\[ +\boldsymbol{V}^- = \boldsymbol{W}- +\boldsymbol{W}\boldsymbol{Z}'\left(\boldsymbol{Z}'\boldsymbol{W}\boldsymbol{Z}+\boldsymbol{\Sigma}^{-1}\right)^{-1}\boldsymbol{Z}\boldsymbol{W} +\]

+

Following breslow.clayton:approximate.inference.glmm the +variance parameters in \(\boldsymbol{Sigma}\) are estimated by +minimizing

+

\[ +q_1 = +\det(\boldsymbol{V})+(\boldsymbol{y}^*-\boldsymbol{X}\boldsymbol{\alpha})\boldsymbol{V}^-(\boldsymbol{y}^*-\boldsymbol{X}\boldsymbol{\alpha}) +\]

+

or the “REML” variant:

+

\[ +q_2 = +\det(\boldsymbol{V})+(\boldsymbol{y}^*-\boldsymbol{X}\boldsymbol{\alpha})\boldsymbol{V}^-(\boldsymbol{y}^*-\boldsymbol{X}\boldsymbol{\alpha})+\det(\boldsymbol{X}'\boldsymbol{V}^{-}\boldsymbol{X}) +\]

+

This motivates the following algorithm, which is strongly inspired by +the glmmPQL() function in Brian Ripley’s R package +MASS:

+
    +
  1. Create some suitable starting values for \(\boldsymbol{\pi}\), \(\boldsymbol{W}\), and \(\boldsymbol{y}^*\) +
  2. +
  3. Construct the “working dependent variable” \(\boldsymbol{y}^*\) +
  4. +
  5. Minimize \(q_1\) (quasi-ML) or +\(q_2\) (quasi-REML) iteratively (inner +loop), to obtain an estimate of \(\boldsymbol{\Sigma}\) +
  6. +
  7. Obtain \(hat{\boldsymbol{\alpha}}\) +and \(\tilde{\boldsymbol{b}}\) based on +the current estimate of \(\boldsymbol{\Sigma}\) +
  8. +
  9. Compute updated \(\boldsymbol{\eta}=\boldsymbol{X}\boldsymbol{\alpha} ++ \boldsymbol{Z}\boldsymbol{b}\), \(\boldsymbol{\pi}\), \(\boldsymbol{W}\).
  10. +
  11. If the change in \(\boldsymbol{\eta}\) is smaller than a given +tolerance criterion stop the algorighm and declare it as converged. +Otherwise go back to step 2 with the updated values of \(\hat{\boldsymbol{\alpha}}\) and \(\tilde{\boldsymbol{b}}\).
  12. +
+

This algorithm is a modification of the IWLS algorithm used to fit conditional +logit models without random effects. Instead of just solving a linear +requatoin in step 3, it estimates a weighted linear mixed-effects model. +In contrast to glmmPQL() it does not use the +lme() function from package nlme for this, +because the weighting matrix \(\boldsymbol{W}\) is non-diagonal. Instead, +\(q_1\) or \(q_2\) are minimized using the function +nlminb from the standard R package “stats”.

+
+
+
+

The Solomon-Cox approximation and MQL +

+
+

The Solomon-Cox approximation +

+

The (first-order) Solomon approximation is based on the quadratic +expansion the integrand

+

\[ +\ell_{\text{cpl}}(\boldsymbol{y},\boldsymbol{b})\approx +\ell(\boldsymbol{y}|\boldsymbol{0};\boldsymbol{\alpha}) ++ +\boldsymbol{g}_0' +\boldsymbol{b} +- +\frac12 +\boldsymbol{b}' +\boldsymbol{H}_0 +\boldsymbol{b} +-\frac12\ln\det(\boldsymbol{\Sigma}) +-\frac12\boldsymbol{b}'\boldsymbol{\Sigma}^{-1}\boldsymbol{b} +\]

+

where \(\boldsymbol{g}\_0=\boldsymbol{g}(\boldsymbol{0})\) +is the gradient of \(\ell(\boldsymbol{y}\|\boldsymbol{b};\boldsymbol{\alpha})\)

+

\[ +\boldsymbol{g}(\boldsymbol{b})=-\frac{\partial\ell(\boldsymbol{y}|\boldsymbol{b};\boldsymbol{\alpha})}{\partial\boldsymbol{b}} +\]

+

at \(\boldsymbol{b}=\boldsymbol{0}\), while +\(\boldsymbol{H}\_0=\boldsymbol{H}(\boldsymbol{0})\) +is the negative Hessian at \(\boldsymbol{b}=\boldsymbol{0}\).

+

Like before, the integral of the exponential this quadratic expansion +(which we refer to as \(\ell_{\text{SC}}(\boldsymbol{y},\boldsymbol{b})\)) +has a closed-form solution, as does its logarithm, which is:

+

\[ +\ln\int \exp(\ell_{\text{SC}}(\boldsymbol{y},\boldsymbol{b})) +\partial\boldsymbol{b} += +\ell(\boldsymbol{y}|\boldsymbol{0};\boldsymbol{\alpha}) +- +\frac12\boldsymbol{g}_0'\left(\boldsymbol{H}_0+\boldsymbol{\Sigma}^{-1}\right)^{-1}\boldsymbol{g}_0 +- +\frac12\ln\det(\boldsymbol{\Sigma}) +- +\frac12\ln\det\left(\boldsymbol{H}_0+\boldsymbol{\Sigma}^{-1}\right). +\]

+
+
+

Marginal quasi-likelhood (MQL) +

+

The resulting estimation technique is very similar to PQL (again, see +breslow.clayton:approximate.inference.glmm for a +discussion). The only difference is the construction of the “working +dependent” variable \(\boldsymbol{y}^*\). With PQL it is +constructed as \[\boldsymbol{y}^* = +\boldsymbol{X}\boldsymbol{\alpha} + \boldsymbol{Z}\boldsymbol{b} + +\boldsymbol{W}^{-}(\boldsymbol{y}-\boldsymbol{pi})\] while the +MQL working dependent variable is just

+

\[ +\boldsymbol{y}^* = \boldsymbol{X}\boldsymbol{\alpha} + +\boldsymbol{W}^{-}(\boldsymbol{y}-\boldsymbol{\pi}) +\]

+

so that the algorithm has the following steps:

+
    +
  1. Create some suitable starting values for \(\boldsymbol{\pi}\), \(\boldsymbol{W}\), and \(\boldsymbol{y}^*\) +
  2. +
  3. Construct the “working dependent variable” \(\boldsymbol{y}^*\) +
  4. +
  5. Minimize \(q_1\) (quasi-ML) or +\(q_2\) (quasi-REML) iteratively (inner +loop), to obtain an estimate of \(\boldsymbol{\Sigma}\) +
  6. +
  7. Obtain \(\hat{\boldsymbol{\alpha}}\) based on the +current estimate of \(\boldsymbol{\Sigma}\) +
  8. +
  9. Compute updated \(\boldsymbol{\eta}=\boldsymbol{X}\boldsymbol{\alpha}\), +\(\boldsymbol{\pi}\), \(\boldsymbol{W}\).
  10. +
  11. If the change in \(\boldsymbol{\eta}\) is smaller than a given +tolerance criterion stop the algorighm and declare it as converged. +Otherwise go back to step 2 with the updated values of \(\hat{\boldsymbol{\alpha}}\).
  12. +
+
+
+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/articles/baseline-and-conditional-logit.html b/articles/baseline-and-conditional-logit.html new file mode 100644 index 0000000..b80970d --- /dev/null +++ b/articles/baseline-and-conditional-logit.html @@ -0,0 +1,219 @@ + + + + + + + + +The relation between baseline logit and conditional logit models • mclogit + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

Baseline-category logit models can be expressed as particular form of +conditional logit models. In a conditional logit model (without random +effects) the probability that individual \(i\) chooses alternative \(j\) from choice set \(\mathcal{S}_i\) is

+

\[ +\pi_{ij} = +\frac{\exp(\eta_{ij})}{\sum_{k\in\mathcal{S}_i}\exp(\eta_{ik})} +\]

+

where

+

\[ +\eta_{ij} = \alpha_1x_{1ij}+\cdots+\alpha_qx_{qij} +\]

+

In a baseline-category logit model, the set of alternatives is the +same for all individuals \(i\) that is +\(\mathcal{S}_i = {1,\ldots,q}\) and +the linear part of the model can be written like:

+

\[ +\eta_{ij} = \beta_{j0}+\beta_{j1}x_{i1}+\cdots+\beta_{jr}x_{ri} +\]

+

where the coefficients in the equation for baseline category \(j\) are all zero, i.e.

+

\[ +\beta_{10} = \cdots = \beta_{1r} = 0 +\]

+

After setting

+

\[ +\begin{aligned} +x_{(g\times(j-1))ij} = d_{gj}, \quad +x_{(g\times(j-1)+h)ij} = d_{gj}x_{hi}, \qquad +\text{with }d_{gj}= +\begin{cases} +0&\text{for } j\neq g\text{ or } j=g\text{ and } j=0\\ +1&\text{for } j=g \text{ and } j\neq0\\ +\end{cases} +\end{aligned} +\]

+

we have for the log-odds:

+

\[ +\begin{aligned} +\begin{aligned} +\ln\frac{\pi_{ij}}{\pi_{i1}} +&=\beta_{j0}+\beta_{ji}x_{1i}+\cdots+\beta_{jr}x_{ri} +\\ +&=\sum_{h}\beta_{jh}x_{hi}=\sum_{g,h}\beta_{jh}d_{gj}x_{hi} +=\sum_{g,h}\alpha_{g\times(j-1)+h}(d_{gj}x_{hi}-d_{g1}x_{hi}) +=\sum_{g,h}\alpha_{g\times(j-1)+h}(x_{(g\times(j-1)+h)ij}-x_{(g\times(j-1)+h)i1})\\ +&=\alpha_{1}(x_{1ij}-x_{1i1})+\cdots+\alpha_{s}(x_{sij}-x_{si1}) +\end{aligned} +\end{aligned} +\]

+

where \(\alpha_1=\beta_{21}\), \(\alpha_2=\beta_{22}\), etc.

+

That is, the baseline-category logit model is translated into a +conditional logit model where the alternative-specific values of the +attribute variables are interaction terms composed of +alternativ-specific dummes and individual-specific values of +characteristics variables.

+

Analogously, the random-effects extension of the baseline-logit model +can be translated into a random-effects conditional logit model where +the random intercepts in the logit equations of the baseline-logit model +are translated into random slopes of category-specific dummy +variables.

+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/articles/baseline-logit.html b/articles/baseline-logit.html new file mode 100644 index 0000000..ce1ee9c --- /dev/null +++ b/articles/baseline-logit.html @@ -0,0 +1,204 @@ + + + + + + + + +Baseline-category logit models • mclogit + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

Multinomial baseline-category logit models are a generalisation of +logistic regression, that allow to model not only binary or dichotomous +responses, but also polychotomous responses. In addition, they allow to +model responses in the form of counts that have a pre-determined sum. +These models are described in agresti:categorical.data.analysis.2002. Estimating +these models is also supported by the function multinom() +in the R package "nnet" MASS. In the package "mclogit", the function to +estimate these models is called mblogit() (see the relevant +manual page), which uses the +infrastructure for estimating conditional logit models, exploiting the +fact that baseline-category logit models can be re-expressed as +condigional logit models.

+

Baseline-category logit models are constructed as follows. Suppose a +categorical dependent variable or response with categories \(j=1,\ldots,q\) is observed for individuals +\(i=1,\ldots,n\). Let \(\pi_{ij}\) denote the probability that the +value of the dependent variable for individual \(i\) is equal to \(j\), then the baseline-category logit model +takes the form:

+

\[ +\begin{aligned} +\pi_{ij} = +\begin{cases} +\dfrac{\exp(\alpha_{j0}+\alpha_{j1}x_{1i}+\cdots+\alpha_{jr}x_{ri})} +{1+\sum_{k>1}\exp(\alpha_{k0}+\alpha_{k1}x_{1i}+\cdots+\alpha_{kr}x_{ri})} +& \text{for } j>1\\[20pt] +\dfrac{1} +{1+\sum_{k>1}\exp(\alpha_{k0}+\alpha_{k1}x_{1i}+\cdots+\alpha_{kr}x_{ri})} +& \text{for } j=1 +\end{cases} +\end{aligned} +\]

+

where the first category (\(j=1\)) +is the baseline category.

+

Equivalently, the model can be expressed in terms of log-odds, +relative to the baseline-category:

+

\[ +\ln\frac{\pi_{ij}}{\pi_{i1}} += +\alpha_{j0}+\alpha_{j1}x_{1i}+\cdots+\alpha_{jr}x_{ri}. +\]

+

Here the relevant parameters of the model are the coefficients \(\alpha_{jk}\) which describe how the values +of independent variables (numbered \(k=1,\ldots,r\)) affect the relative chances +of the response taking a value \(j\) +versus taking the value \(1\). Note +that there is one coefficient for each independent variable and each +response other than the baseline category.

+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/articles/conditional-logit.html b/articles/conditional-logit.html new file mode 100644 index 0000000..26da999 --- /dev/null +++ b/articles/conditional-logit.html @@ -0,0 +1,199 @@ + + + + + + + + +Conditional logit models • mclogit + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

Conditional logit models are motivated by a variety of +considerations, notably as a way to model binary panel data or responses +in case-control-studies. The variant supported by the package “mclogit” +is motivated by the analysis of discrete choices and goes back to mcfadden:conditional.logit. +Here, a series of individuals \(i=1,ldots,n\) is observed to have made a +choice (represented by a number \(j\)) +from a choice set \(\mathcal{S}_i\), +the set of alternatives at the individual’s disposal. Each alternatives +\(j\) in the choice set can be +described by the values \(x_{1ij},\ldots,x_{1ij}\) of \(r\) attribute variables (where the +variables are enumerated as \(i=1,\ldots,r\)). (Note that in contrast to +the baseline-category logit model, these values vary between choice +alternatives.) Conditional logit models then posit that individual \(i\) chooses alternative \(j\) from his or her choice set \(\mathcal{S}_i\) with probability

+

\[ +\pi_{ij} = \frac{\exp(\alpha_1x_{1ij}+\cdots+\alpha_rx_{rij})} + {\sum_{k\in\mathcal{S}_i}\exp(\alpha_1x_{1ik}+\cdots+\alpha_rx_{rik})}. +\]

+

It is worth noting that the conditional logit model does not require +that all individuals face the same choice sets. Only that the +alternatives in the choice sets can be distinguished from one another by +the attribute variables.

+

The similarities and differences of these models to baseline-category +logit model becomes obvious if one looks at the log-odds relative to the +first alternative in the choice set:

+

\[ +\ln\frac{\pi_{ij}}{\pi_{i1}} += +\alpha_{1}(x_{1ij}-x_{1i1})+\cdots+\alpha_{r}(x_{rij}-x_{ri1}). +\]

+

Conditional logit models appear more parsimonious than +baseline-category logit models in so far as they have only one +coefficient for each independent variables.[^1] In the “mclogi" package, +these models can be estimated using the function mclogit() +(see the relevant manual page).

+

My interest in conditional logit models derives from my research into +the influence of parties' political positions on the patterns of voting. +Here, the political positions are the attributes of the alternatives and +the choice sets are the sets of parties that run candidates in a +countries at various points in time. For the application of the +conditional logit models, see my doctoral thesis elff:politische.ideologien.

+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/articles/fitting-mclogit.html b/articles/fitting-mclogit.html new file mode 100644 index 0000000..69160ae --- /dev/null +++ b/articles/fitting-mclogit.html @@ -0,0 +1,331 @@ + + + + + + + + +The IWLS algorithm used to fit conditional logit models • mclogit + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

The package “mclogit” fits conditional logit models using a maximum +likelihood estimator. It does this by maximizing the log-likelihood +function using an iterative weighted least-squares (IWLS) +algorithm, which follows the algorithm used by the +glm.fit() function from the “stats” package of +R.

+

If \(\pi_{ij}\) is the probability +that individual \(i\) chooses +alternative \(j\) from his/her choice +set \(\mathcal{S}_i\), where

+

\[ +\pi_{ij}=\frac{\exp(\eta_{ij})}{\sum_k{\in\mathcal{S}_i}\exp(\eta_{ik})} +\]

+

and if \(y_{ij}\) is the dummy +variable with equals 1 if individual \(i\) chooses alternative \(j\) and equals 0 otherwise, the +log-likelihood function (given that the choices are identically +independent distributed given \(\pi_{ij}\)) can be written as

+

\[ +\ell=\sum_{i,j}y_{ij}\ln\pi_{ij} + =\sum_{i,j}y_{ij}\eta_{ij}-\sum_i\ln\left(\sum_j\exp(\eta_{ij})\right) +\]

+

If the data are aggregated in the terms of counts such that \(n_{ij}\) is the number of individuals with +the same choice set and the same choice probabilities \(\pi_{ij}\) that have chosen alternative +\(j\), the log-likelihood is (given +that the choices are identically independent distributed given \(\pi_{ij}\))

+

\[ +\ell=\sum_{i,j}n_{ij}\ln\pi_{ij} + =\sum_{i,j}n_{ij}\eta_{ij}-\sum_in_{i+}\ln\left(\sum_j\exp(\eta_{ij})\right) +\]

+

where \(n_{i+}=\sum_{j\in\mathcal{S}_i}n_{ij}\).

+

If

+

\[ +\eta_{ij} = +\alpha_1x_{1ij}+\cdots+\alpha_rx_{rij}=\boldsymbol{x}_{ij}'\boldsymbol{\alpha} +\]

+

then the gradient of the log-likelihood with respect to the +coefficient vector \(\boldsymbol{\alpha}\) is

+

\[ +\frac{\partial\ell}{\partial\boldsymbol{\alpha}} += +\sum_{i,j} +\frac{\partial\eta_{ij}}{\partial\boldsymbol{\alpha}} +\frac{\partial\ell}{\partial\eta_{ij}} += +\sum_{i,j} +\boldsymbol{x}_{ij} +(n_{ij}-n_{i+}\pi_{ij}) += +\sum_{i,j} +\boldsymbol{x}_{ij} +n_{i+} +(y_{ij}-\pi_{ij}) += +\boldsymbol{X}'\boldsymbol{N}(\boldsymbol{y}-\boldsymbol{\pi}) +\]

+

and the Hessian is

+

\[ +\frac{\partial^2\ell}{\partial\boldsymbol{\alpha}\partial\boldsymbol{\alpha}'} += +\sum_{i,j} +\frac{\partial\eta_{ij}}{\partial\boldsymbol{\alpha}} +\frac{\partial\eta_{ij}}{\partial\boldsymbol{\alpha}'} +\frac{\partial\ell^2}{\partial\eta_{ij}^2} += +- +\sum_{i,j,k} +\boldsymbol{x}_{ij} +n_{i+} +(\delta_{jk}-\pi_{ij}\pi_{ik}) +\boldsymbol{x}_{ij}' += +- +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X} +\]

+

Here \(y_{ij}=n_{ij}/n_{i+}\), while +\(boldsymbol{N}\) is a diagonal matrix +with diagonal elements \(n_{i+}\).

+

Newton-Raphson iterations then take the form

+

\[ +\boldsymbol{\alpha}^{(s+1)} += +\boldsymbol{\alpha}^{(s)} +- +\left( +\frac{\partial^2\ell}{\partial\boldsymbol{\alpha}\partial\boldsymbol{\alpha}'} +\right)^{-1} +\frac{\partial\ell}{\partial\boldsymbol{\alpha}} += +\boldsymbol{\alpha}^{(s)} ++ +\left( +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X} +\right)^{-1} +\boldsymbol{X}'\boldsymbol{N}(\boldsymbol{y}-\boldsymbol{\pi}) +\]

+

where \(\boldsymbol{\pi}\) and \(\boldsymbol{W}\) are evaluated at \(\boldsymbol{\alpha}=\boldsymbol{\alpha}^{(s)}\).

+

Multiplying by \(\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X}\) +gives

+

\[ +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X} +\boldsymbol{\alpha}^{(s+1)} += +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X} +\boldsymbol{\alpha}^{(s)} ++ +\boldsymbol{X}'\boldsymbol{N}(\boldsymbol{y}-\boldsymbol{\pi}) += +\boldsymbol{X}'\boldsymbol{W} +\left(\boldsymbol{X}\boldsymbol{\alpha}^{(s)}+\boldsymbol{W}^-\boldsymbol{N}(\boldsymbol{y}-\boldsymbol{\pi})\right) += +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{y}^* +\]

+

where \(\boldsymbol{W}^-\) is a +generalized inverse of \(\boldsymbol{W}\) and \(\boldsymbol{y}^*\) is a “working response +vector” with elements

+

\[ +y_{ij}^*=\boldsymbol{x}_{ij}'\boldsymbol{\alpha}^{(s)}+\frac{y_{ij}-\pi_{ij}}{\pi_{ij}} +\]

+

The IWLS algorithm thus involves the following steps:

+
    +
  1. Create some suitable starting values for \(\boldsymbol{\pi}\), \(\boldsymbol{W}\), and \(\boldsymbol{y}^*\)

  2. +
  3. Construct the “working dependent variable” \(\boldsymbol{y}^*\)

  4. +
  5. +

    Solve the equation

    +

    \[ +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{X} +\boldsymbol{\alpha} += +\boldsymbol{X}'\boldsymbol{W}\boldsymbol{y}^* +\]

    +

    for \(\boldsymbol{\alpha}\).

    +
  6. +
  7. Compute updated \(\boldsymbol{\eta}\), \(\boldsymbol{\pi}\), \(\boldsymbol{W}\), and \(\boldsymbol{y}^*\).

  8. +
  9. +

    Compute the updated value for the log-likelihood or the +deviance

    +

    \[ +d=2\sum_{i,j}n_{ij}\ln\frac{y_{ij}}{\pi_{ij}} +\]

    +
  10. +
  11. If the decrease of the deviance (or the increase of the +log-likelihood) is smaller than a given tolerance criterian (typically +\(\Delta d \leq 10^{-7}\)) stop the +algorighm and declare it as converged. Otherwise go back to step 2 with +the updated value of \(\boldsymbol{\alpha}\).

  12. +
+

The starting values for the algorithm used by the mclogit +package are constructe as follows:

+
    +
  1. +

    Set

    +

    \[ +\eta_{ij}^{(0)} = \ln (n_{ij}+\tfrac12) + - \frac1{q_i}\sum_{k\in\mathcal{S}_i}\ln +(n_{ij}+\tfrac12) +\]

    +

    (where \(q_i\) is the size of the +choice set \(\mathcal{S}_i\))

    +
  2. +
  3. Compute the starting values of the choice probabilities \(\pi_{ij}^{(0)}\) according to the equation +at the beginning of the page

  4. +
  5. +

    Compute intial values of the working dependent variable according +to

    +

    \[ +y_{ij}^{*(0)} += +\eta_{ij}^{(0)}+\frac{y_{ij}-\pi_{ij}^{(0)}}{\pi_{ij}^{(0)}} +\]

    +
  6. +
+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/articles/index.html b/articles/index.html new file mode 100644 index 0000000..5ccbe64 --- /dev/null +++ b/articles/index.html @@ -0,0 +1,134 @@ + +Articles • mclogit + + +
+
+ + + +
+ +
+ + +
+ + + + + + + + diff --git a/articles/random-effects.html b/articles/random-effects.html new file mode 100644 index 0000000..b2351d0 --- /dev/null +++ b/articles/random-effects.html @@ -0,0 +1,217 @@ + + + + + + + + +Random effects in baseline logit models and conditional logit models • mclogit + + + + + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

The “mclogit” package allows for the presence of random effects in +baseline-category logit and conditional logit models. In +baseline-category logit models, the random effects may represent +(unobserved) characteristics that are common the individuals in +clusters, such as regional units or electoral districts or the like. In +conditional logit models, random effects may represent attributes that +share across several choice occasions within the same context of choice. +That is, if one analyses voting behaviour across countries then an +random effect specific to the Labour party may represent unobserved +attributes of this party in terms of which it differs from (or is more +like) the Social Democratic Party of Germany (SPD). My original +motivation for working on conditional logit models with random effects +was to make it possible to assess the impact of parties’ political +positions on the patterns of voting behaviour in various European +countries. The results of this research are published in an article in +Electoral Studies elff:divisions.positions.voting.

+

In its earliest incarnation, the package supported only a very simple +random-intercept extension of conditional logit models (or “mixed +conditional logit models”, hence the name of the package). These models +can be written as

+

\[ +\pi_{ij} = +\frac{\exp(\eta_{ij})}{\sum_{k\in\mathcal{S}_i}\exp(\eta_{ik})} +\]

+

with

+

\[ +\eta_{ij}=\sum_h\alpha_hx_{hij}+\sum_kz_{ik}b_{jk} +\]

+

where \(x_{hij}\) represents values +of independent variables, \(\alpha_h\) +are coefficients, \(z_{ik}\) are dummy +ariables (that are equal to \(1\) if +\(i\) is in cluster \(k\) and equal to \(0\) otherwise), \(b_{jk}\) are random effects with a normal +distribution with expectation \(0\) and +variance parameter \(\sigma^2\).

+

Later releases also added support for baseline-category logit models +(initially only without random effects). In order to support random +effects in baseline-category logit models, the package had to be further +modified to allow for conditional logit models with random slopes (this +is so because baseline-categoy logit models can be expressed as a +particular type of conditional logit models).

+

It should be noted that estimating the parameters of random effects +multinomial logit models (whether of baseline-category logit variety or +the conditional logit variety) involves the considerable challenges +already known from the “generalized linear mixed models” literature. The +main challenge is that the likelihood function involves analytically +intractable integrals (i.e. there is know way to “solve” or eliminate +the intergrals from the formula of the likelihood function). This means +that either computationally intensive methods for the computation of +such integrals have to be used or certain approximations (most notably +the Laplace approximation technique and its variants), which may lead to +biases in certain situations. The “mclogit” package only supports +approximate likelihood-based inference. Most of the time the +PQL-technique based on a (first-order) Laplace approximation was +supported, release 0.8, “mclogit” also supports the MQL technique, which +is based on a (first-order) Solomon-Cox approximation. The ideas behind +the PQL and MQL techniques are described e.g. in breslow.clayton:approximate.inference.glmm.

+
+ + + +
+ + + + +
+ + + + + + + + diff --git a/authors.html b/authors.html index 0586cac..112814d 100644 --- a/authors.html +++ b/authors.html @@ -1,8 +1,20 @@ -Authors and Citation • mclogitAuthors and Citation • mclogit +
@@ -17,7 +29,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -25,12 +37,45 @@ @@ -60,14 +105,14 @@

Citation

Elff M (2023). mclogit: Multinomial Logit Models, with or without Random Effects or Overdispersion. -R package version 0.9.6, https://github.com/melff/mclogit/, http://mclogit.elff.eu. +R package version 0.9.8, https://github.com/melff/mclogit/, http://melff.github.io/mclogit/.

@Manual{,
   title = {mclogit: Multinomial Logit Models, with or without Random Effects or Overdispersion},
   author = {Martin Elff},
   year = {2023},
-  note = {R package version 0.9.6, https://github.com/melff/mclogit/},
-  url = {http://mclogit.elff.eu},
+  note = {R package version 0.9.8, https://github.com/melff/mclogit/},
+  url = {http://melff.github.io/mclogit/},
 }
@@ -82,6 +127,7 @@

Citation

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/code-color-scheme-dark.css b/code-color-scheme-dark.css new file mode 100644 index 0000000..3cec218 --- /dev/null +++ b/code-color-scheme-dark.css @@ -0,0 +1,48 @@ +pre { + word-wrap: normal; + word-break: normal; + /*border: 1px solid #eee;*/ + border: 0px !important; +} + +pre, code { + background-color: #1c1c1c; + color: #ccc; +} + +pre code { + overflow: auto; + word-wrap: normal; + white-space: pre; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #aaa; + display: block; + height: auto; +} + +code a, pre a { + font-family: ui-monospace, SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace; + color: #85AACC; + text-decoration: underline; +} + +a.sourceLine:hover { + text-decoration: none; +} + +.fl {color: #ae81ff;} +.fu {color: #ade837;} /* function */ +.ch,.st {color: #e7db74;} /* string */ +.kw {color: #f92672;} /* keyword */ +.co {color: #696d70;} /* comment */ +.va {color: #fd971f;} /* values */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} diff --git a/code-color-scheme-light.css b/code-color-scheme-light.css new file mode 100644 index 0000000..6a23e80 --- /dev/null +++ b/code-color-scheme-light.css @@ -0,0 +1,48 @@ +pre { + word-wrap: normal; + word-break: normal; + /*border: 1px solid #eee;*/ + border: 0px !important; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre code { + overflow: auto; + word-wrap: normal; + white-space: pre; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #fff; + display: block; + height: auto; +} + +code a, pre a { + font-family: ui-monospace, SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace; + color: #375f84; + text-decoration: underline; +} + +a.sourceLine:hover { + text-decoration: none; +} + +.fl {color: #1514b5;} +.fu {color: #8c60bf;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ +.va {color: #3032da;} /* values */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} \ No newline at end of file diff --git a/darkswitch.js b/darkswitch.js new file mode 100644 index 0000000..ad68ee0 --- /dev/null +++ b/darkswitch.js @@ -0,0 +1,69 @@ +$(document).ready(function(){ + + prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)"); + + currentTheme = localStorage.getItem("theme"); + if (currentTheme) { + init_color_scheme_css("css", currentTheme); + init_color_scheme_css("css-code", currentTheme); + } else if (prefersDarkScheme) { + if (typeof $mode === 'undefined') { + $mode = 'light'; + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) $mode = 'dark'; + init_color_scheme_css("css", $mode); + init_color_scheme_css("css-code", $mode); + } + toggle_color_scheme_css("css", $mode); + toggle_color_scheme_css("css-code", $mode); + } + + // function to initialise the css + function init_color_scheme_css($id, $mode) { + if ($("#"+$id)) $("#"+$id).remove(); // remove existing id + $("#"+$id+"-"+$mode).attr( { + "data-href-light": $("#"+$id+"-light").attr("href"), // store the light CSS url + "data-href-dark": $("#"+$id+"-dark").attr("href"), // store the dark CSS url + "data-color-scheme": $mode, // store the mode, so that we don't re-initalise + "media": "all", // drop the media filter + "id": $id // rename the id (drop the `-{mode}` bit) + } ); + $other = ($mode == 'dark') ? 'light' : 'dark'; + $("#"+$id+"-"+$other).remove(); + } + + // function to toggle the CSS + function toggle_color_scheme_css($id, $mode) { + // grab the new mode css href + $href = $("#"+$id).data("href-"+$mode); // use `.data()` here, leverage the cache + // set the CSS to the mode preference. + $("#"+$id).attr( { + "href": $href, + "data-color-scheme": $mode, + }); + } + + // toggle button click code + $("#css-toggle-btn").bind("click", function() { + // get current mode + // don't use `.data("color-scheme")`, it doesn't refresh + $mode = $("#css").attr("data-color-scheme"); + // test if this is a first time click event, if so initialise the code + if (typeof $mode === 'undefined') { + // not defined yet - set pref. & ask the browser if alt. is active + $mode = 'light'; + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) $mode = 'dark'; + init_color_scheme_css("css", $mode); + init_color_scheme_css("css-code", $mode); + // `init_color_scheme_css()` any other CSS + } + // by here we have the current mode, so swap it + $new_mode = ($mode == 'dark') ? 'light' : 'dark'; + toggle_color_scheme_css("css", $new_mode); + toggle_color_scheme_css("css-code", $new_mode); + // `toggle_color_scheme_css()` any other CSS + + // Saving user's preference to the localStorage + localStorage.setItem("theme", $new_mode); + }); + +}); diff --git a/index.html b/index.html index ad407f8..715ad6c 100644 --- a/index.html +++ b/index.html @@ -5,9 +5,21 @@ -Multinomial Logit Models, with or without Random Effects or Overdispersion • mclogit - - + +Multinomial Logit Models, with or without Random Effects or Overdispersion • mclogit + @@ -21,7 +33,11 @@ + + + + + @@ -38,7 +54,7 @@ mclogit - 0.9.6 + 0.9.8 @@ -46,6 +62,39 @@ @@ -73,8 +126,6 @@

CRAN Total downloads from RStudio CRAN mirror Current release on GitHub Build Status

This packages provides estimators for multinomial logit models in their conditional logit and baseline logit variants, with or without random effects, with or without overdispersion. Random effects models are estimated using the PQL technique (based on a Laplace approximation) or the MQL technique (based on a Solomon-Cox approximation). Estimates should be treated with caution if the group sizes are small.

-

Releases will be published on CRAN. Pre-releases will be available here in source and binary form. To install from the sources on GitHub you can use devtools::install_github("melff/mclogit",subdir="pkg").

-

More information about the package can be found at my site

@@ -124,6 +175,7 @@

Developers

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/pkgdown.yml b/pkgdown.yml index 69f21b4..1c5bef1 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -1,6 +1,15 @@ pandoc: 2.19.2 pkgdown: 2.0.7 pkgdown_sha: ~ -articles: {} -last_built: 2023-11-24T17:27Z +articles: + approximations: approximations.html + baseline-and-conditional-logit: baseline-and-conditional-logit.html + baseline-logit: baseline-logit.html + conditional-logit: conditional-logit.html + fitting-mclogit: fitting-mclogit.html + random-effects: random-effects.html +last_built: 2023-12-27T11:12Z +urls: + reference: https://melff.github.io/mclogit/reference + article: https://melff.github.io/mclogit/articles diff --git a/preferably.css b/preferably.css new file mode 100644 index 0000000..d6493f7 --- /dev/null +++ b/preferably.css @@ -0,0 +1,37 @@ +body, p, a { + font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji; + font-weight: 500; +} + +h1 { + font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji; + font-weight: 800 !important; +} + +h2, h3, h4, h5, h6 { + font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji; + font-weight: bold; +} + +pre, code, pre.usage, code.sourceCode.r, .sourceCode, .examples, .downlit, .sourceCode, .r { + font-family: ui-monospace, SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace; + font-weight: 500; +} + +.github-love { + stroke: #ea4aaa; + fill: #ea4aaa; +} + + +.preferably { + margin-top: -2px; +} + +@media (prefers-color-scheme: dark) { + + .github-love { + stroke: #db61a2; + fill: #db61a2; + } +} diff --git a/reference/Transport.html b/reference/Transport.html index c31d1f4..40c05d3 100644 --- a/reference/Transport.html +++ b/reference/Transport.html @@ -1,9 +1,21 @@ -Choice of Means of Transport — Transport • mclogitChoice of Means of Transport — Transport • mclogit +
@@ -18,7 +30,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -26,12 +38,45 @@ @@ -95,6 +140,7 @@

Format

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/dispersion.html b/reference/dispersion.html index 72c037f..cb8c40b 100644 --- a/reference/dispersion.html +++ b/reference/dispersion.html @@ -1,12 +1,24 @@ -Overdispersion in Multinomial Logit Models — dispersion • mclogitOverdispersion in Multinomial Logit Models — dispersion • mclogit +
@@ -21,7 +33,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -29,12 +41,45 @@ @@ -60,7 +105,7 @@

Overdispersion in Multinomial Logit Models

dispersion(object,method, ...)
 # S3 method for mclogit
-dispersion(object,method=NULL, ...)
+dispersion(object,method=NULL,groups=NULL, ...)
@@ -78,6 +123,13 @@

Arguments

NULL, in which case the default estimator, "Afroz" is used. The estimators are discussed in Afroz et al. (2019).

+
groups
+

an optional formula that specifies groups of observations + relevant for the estimation of overdispersion. Prediced probabilities should be + constant within groups, otherwise a warning is generated + since the overdispersion estimate may + be imprecise.

+
...

other arguments, ignored or passed to other methods.

@@ -106,9 +158,9 @@

Examples

#> converged dispersion(house.mblogit,method="Afroz") -#> [1] 20.45129 +#> [1] 2.062653 dispersion(house.mblogit,method="Deviance") -#> [1] 26.69295 +#> [1] 2.175601 summary(house.mblogit) #> @@ -170,7 +222,7 @@

Examples

#> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> -#> Dispersion: 20.45129 on 130 degrees of freedom +#> Dispersion: 2.062653 on 130 degrees of freedom #> Approximate residual Deviance: 3470 #> Number of Fisher scoring iterations: 4 #> Number of observations: 1681 @@ -182,28 +234,28 @@

Examples

#> mblogit(formula = Sat ~ Infl + Type + Cont, data = housing, weights = Freq) #> #> Equation for Medium vs Low: -#> Estimate Std. Error t value Pr(>|t|) -#> (Intercept) -0.4192 0.7821 -0.536 0.593 -#> InflMedium 0.4464 0.6402 0.697 0.487 -#> InflHigh 0.6649 0.8427 0.789 0.432 -#> TypeApartment -0.4357 0.7802 -0.558 0.578 -#> TypeAtrium 0.1314 1.0090 0.130 0.897 -#> TypeTerrace -0.6666 0.9327 -0.715 0.476 -#> ContHigh 0.3609 0.5987 0.603 0.548 +#> Estimate Std. Error t value Pr(>|t|) +#> (Intercept) -0.4192 0.2484 -1.688 0.0938 . +#> InflMedium 0.4464 0.2033 2.196 0.0299 * +#> InflHigh 0.6649 0.2676 2.485 0.0142 * +#> TypeApartment -0.4357 0.2478 -1.758 0.0811 . +#> TypeAtrium 0.1314 0.3204 0.410 0.6825 +#> TypeTerrace -0.6666 0.2962 -2.250 0.0261 * +#> ContHigh 0.3609 0.1901 1.898 0.0599 . #> #> Equation for High vs Low: -#> Estimate Std. Error t value Pr(>|t|) -#> (Intercept) -0.1387 0.7201 -0.193 0.8475 -#> InflMedium 0.7349 0.6193 1.187 0.2375 -#> InflHigh 1.6126 0.7558 2.134 0.0348 * -#> TypeApartment -0.7356 0.7022 -1.048 0.2968 -#> TypeAtrium -0.4080 0.9565 -0.427 0.6704 -#> TypeTerrace -1.4123 0.9051 -1.560 0.1211 -#> ContHigh 0.4818 0.5614 0.858 0.3923 +#> Estimate Std. Error t value Pr(>|t|) +#> (Intercept) -0.1387 0.2287 -0.607 0.545109 +#> InflMedium 0.7349 0.1967 3.737 0.000278 *** +#> InflHigh 1.6126 0.2400 6.718 5.20e-10 *** +#> TypeApartment -0.7356 0.2230 -3.299 0.001253 ** +#> TypeAtrium -0.4080 0.3038 -1.343 0.181568 +#> TypeTerrace -1.4123 0.2875 -4.913 2.64e-06 *** +#> ContHigh 0.4818 0.1783 2.703 0.007800 ** #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> -#> Dispersion: 20.45129 on 130 degrees of freedom +#> Dispersion: 2.062653 on 130 degrees of freedom #> Approximate residual Deviance: 3470 #> Number of Fisher scoring iterations: 4 #> Number of observations: 1681 @@ -231,28 +283,28 @@

Examples

#> dispersion = "Afroz", from.table = TRUE) #> #> Equation for Medium vs Low: -#> Estimate Std. Error t value Pr(>|t|) -#> (Intercept) -0.4192 0.1832 -2.289 0.02842 * -#> InflMedium 0.4464 0.1499 2.977 0.00533 ** -#> InflHigh 0.6649 0.1974 3.369 0.00189 ** -#> TypeApartment -0.4357 0.1827 -2.384 0.02284 * -#> TypeAtrium 0.1314 0.2363 0.556 0.58189 -#> TypeTerrace -0.6666 0.2184 -3.051 0.00440 ** -#> ContHigh 0.3609 0.1402 2.573 0.01461 * +#> Estimate Std. Error t value Pr(>|t|) +#> (Intercept) -0.41923 0.02661 -15.757 < 2e-16 *** +#> InflMedium 0.44640 0.02178 20.497 < 2e-16 *** +#> InflHigh 0.66494 0.02867 23.195 < 2e-16 *** +#> TypeApartment -0.43569 0.02654 -16.414 < 2e-16 *** +#> TypeAtrium 0.13137 0.03432 3.827 0.00053 *** +#> TypeTerrace -0.66657 0.03173 -21.007 < 2e-16 *** +#> ContHigh 0.36085 0.02037 17.716 < 2e-16 *** #> #> Equation for High vs Low: #> Estimate Std. Error t value Pr(>|t|) -#> (Intercept) -0.1387 0.1686 -0.823 0.416418 -#> InflMedium 0.7349 0.1450 5.067 1.41e-05 *** -#> InflHigh 1.6126 0.1770 9.110 1.20e-10 *** -#> TypeApartment -0.7356 0.1645 -4.473 8.19e-05 *** -#> TypeAtrium -0.4080 0.2240 -1.821 0.077370 . -#> TypeTerrace -1.4123 0.2120 -6.662 1.20e-07 *** -#> ContHigh 0.4818 0.1315 3.665 0.000837 *** +#> (Intercept) -0.13874 0.02450 -5.664 2.36e-06 *** +#> InflMedium 0.73486 0.02107 34.882 < 2e-16 *** +#> InflHigh 1.61263 0.02571 62.718 < 2e-16 *** +#> TypeApartment -0.73563 0.02389 -30.795 < 2e-16 *** +#> TypeAtrium -0.40798 0.03254 -12.539 2.64e-14 *** +#> TypeTerrace -1.41233 0.03079 -45.866 < 2e-16 *** +#> ContHigh 0.48183 0.01910 25.229 < 2e-16 *** #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> -#> Dispersion: 1.121765 on 34 degrees of freedom +#> Dispersion: 0.0236687 on 34 degrees of freedom #> Approximate residual Deviance: 38.66 #> Number of Fisher scoring iterations: 4 #> Number of observations: 1681 @@ -272,6 +324,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/electors.html b/reference/electors.html index 0776dee..00e37a8 100644 --- a/reference/electors.html +++ b/reference/electors.html @@ -1,9 +1,21 @@ -Class, Party Position, and Electoral Choice — electors • mclogitClass, Party Position, and Electoral Choice — electors • mclogit +
@@ -18,7 +30,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -26,12 +38,45 @@ @@ -201,7 +246,8 @@

Examples

#> (Co-)Variances: #> Grouping level: party.time #> Estimate Std.Err. -#> (Const.) 1.604 0.3098 +#> (Const.) (Const.) +#> (Const.) 1.604 0.3098 #> #> Approximate residual deviance: 947.5 #> Number of Fisher scoring iterations: 6 @@ -225,6 +271,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/getSummary-mclogit.html b/reference/getSummary-mclogit.html index 568839e..cfd103e 100644 --- a/reference/getSummary-mclogit.html +++ b/reference/getSummary-mclogit.html @@ -1,8 +1,20 @@ -`getSummary` Methods — getSummary-methods • mclogit`getSummary` Methods — getSummary-methods • mclogit +
@@ -17,7 +29,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -25,12 +37,45 @@ @@ -165,6 +210,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/index.html b/reference/index.html index d31c6fa..39b4cc4 100644 --- a/reference/index.html +++ b/reference/index.html @@ -1,8 +1,20 @@ -Function reference • mclogitFunction reference • mclogit +
@@ -17,7 +29,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -25,12 +37,45 @@ @@ -102,6 +147,7 @@

All functions

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/mblogit.html b/reference/mblogit.html index eb0874b..4fddea7 100644 --- a/reference/mblogit.html +++ b/reference/mblogit.html @@ -1,9 +1,21 @@ -Baseline-Category Logit Models for Categorical and Multinomial Responses — mblogit • mclogitBaseline-Category Logit Models for Categorical and Multinomial Responses — mblogit • mclogit +
@@ -18,7 +30,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -26,12 +38,45 @@ @@ -213,11 +258,11 @@

Details

References

Agresti, Alan. 2002. Categorical Data Analysis. 2nd ed, Hoboken, NJ: Wiley. - https://doi.org/10.1002/0471249688

+ doi:10.1002/0471249688

Breslow, N.E. and D.G. Clayton. 1993. "Approximate Inference in Generalized Linear Mixed Models". Journal of the American Statistical Association 88 (421): 9-25. - https://doi.org/10.1080/01621459.1993.10594284

+ doi:10.1080/01621459.1993.10594284

See also

@@ -284,14 +329,14 @@

Examples

#> Call: mblogit(formula = Sat ~ Infl + Type + Cont, data = housing, weights = Freq) #> #> Coefficients: -#> Predictors -#> Response categories (Intercept) InflMedium InflHigh TypeApartment -#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 -#> High/Low -0.1387 0.7349 1.6126 -0.7356 -#> Predictors -#> Response categories TypeAtrium TypeTerrace ContHigh -#> Medium/Low 0.1314 -0.6666 0.3609 -#> High/Low -0.4080 -1.4123 0.4818 +#> Predictors +#> Logit eqn. (Intercept) InflMedium InflHigh TypeApartment TypeAtrium +#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 +#> High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 +#> Predictors +#> Logit eqn. TypeTerrace ContHigh +#> Medium/Low -0.6666 0.3609 +#> High/Low -1.4123 0.4818 #> #> Null Deviance: 3694 #> Residual Deviance: 3470 @@ -395,6 +440,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/mclogit.fit.html b/reference/mclogit.fit.html index 87ec9ef..2f2825a 100644 --- a/reference/mclogit.fit.html +++ b/reference/mclogit.fit.html @@ -1,9 +1,21 @@ -Internal functions used for model fit. — mclogit.fit • mclogitInternal functions used for model fit. — mclogit.fit • mclogit +
@@ -18,7 +30,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -26,12 +38,45 @@ @@ -141,6 +186,7 @@

Value

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/mclogit.html b/reference/mclogit.html index d6fb127..8f5f249 100644 --- a/reference/mclogit.html +++ b/reference/mclogit.html @@ -1,5 +1,17 @@ -Conditional Logit Models and Mixed Conditional Logit Models — mclogit • mclogitConditional Logit Models and Mixed Conditional Logit Models — mclogit • mclogit +
@@ -23,7 +35,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -31,12 +43,45 @@ @@ -68,6 +113,7 @@

Conditional Logit Models and Mixed Conditional Logit Models

method = NULL, estimator=c("ML","REML"), dispersion = FALSE, start=NULL, + groups = NULL, control=if(length(random)) mmclogit.control(...) else mclogit.control(...), ...) @@ -181,6 +227,14 @@

Arguments

("Afroz") is used, if FALSE, the dispersion parameter is set to 1, that is, no dispersion. For details see dispersion.

+ +
groups
+

an optional formula that specifies groups of observations + relevant for the estimation of overdispersion. Covariates should be + constant within groups, otherwise a warning is generated + since the overdispersion estimate may + be imprecise.

+
control

a list of parameters for the fitting process. @@ -230,6 +284,12 @@

Note

satisfied. Since version 0.6 of the package, the function mclogit will complain about such model a misspecification explicitely.

+

From version 0.9.7 it is possible to choose the optimization + technique used for the inner iterations of the PQL/MQL: either + nlminb (the default), nlm, + or any of the algorithms (other than "Brent" supported by + optim). To choose the optimizer, use the + appropriate argument for mmclogit.control .

References

@@ -338,7 +398,8 @@

Examples

Freq|time.class~econ.left/class+welfare/class+auth/class, random=~1|party/time, data=electors)) -#> Warning: Inner iterations did not coverge - nlminb message: singular convergence (7) +#> +#> Warning: Possible non-convergence of inner iterations - nlminb message: singular convergence (7) #> #> Iteration 1 - deviance = 495.6469 - criterion = 0.1640698 #> Iteration 2 - deviance = 379.0387 - criterion = 0.02944294 @@ -369,10 +430,12 @@

Examples

#> (Co-)Variances: #> Grouping level: party #> Estimate Std.Err. -#> (Const.) 2.002 2.143 +#> (Const.) (Const.) +#> (Const.) 2.002 2.143 #> #> Grouping level: party:time #> Estimate Std.Err. +#> (Const.) (Const.) #> (Const.) 2.372e-08 1.09e-24 #> #> Approximate residual deviance: 362.8 @@ -419,10 +482,12 @@

Examples

#> (Co-)Variances: #> Grouping level: party #> Estimate Std.Err. -#> (Const.) 2.002 2.143 +#> (Const.) (Const.) +#> (Const.) 2.002 2.143 #> #> Grouping level: time #> Estimate Std.Err. +#> econ.left econ.left #> econ.left 0.0002345 2.579e-12 #> #> Approximate residual deviance: 362.6 @@ -448,6 +513,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/mclogit_control.html b/reference/mclogit_control.html index a864100..e136289 100644 --- a/reference/mclogit_control.html +++ b/reference/mclogit_control.html @@ -1,9 +1,21 @@ -Control Parameters for the Fitting Process — mclogit.control • mclogitControl Parameters for the Fitting Process — mclogit.control • mclogit +
@@ -18,7 +30,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -26,12 +38,45 @@ @@ -60,7 +105,18 @@

Control Parameters for the Fitting Process

avoid.increase = FALSE, break.on.increase = FALSE, break.on.infinite = FALSE, - break.on.negative = FALSE) + break.on.negative = FALSE, + inner.optimizer = "nlminb", + maxit.inner = switch(inner.optimizer, + SANN = 10000, + `Nelder-Mead` = 500, + 100), + CG.type = 1, + NM.alpha = 1, + NM.beta = 0.5, + NM.gamma = 2.0, + SANN.temp = 10, + SANN.tmax = 10)
@@ -97,6 +153,44 @@

Arguments

logical; should a negative deviance stop the algorithm?

+
inner.optimizer
+

a character string, one of + "nlminb", "nlm", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN". + See nlminb, nlm, optim.

+ +
maxit.inner
+

integer; the maximum number of inner iterations

+ +
CG.type
+

integer; the type argument passed to + optim if + "CG" is selected as inner optimizer.

+ +
NM.alpha
+

integer; the alpha argument passed to + optim if + "Nelder-Mead" is selected as inner optimizer.

+ +
NM.beta
+

integer; the beta argument passed to + optim if + "Nelder-Mead" is selected as inner optimizer.

+ +
NM.gamma
+

integer; the gamma argument passed to + optim if + "Nelder-Mead" is selected as inner optimizer.

+ +
SANN.temp
+

integer; the temp argument passed to + optim if + "SANN" is selected as inner optimizer.

+ +
SANN.tmax
+

integer; the tmax argument passed to + optim if + "SANN" is selected as inner optimizer.

+

Value

@@ -118,6 +212,7 @@

Value

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/predict.html b/reference/predict.html index b4ddf3f..33d66be 100644 --- a/reference/predict.html +++ b/reference/predict.html @@ -1,6 +1,18 @@ -Predicting responses or linear parts of the baseline-category and - conditional logit models — predict • mclogitPredicting responses or linear parts of the baseline-category and + conditional logit models — predict • mclogit +
@@ -24,7 +36,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -32,12 +44,45 @@ @@ -128,14 +173,14 @@

Examples

#> Call: mblogit(formula = Sat ~ Infl + Type + Cont, data = housing, weights = Freq) #> #> Coefficients: -#> Predictors -#> Response categories (Intercept) InflMedium InflHigh TypeApartment -#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 -#> High/Low -0.1387 0.7349 1.6126 -0.7356 -#> Predictors -#> Response categories TypeAtrium TypeTerrace ContHigh -#> Medium/Low 0.1314 -0.6666 0.3609 -#> High/Low -0.4080 -1.4123 0.4818 +#> Predictors +#> Logit eqn. (Intercept) InflMedium InflHigh TypeApartment TypeAtrium +#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 +#> High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 +#> Predictors +#> Logit eqn. TypeTerrace ContHigh +#> Medium/Low -0.6666 0.3609 +#> High/Low -1.4123 0.4818 #> #> Null Deviance: 3694 #> Residual Deviance: 3470 @@ -246,6 +291,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/reference/simulate.html b/reference/simulate.html index bae5dd4..ec0203a 100644 --- a/reference/simulate.html +++ b/reference/simulate.html @@ -1,10 +1,22 @@ -Simulating responses from baseline-category and conditional logit models — simulate.mclogit • mclogitSimulating responses from baseline-category and conditional logit models — simulate.mclogit • mclogit +
@@ -19,7 +31,7 @@ mclogit - 0.9.6 + 0.9.8
@@ -27,12 +39,45 @@ @@ -137,14 +182,14 @@

Examples

#> from.table = TRUE) #> #> Coefficients: -#> Predictors -#> Response categories (Intercept) InflMedium InflHigh TypeApartment -#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 -#> High/Low -0.1387 0.7349 1.6126 -0.7356 -#> Predictors -#> Response categories TypeAtrium TypeTerrace ContHigh -#> Medium/Low 0.1314 -0.6666 0.3609 -#> High/Low -0.4080 -1.4123 0.4818 +#> Predictors +#> Logit eqn. (Intercept) InflMedium InflHigh TypeApartment TypeAtrium +#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 +#> High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 +#> Predictors +#> Logit eqn. TypeTerrace ContHigh +#> Medium/Low -0.6666 0.3609 +#> High/Low -1.4123 0.4818 #> #> Null Deviance: 262.1 #> Residual Deviance: 38.66 @@ -163,14 +208,14 @@

Examples

#> Call: mblogit(formula = Sat ~ Infl + Type + Cont, data = housing.long) #> #> Coefficients: -#> Predictors -#> Response categories (Intercept) InflMedium InflHigh TypeApartment -#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 -#> High/Low -0.1387 0.7349 1.6126 -0.7356 -#> Predictors -#> Response categories TypeAtrium TypeTerrace ContHigh -#> Medium/Low 0.1314 -0.6666 0.3609 -#> High/Low -0.4080 -1.4123 0.4818 +#> Predictors +#> Logit eqn. (Intercept) InflMedium InflHigh TypeApartment TypeAtrium +#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 +#> High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 +#> Predictors +#> Logit eqn. TypeTerrace ContHigh +#> Medium/Low -0.6666 0.3609 +#> High/Low -1.4123 0.4818 #> #> Null Deviance: 3694 #> Residual Deviance: 3470 @@ -201,14 +246,14 @@

Examples

#> data = housing.mat) #> #> Coefficients: -#> Predictors -#> Response categories (Intercept) InflMedium InflHigh TypeApartment -#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 -#> High/Low -0.1387 0.7349 1.6126 -0.7356 -#> Predictors -#> Response categories TypeAtrium TypeTerrace ContHigh -#> Medium/Low 0.1314 -0.6666 0.3609 -#> High/Low -0.4080 -1.4123 0.4818 +#> Predictors +#> Logit eqn. (Intercept) InflMedium InflHigh TypeApartment TypeAtrium +#> Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 +#> High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 +#> Predictors +#> Logit eqn. TypeTerrace ContHigh +#> Medium/Low -0.6666 0.3609 +#> High/Low -1.4123 0.4818 #> #> Null Deviance: 262.1 #> Residual Deviance: 38.66 @@ -289,6 +334,7 @@

Examples

Site built with pkgdown 2.0.7.

+

Using preferably template.

diff --git a/sitemap.xml b/sitemap.xml index 216ab23..6d14b1b 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -1,45 +1,66 @@ - /404.html + https://melff.github.io/mclogit/404.html - /authors.html + https://melff.github.io/mclogit/articles/approximations.html - /index.html + https://melff.github.io/mclogit/articles/baseline-and-conditional-logit.html - /reference/Transport.html + https://melff.github.io/mclogit/articles/baseline-logit.html - /reference/dispersion.html + https://melff.github.io/mclogit/articles/conditional-logit.html - /reference/electors.html + https://melff.github.io/mclogit/articles/fitting-mclogit.html - /reference/getSummary-mclogit.html + https://melff.github.io/mclogit/articles/index.html - /reference/index.html + https://melff.github.io/mclogit/articles/random-effects.html - /reference/mblogit.html + https://melff.github.io/mclogit/authors.html - /reference/mclogit.fit.html + https://melff.github.io/mclogit/index.html - /reference/mclogit.html + https://melff.github.io/mclogit/reference/Transport.html - /reference/mclogit_control.html + https://melff.github.io/mclogit/reference/dispersion.html - /reference/predict.html + https://melff.github.io/mclogit/reference/electors.html - /reference/simulate.html + https://melff.github.io/mclogit/reference/getSummary-mclogit.html + + + https://melff.github.io/mclogit/reference/index.html + + + https://melff.github.io/mclogit/reference/mblogit.html + + + https://melff.github.io/mclogit/reference/mclogit.fit.html + + + https://melff.github.io/mclogit/reference/mclogit.html + + + https://melff.github.io/mclogit/reference/mclogit_control.html + + + https://melff.github.io/mclogit/reference/predict.html + + + https://melff.github.io/mclogit/reference/simulate.html