Skip to content

Commit

Permalink
Fixed bug in 'blockMatrix' and make it check for argument validity
Browse files Browse the repository at this point in the history
  • Loading branch information
melff committed Apr 14, 2022
1 parent dadb418 commit c6cbf56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/DESCRIPTION
@@ -1,8 +1,8 @@
Package: mclogit
Type: Package
Title: Multinomial Logit Models, with or without Random Effects or Overdispersion
Version: 0.9.4.1
Date: 2022-04-11
Version: 0.9.4.2
Date: 2022-04-14
Author: Martin Elff
Maintainer: Martin Elff <mclogit@elff.eu>
Description: Provides estimators for multinomial logit models in their
Expand Down
20 changes: 19 additions & 1 deletion pkg/R/blockMatrices.R
@@ -1,6 +1,24 @@
blockMatrix <- function(x=list(),nrow=1,ncol=1){
all_equal <- function(x) length(unique(x)) == 1

blockMatrix <- function(x=list(),nrow,ncol,horizontal=TRUE){
if(!is.list(x)) x <- list(x)
if(horizontal){
if(missing(nrow)) nrow <- 1
if(missing(ncol)) ncol <- length(x)
}
else {
if(missing(nrow)) nrow <- length(x)
if(missing(ncol)) ncol <- 1
}
y <- matrix(x,nrow=nrow,ncol=ncol)
ncols <- apply(y,1:2,ncol)
nrows <- apply(y,1:2,nrow)
ncols <- array(sapply(y,ncol),dim=dim(y))
nrows <- array(sapply(y,nrow),dim=dim(y))
nrows_equal <- apply(nrows,1,all_equal)
ncols_equal <- apply(ncols,2,all_equal)
if(!all(nrows_equal)) stop("Non-matching numbers of rows")
if(!all(ncols_equal)) stop("Non-matching numbers of columns")
structure(y,class="blockMatrix")
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/inst/ChangeLog
@@ -1,3 +1,6 @@
2022-04-13:
- Fixed bug in 'blockMatrix' and make it check for argument validity

2022-04-11:
- Hotfix of prediction method

Expand Down

0 comments on commit c6cbf56

Please sign in to comment.