Skip to content

Commit

Permalink
version 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Elff authored and cran-robot committed May 10, 2018
1 parent 5b16c63 commit 9321327
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 123 deletions.
12 changes: 6 additions & 6 deletions DESCRIPTION
@@ -1,13 +1,13 @@
Package: mclogit
Type: Package
Title: Mixed Conditional Logit Models
Version: 0.5.1
Date: 2017-07-16
Version: 0.6
Date: 2018-04-25
Author: Martin Elff
Maintainer: Martin Elff <mclogit@elff.eu>
Description: Specification and estimation of conditional logit models of binary
responses and multinomial counts is provided, with or without alternative-
specific random effects. The current implementation of the estimator for random
responses and multinomial counts is provided, with or without
random effects. The current implementation of the estimator for random
effects variances uses a Laplace approximation (or PQL) approach and thus should
be used only if groups sizes are large.
License: GPL-2
Expand All @@ -19,6 +19,6 @@ URL:
BugReports: http://github.com/melff/mclogit/issues
RoxygenNote: 5.0.1
NeedsCompilation: no
Packaged: 2017-07-15 23:56:48 UTC; elff
Packaged: 2018-05-10 09:48:14 UTC; elff
Repository: CRAN
Date/Publication: 2017-07-17 09:46:59 UTC
Date/Publication: 2018-05-10 12:16:38 UTC
16 changes: 7 additions & 9 deletions MD5
@@ -1,25 +1,23 @@
5b79bb423fd1a848c875aa6eff03c133 *DESCRIPTION
bc526bce97fcc5ab31252ecf1274de1c *DESCRIPTION
8e2f6305165fc3d69a294d09227ba690 *NAMESPACE
5f46b25a049e81e86774e78cd294ff89 *R/AIC-mclogit.R
fda85116896df5934a2ce2b9e3118dee *R/anova-mclogit.R
825e92e98bee4d5cba8ebbb5bad2f448 *R/getSummary-mblogit.R
174a746177e5e0ffa74047959c4b59ba *R/getSummary-mclogit.R
8443552bb939bf83bafc6255125dd6a9 *R/mblogit.R
e59d1445b41da59347a1d181b9e44025 *R/mclogit-fit.R
373e59f4f1e50208db954430b959aabc *R/mclogit.R
4391129b68ab0c0b4b4f6c6920d82f9a *R/mclogit.R
202e8dd6dd5ee19a281df6277484e46c *R/zzz.R
39d40b69dd3cffb9bf8c3d6fbd638fae *data/Transport.rda
030cc52f5962d7f76f12370c2c108ff9 *data/electors.rda
f07c5b8a1b9a311ce9f14c89a3501be5 *data/Transport.rda
170a2686691e2ec1bc0d197ec11a8397 *data/electors.rda
de4c63b49c62998527d72c185ceab0d3 *demo/00Index
6ba2e10f92f3743f465cda6cc059f5a1 *demo/mclogit.test.R
198cfecbf3ad7e32f75624a87953e05f *inst/ChangeLog
b98c84290f3b8c0921224cde137b44c8 *inst/ChangeLog.sync-conflict-20170309-201336
055faf0212b89aec35ac26ea67dc7f75 *inst/NEWS.Rd
85a099ef2942ee748e7c3baef305479f *inst/NEWS.sync-conflict-20170309-201318.Rd
285f7ffde7690a50a68c9e2d79922631 *inst/ChangeLog
3108d598ac3ef8fec366d0563fc95d72 *inst/NEWS.Rd
c05ff442f7a2312ff8f3d6b5aa96ddeb *man/Transport.Rd
6384c0365cb1b46ea7230227dd9c8392 *man/electors.Rd
5bb2193c1f179dc06510bfd2b8a46dfe *man/getSummary-mclogit.Rd
215c7ba13f2a1ca831b87c00adfb6e4a *man/mblogit.Rd
14524331f76dc7dd591490b6a448865f *man/mclogit.Rd
c1493568f138301373475f881ff48877 *man/mclogit.Rd
2592f185bc66478485d812cd6eaa59d6 *man/mclogit.fit.Rd
89ef120edb709000ad26477de8194dd7 *man/mclogit_control.Rd
62 changes: 48 additions & 14 deletions R/mclogit.R
Expand Up @@ -24,16 +24,25 @@ quickInteraction <- function(by){
return(structure(f,unique=uf))
}

constInSets <- function(X,sets){
ans <- integer(0)
matConstInSets <- function(X,sets){
ans <- logical(ncol(X))
for(i in 1:ncol(X)){
v <- tapply(X[,i],sets,var)
if(all(v[is.finite(v)]==0)) ans <- c(ans,i)
ans[i] <- all(v[is.finite(v)]==0)
}
names(ans) <- colnames(X)[ans]
ans
}

listConstInSets <- function(X,sets){
ans <- logical(length(X))
for(i in 1:length(X)){
v <- tapply(X[[i]],sets,var)
ans[i] <- all(v[is.finite(v)]==0)
}
ans
}


mclogit <- function(
formula,
data=parent.frame(),
Expand Down Expand Up @@ -102,10 +111,12 @@ mclogit <- function(
xlevels <- .getXlevels(mt,mf)
icpt <- match("(Intercept)",colnames(X),nomatch=0)
if(icpt) X <- X[,-icpt,drop=FALSE]
const <- constInSets(X,sets)
if(length(const)){
warning("removing ",paste(names(const),collapse=",")," from model")
X <- X[,-const,drop=FALSE]
const <- matConstInSets(X,sets)
if(any(const)){
warning("removing ",
gsub("(Intercept)","intercept",paste(colnames(X)[const],collapse=","),fixed=TRUE),
" from model due to insufficient within-choice set variance")
X <- X[,!const,drop=FALSE]
}
if(!length(start)){
drop.coefs <- check.mclogit.drop.coefs(Y,sets,weights,X,
Expand All @@ -115,14 +126,21 @@ mclogit <- function(
X <- X[,!drop.coefs,drop=FALSE]
}
}
if(ncol(X)<1)
stop("No predictor variable remains in model")

if(length(random) && control$trace)
cat("Fitting plain conditional logit to obtain starting values")

fit <- mclogit.fit(Y,sets,weights,X,
control=control,
start = start,
offset = offset)
control=control,
start = start,
offset = offset)

if(length(random)){ ## random effects

if(control$trace)
cat("Fitting random effects/random coefficients model")

null.dev <- fit$null.deviance

Expand All @@ -131,7 +149,6 @@ mclogit <- function(

groups <- random$groups
rX <- model.matrix(rt,mf,contrasts)

groups <- mf[groups]

nlev <- length(groups)
Expand All @@ -141,6 +158,21 @@ mclogit <- function(
for(i in 2:nlev)
groups[[i]] <- quickInteraction(groups[c(i-1,i)])
}

gconst <- listConstInSets(groups,sets)
if(any(gconst)){
rconst <- matConstInSets(rX,sets)
if(any(rconst)){
cat("\n")
warning("removing ",
gsub("(Intercept)","intercept",paste(colnames(rX)[rconst],collapse=","),fixed=TRUE),
" from random part of the model\n because of insufficient within-choice set variance")
rX <- rX[,!rconst,drop=FALSE]
}
if(ncol(rX)<1)
stop("No predictor variable remains in random part of the model.\nPlease reconsider your model specification.")
}


Z <- lapply(groups,mkZ,rX=rX)
G <- mkG(rX)
Expand Down Expand Up @@ -370,8 +402,10 @@ predict.mclogit <- function(object, newdata=NULL,type=c("link","response"),se.fi
contasts.arg=object$contrasts,
xlev=object$xlevels
)
drop <- match("(Intercept)",colnames(X))
X <- X[,-drop,drop=FALSE]

cf <- coef(object)
X <- X[,names(cf)]

eta <- c(X %*% coef(object))
if(se.fit){
V <- vcov(object)
Expand Down
Binary file modified data/Transport.rda
Binary file not shown.
Binary file modified data/electors.rda
Binary file not shown.
7 changes: 7 additions & 0 deletions inst/ChangeLog
@@ -1,3 +1,10 @@
2018-04-25:
- Improved handling of with misspecified random effect structures.
- Added documentation about new handling of misspecified models.

2017-10-25:
- Fixed handling of dropped predictors in `predict.mclogit`.

2017-01-26:
- Fixed some bugs in predict models for `mclogit` objects.
- Made sure that dummy coding is used for response factors even if they are ordinal
Expand Down
60 changes: 0 additions & 60 deletions inst/ChangeLog.sync-conflict-20170309-201336

This file was deleted.

28 changes: 28 additions & 0 deletions inst/NEWS.Rd
Expand Up @@ -2,6 +2,34 @@
\title{\emph{mclogit} News}
\encoding{UTF-8}

\section{Version 0.6}{
\subsection{NEW FEATURES}{
\itemize{
\item \code{mclogit} now complains about (i.e. throws an error
exception) when the random effects structure cannot be estimated,
e.g. because random effects are constant within choice sets
and therefore drop out by the formation of conditional logits.
}
}
}

\section{Version 0.5}{
\subsection{NEW FEATURES}{
\itemize{
\item \code{mclogit} now supports conditional logit models with
random slopes.
\item \code{mblogit} now supports multinomial baseline models with
random intercept and random slopes.
}
}
\subsection{BUGFIXES}{
\itemize{
\item \code{predict} methods of objects created by \code{mclogit}
and \code{mblogit} are better in handling missing data.
}
}
}

\section{Version 0.4}{
\subsection{NEW FEATURES}{
\itemize{
Expand Down
31 changes: 0 additions & 31 deletions inst/NEWS.sync-conflict-20170309-201318.Rd

This file was deleted.

27 changes: 24 additions & 3 deletions man/mclogit.Rd
Expand Up @@ -22,9 +22,9 @@
where the choice set may vary across choice occasions.

Conditional logit models without random effects are fitted by
Fisher-scoring/IWLS.
The implementation of mixed conditional logit currently is limited
to PQL and random intercepts.
Fisher-scoring/IWLS. Models with random effects
(mixed conditional logit models) are estimated via maximum likelihood
with a simple Laplace aproximation (aka PQL).
}
\usage{

Expand Down Expand Up @@ -105,6 +105,27 @@ mclogit(formula, data=parent.frame(), random=NULL,
same structure as an object of class "\link[stats]{glm}".
}

\note{
Covariates that are constant within choice sets are automatically
dropped from the model formula specified by the \code{formula}
argument of \code{mclogit}.

If the model contains random effects, these should
\itemize{
\item either vary within choice sets (e.g. the levels of a factor
that defines the choice sets should not be nested within the levels
of factor)
\item or be random coefficients of covariates that vary within
choice sets.
}

In earlier versions of the package (prior to 0.6) it will lead to a
failure of the model fitting algorithm if these conditions are not
satisfied. Since version 0.6 of the package, the function
\code{mclogit} will complain about such model a misspecification
explicitely.
}

\examples{
data(Transport)

Expand Down

0 comments on commit 9321327

Please sign in to comment.