Skip to content

Commit

Permalink
version 0.2-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Elff authored and gaborcsardi committed Dec 7, 2011
1 parent b0c606d commit 5dbcce6
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 277 deletions.
17 changes: 8 additions & 9 deletions DESCRIPTION
@@ -1,18 +1,17 @@
Package: mclogit
Type: Package
Title: Mixed Conditional Logit
Version: 0.2-2
Date: 2010-04-08
Version: 0.2-3
Date: 2011-12-07
Author: Martin Elff
Maintainer: Martin Elff <melff@essex.ac.uk>
Description: This packages provides a function to estimate parameters
for the mixed conditional logit model, or conditional logit
with random effects. The current implementation is limited to
random intercepts and to the PQL technique, mainly appropriate
for large clusters.
Description: This packages provides a function to estimate parameters for the
mixed conditional logit model, or conditional logit with random effects.
The current implementation is limited to random intercepts and to
the PQL technique, mainly appropriate for large clusters.
License: GPL-2
Depends: stats, MASS, memisc, Matrix
LazyLoad: Yes
Packaged: 2010-04-08 16:04:16 UTC; elff
Packaged: 2011-12-07 16:08:09 UTC; elff
Repository: CRAN
Date/Publication: 2010-04-09 17:30:44
Date/Publication: 2011-12-09 09:21:18
12 changes: 12 additions & 0 deletions MD5
@@ -0,0 +1,12 @@
0de589074236d95605638536da41b008 *DESCRIPTION
8cdde8983a8f991444d8fb7375d3d89a *NAMESPACE
96d8a24e0cbdaa6bf83bd6dc06f57c0d *R/mclogit.R
cb3bcc2bbfeca991c87728116fbbaeae *R/zzz.R
ff0bcabfd65173c63724454726eb74bd *data/Transport.rda
ab76aafc4431d069700ff11052f6d6d3 *data/electors.rda
de4c63b49c62998527d72c185ceab0d3 *demo/00Index
6ba2e10f92f3743f465cda6cc059f5a1 *demo/mclogit.test.R
c05ff442f7a2312ff8f3d6b5aa96ddeb *man/Transport.Rd
ca90251e1b6d6c9dd5d4bf069ffa090b *man/electors.Rd
4785075a991dbf2a6e4db4e878033822 *man/mclogit.Rd
89ef120edb709000ad26477de8194dd7 *man/mclogit_control.Rd
11 changes: 9 additions & 2 deletions NAMESPACE
@@ -1,10 +1,17 @@
import(stats,Matrix)
import(stats,Matrix,memisc)
export(
mclogit,
mclogit.control
mclogit.control#,
#getSummary.mclogit,
#mclogit.fit,
#mclogit.fit.random
)
S3method(print,mclogit)
S3method(vcov,mclogit)
S3method(deviance,mclogit)
S3method(summary,mclogit)
S3method(print,summary.mclogit)
S3method(fitted,mclogit)
S3method(predict,mclogit)
S3method(getSummary,mclogit)

53 changes: 43 additions & 10 deletions R/mclogit.R
@@ -1,12 +1,37 @@
# require(methods)
# if(!require(Matrix)) warning("mclogit with random effects won't work without Matrix package")

quickInteraction <- function(by){
if(is.list(by)){
n.arg <- length(by)
f <- 0L
uf <- 0L
for(i in rev(1:n.arg)){
y <- by[[i]]
y <- as.numeric(y)
uy <- unique(na.omit(y))
y <- match(y,uy,NA)
l <- length(uy)
f <- f*l + y - 1
uf <- unique(na.omit(f))
f <- match(f,uf,NA)
uf <- seq(length(uf))
}
}
else {
by <- as.numeric(by)
uf <- unique(na.omit(by))
f <- match(by,uf,NA)
uf <- seq(length(uf))
}
return(structure(f,unique=uf))
}

constInSets <- function(X,sets){
ans <- integer(0)
for(i in 1:ncol(X)){
v <- tapply(X[,i],sets,var)
if(all(v==0)) ans <- c(ans,i)
if(all(v[is.finite(v)]==0)) ans <- c(ans,i)
}
names(ans) <- colnames(X)[ans]
ans
Expand Down Expand Up @@ -122,11 +147,12 @@ mclogit <- function(
na.action = na.action,
prior.weights=prior.weights,
weights=weights,
model=mf,
N=N))
if(length(random))
class(fit) <- c("mclogitRandeff","mclogit")
class(fit) <- c("mclogitRandeff","mclogit","lm")
else
class(fit) <- "mclogit"
class(fit) <- c("mclogit","lm")
fit
}

Expand Down Expand Up @@ -228,7 +254,8 @@ mclogit.fit <- function(
null.deviance <- sum(mclogit.dev.resids(Y,P0,w))
resid.df <- length(Y)#-length(unique(s))
model.df <- ncol(X)
phi <- sum(w/P*(Y-P)^2)/(resid.df-model.df)
resid.df <- resid.df - model.df
phi <- sum(w/P*(Y-P)^2)/resid.df
return(list(
coefficients = drop(coef),
linear.predictors = eta,
Expand Down Expand Up @@ -530,7 +557,8 @@ mclogit.fit.random <- function(
B <- as.matrix(B)
resid.df <- length(Y)#-length(unique(s))
model.df <- ncol(X) + length(theta)
phi <- sum(w/P*(Y-P)^2)/(resid.df-model.df)
resid.df <- resid.df-model.df
phi <- sum(w/P*(Y-P)^2)/resid.df
return(list(
coefficients = drop(coef),
varPar = theta,
Expand Down Expand Up @@ -580,10 +608,10 @@ reDesignMatrix <- function(random,data,use=NULL){
gnames <- names(groups)
n <- length(groups[[1]])
nlev <- length(groups)
groups[[1]] <- memisc:::quickInteraction(groups[[1]])
groups[[1]] <- quickInteraction(groups[[1]])
if(nlev>1)
for(i in 2:nlev)
groups[[i]] <- memisc:::quickInteraction(groups[c(i-1,i)])
groups[[i]] <- quickInteraction(groups[c(i-1,i)])
un <- length(attr(groups[[1]],"unique"))
Z <- Matrix(0,nrow=n,ncol=un,dimnames=list(NULL,paste(gnames[1],seq(un),sep="")))
ij <- cbind(1:n,groups[[1]])
Expand Down Expand Up @@ -671,10 +699,14 @@ weights.mclogit <- function(object,...){
return(object$weights)
}

deviance.mclogit <- function(object,...){
return(object$deviance)
}

summary.mclogit <- function(object,dispersion=NULL,correlation = FALSE, symbolic.cor = FALSE,...){

if(!length(dispersion))
dispersion <- object$phi
dispersion <- max(object$phi,1)


## calculate coef table
Expand Down Expand Up @@ -864,7 +896,7 @@ getSummary.mclogit <- function(obj,
})
rownames(coef.groups[[g]]) <- newnames
}
coef.groups <- memisc:::comb.arrays(coef.groups)
coef.groups <- memisc:::clct.arrays(coef.groups)
coef.ungrouped <- coef[ungrouped,]
coef <- array(NA,dim=c(
dim(coef.groups)[1] + nrow(coef.ungrouped)+NROW(varPar),
Expand Down Expand Up @@ -984,4 +1016,5 @@ predict.mclogit <- function(object, newdata,type=c("link","response"),se=FALSE,.
else p
}
else if(se) list(pred=eta,se.pred=se.eta) else eta
}
}

98 changes: 0 additions & 98 deletions data/Transport.R

This file was deleted.

Binary file added data/Transport.rda
Binary file not shown.

0 comments on commit 5dbcce6

Please sign in to comment.