Skip to content

Commit

Permalink
Release 2.4.3
Browse files Browse the repository at this point in the history
* fix nonmatching matrix dimensions (#63)
* update GH actions: R, ubuntu
  • Loading branch information
pschil authored Sep 4, 2021
2 parents 654081f + 25125eb commit 845b312
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 29 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/Coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@ on:


jobs:
coverage-ubuntu-16-04-R-3-6:
runs-on: ubuntu-16.04
coverage-ubuntu-20-04-R-release:
runs-on: ubuntu-20.04
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
# to install binaries on ubuntu
RSPM: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"
RSPM: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v1
with:
r-version: 3.6
r-version: release

- name: Install system dependencies
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "install.packages(c('remotes'))"
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements(os="ubuntu", os_release="20.04"))')
- name: Install package dependencies
run: |
remotes::install_deps(dependencies = TRUE) # installs binaries
Expand Down
25 changes: 18 additions & 7 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
- {os: windows-latest, r: 'devel'}
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-16.04, r: 'release', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}

steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v1
with:
r-version: ${{ matrix.config.r }}
- name: Query dependencies
Expand All @@ -44,10 +44,10 @@ jobs:
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"
sudo apt-get install -y qpdf # qpdf needed on ubuntu
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install package dependencies
run: |
Expand All @@ -58,5 +58,16 @@ jobs:
shell: Rscript {0}

- name: Check
run: rcmdcheck::rcmdcheck(args = c("--no-tests", "--as-cran", "--no-manual"), error_on = "warning", check_dir = "check")
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-tests", "--as-cran", "--no-manual"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: REndo
Title: Fitting Linear Models with Endogenous Regressors using Latent Instrumental Variables
Type: Package
Version: 2.4.2
Date: 2021-02-09
Version: 2.4.3
Date: 2021-09-03
Authors@R: c(
person(given="Raluca", family="Gui", email = "raluca.gui@business.uzh.ch", role = c("cre","aut")),
person(given="Markus", family="Meierer", email = "markus.meierer@business.uzh.ch", role = "aut"),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# REndo 2.4.3

### BUG FIXES
* In method `multilevelIV` matrices could not be constructed if all groups were of the same size. Thanks to pinson06 for reporting.



# REndo 2.4.2

### BUG FIXES
Expand Down
4 changes: 2 additions & 2 deletions R/f_multilevel_2levels.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ multilevel_2levels <- function(cl, f.orig, dt.model.data, res.VC,
# Qsc = i(Tsc) - Wsc*Zsc*ginv(Zsc`*Wsc*Wsc*Zsc)*Zsc`*Wsc;
#
# Move the diagonal outside as the blocks are all square and therefore the diagnoal is the same
l.Q <- mapply(l.Z2, l.W, FUN = function(g.z2, g.w){
l.Q <- mapply(l.Z2, l.W, SIMPLIFY = FALSE, FUN = function(g.z2, g.w){
g.w %*% g.z2 %*% corpcor::pseudoinverse(Matrix::crossprod(g.z2, g.w) %*% g.w %*% g.z2) %*%
Matrix::crossprod(g.z2, g.w)
})
})

Q <- Matrix::Diagonal(x=1, n=nrow(W)) - Matrix::bdiag(l.Q)

Expand Down
10 changes: 6 additions & 4 deletions R/f_multilevel_3levels.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ multilevel_3levels <- function(cl, f.orig, dt.model.data, res.VC,

# . Q at L3 level ------------------------------------------------------------------------------------
# Move the diagonal outside as the blocks are all square and therefore the diagonal is the same
l.L3.Q <- mapply(l.L3.Z3, l.L3.W, FUN = function(g.z3, g.w3){
l.L3.Q <- mapply(l.L3.Z3, l.L3.W, SIMPLIFY = FALSE, FUN = function(g.z3, g.w3){
g.w3 %*% g.z3 %*% corpcor::pseudoinverse(Matrix::crossprod(g.z3, g.w3) %*% g.w3 %*% g.z3) %*%
Matrix::crossprod(g.z3, g.w3)
})
})

L3.Q <- Matrix::Diagonal(x=1, n=nrow(W)) - Matrix::bdiag(l.L3.Q)


Expand All @@ -144,9 +145,10 @@ multilevel_3levels <- function(cl, f.orig, dt.model.data, res.VC,
name.split.by=name.split.by.L2)

# Move the diagonal outside as the blocks are all square and therefore the diagnoal is the same
l.L2.Q <- mapply(l.L2.Z2, l.L2.W, FUN = function(g.z2, g.w2){
l.L2.Q <- mapply(l.L2.Z2, l.L2.W, SIMPLIFY = FALSE, FUN = function(g.z2, g.w2){
g.w2 %*% g.z2 %*%corpcor::pseudoinverse(t(g.z2)%*%(g.w2%*%g.w2)%*%g.z2) %*% Matrix::crossprod(g.z2, g.w2)
})
})

L2.Q <- Matrix::Diagonal(x=1, n=nrow(W)) - Matrix::bdiag(l.L2.Q)

# Calc P -------------------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions R/f_multilevel_omittedvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ multilevel_omittedvartest <- function(IV1, IV2,

# Residuals ----------------------------------------------------------------------------
m.coef.IV1 <- matrix(data = coef.IV1, ncol=1)
l.Lhighest.resid.e <- mapply(l.Lhighest.y, l.Lhighest.X, FUN=function(g.y,g.x){
g.y - g.x %*% m.coef.IV1})
l.Lhighest.resid.e <- mapply(l.Lhighest.y, l.Lhighest.X, SIMPLIFY = FALSE, FUN=function(g.y,g.x){
g.y - g.x %*% m.coef.IV1
})

# resid * resid' in blocks
V.hat <- Matrix::tcrossprod(Matrix::bdiag(l.Lhighest.resid.e))

Expand Down
8 changes: 4 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Comment from the authors
This is version 2.4.2 which fixes 2 bugs in the copulaCorrection method for 1 endogenous regressor where the implementation deviated from the formula.
This is version 2.4.3 which fixes 1 bug in the multilevelIV method where matrices could not be constructed if all groups were of the same size.


## Test environments
* local install on OS X 10.15.17, R 4.0.1, devtools 2.3.2
* local install on OS X 10.15.7, R 4.0.4, devtools 2.4.2
* github actions: win, osx, linux (release and devel)
* win-builder (rdevel, release)
(* rhub is currently not working)
* win-builder: release and devel
* rhub: check_for_cran

## R CMD check results
There were 0 ERRORs, 0 WARNINGs, and 1-3 insignificant NOTEs (mis-spellings, invalid DOI).
Expand Down
5 changes: 5 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// copulaCorrection_LL_rcpp
double copulaCorrection_LL_rcpp(const NumericVector& params, const NumericVector& vec_y, const NumericMatrix& m_data_exo_endo, const NumericVector& vec_data_endo_pstar, const IntegerVector& param_pos_data, const int& param_pos_sigma, const int& param_pos_rho);
RcppExport SEXP _REndo_copulaCorrection_LL_rcpp(SEXP paramsSEXP, SEXP vec_ySEXP, SEXP m_data_exo_endoSEXP, SEXP vec_data_endo_pstarSEXP, SEXP param_pos_dataSEXP, SEXP param_pos_sigmaSEXP, SEXP param_pos_rhoSEXP) {
Expand Down
35 changes: 35 additions & 0 deletions tests/testthat/pinson06_rankdeficient_samesizegroup.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
album_id,y,e,f,a,w,l,w2,w_l,f_l,e_l,e_w,a_w,a_l,a_e,e_w_l,f_w_l,f_a_l,f_e_l,a_w_l,f_a_e_l,pr,v,t
3,4.86,0.44,0.65,-1.01,-8,0,64,0,0,0,-3.50,8.06,0,-0.44,0,0,0,0,0,0,-0.75,-1.75,1.95
3,4.83,0.44,0.65,-1.01,-7,0,49,0,0,0,-3.06,7.05,0,-0.44,0,0,0,0,0,0,-0.75,-1.75,1.95
3,4.80,0.44,0.65,-1.01,-6,0,36,0,0,0,-2.63,6.04,0,-0.44,0,0,0,0,0,0,-0.67,-1.75,1.95
3,4.80,0.44,0.65,-1.01,-5,0,25,0,0,0,-2.19,5.04,0,-0.44,0,0,0,0,0,0,-0.29,-1.75,1.95
3,4.76,0.44,0.65,-1.01,-4,0,16,0,0,0,-1.75,4.03,0,-0.44,0,0,0,0,0,0,-0.75,-1.75,1.95
3,4.71,0.44,0.65,-1.01,-3,0,9,0,0,0,-1.31,3.02,0,-0.44,0,0,0,0,0,0,-0.75,-1.75,1.95
3,4.67,0.44,0.65,-1.01,-2,0,4,0,0,0,-0.88,2.01,0,-0.44,0,0,0,0,0,0,-0.67,-1.75,1.95
3,5.00,0.44,0.65,-1.01,-1,0,1,0,0,0,-0.44,1.01,0,-0.44,0,0,0,0,0,0,-0.29,-1.75,1.95
3,8.45,0.44,0.65,-1.01,0,1,0,0,0.65,0.44,0,0,-1.01,-0.44,0,0,-0.65,0.28,0,-0.29,-0.29,-1.75,1.95
3,7.87,0.44,0.65,-1.01,1,1,1,1,0.65,0.44,0.44,-1.01,-1.01,-0.44,0.44,0.65,-0.65,0.28,-1.01,-0.29,-0.60,-1.75,1.95
3,7.78,0.44,0.65,-1.01,2,1,4,2,0.65,0.44,0.88,-2.01,-1.01,-0.44,0.88,1.30,-0.65,0.28,-2.01,-0.29,-0.60,-1.75,1.95
3,7.81,0.44,0.65,-1.01,3,1,9,3,0.65,0.44,1.31,-3.02,-1.01,-0.44,1.31,1.95,-0.65,0.28,-3.02,-0.29,-0.67,-1.75,1.95
3,7.79,0.44,0.65,-1.01,4,1,16,4,0.65,0.44,1.75,-4.03,-1.01,-0.44,1.75,2.60,-0.65,0.28,-4.03,-0.29,-0.67,-1.75,1.95
3,7.69,0.44,0.65,-1.01,5,1,25,5,0.65,0.44,2.19,-5.04,-1.01,-0.44,2.19,3.25,-0.65,0.28,-5.04,-0.29,-0.67,-1.75,1.95
3,7.63,0.44,0.65,-1.01,6,1,36,6,0.65,0.44,2.63,-6.04,-1.01,-0.44,2.63,3.89,-0.65,0.28,-6.04,-0.29,-0.67,-1.75,1.95
3,7.57,0.44,0.65,-1.01,7,1,49,7,0.65,0.44,3.06,-7.05,-1.01,-0.44,3.06,4.54,-0.65,0.28,-7.05,-0.29,-0.67,-1.75,1.95
3,7.60,0.44,0.65,-1.01,8,1,64,8,0.65,0.44,3.50,-8.06,-1.01,-0.44,3.50,5.19,-0.65,0.28,-8.06,-0.29,-0.52,-1.75,1.95
4,1.42,-0.86,0.83,-0.47,-8,0,64,0,0,0,6.85,3.75,0,0.40,0,0,0,0,0,0,0.31,-0.41,0.07
4,1.49,-0.86,0.83,-0.47,-7,0,49,0,0,0,5.99,3.28,0,0.40,0,0,0,0,0,0,0.31,-0.41,0.07
4,1.84,-0.86,0.83,-0.47,-6,0,36,0,0,0,5.14,2.81,0,0.40,0,0,0,0,0,0,-0.44,-0.41,0.07
4,1.45,-0.86,0.83,-0.47,-5,0,25,0,0,0,4.28,2.35,0,0.40,0,0,0,0,0,0,0.31,-0.41,0.07
4,1.09,-0.86,0.83,-0.47,-4,0,16,0,0,0,3.42,1.88,0,0.40,0,0,0,0,0,0,-0.44,-0.41,0.07
4,1.26,-0.86,0.83,-0.47,-3,0,9,0,0,0,2.57,1.41,0,0.40,0,0,0,0,0,0,1.80,-0.41,0.07
4,1.69,-0.86,0.83,-0.47,-2,0,4,0,0,0,1.71,0.94,0,0.40,0,0,0,0,0,0,1.05,-0.41,0.07
4,1.61,-0.86,0.83,-0.47,-1,0,1,0,0,0,0.86,0.47,0,0.40,0,0,0,0,0,0,0.31,-0.41,0.07
4,2.50,-0.86,0.83,-0.47,0,1,0,0,0.83,-0.86,0,0,-0.47,0.40,0,0,-0.39,-0.71,0,0.33,1.05,-0.41,0.07
4,1.98,-0.86,0.83,-0.47,1,1,1,1,0.83,-0.86,-0.86,-0.47,-0.47,0.40,-0.86,0.83,-0.39,-0.71,-0.47,0.33,0.31,-0.41,0.07
4,1.89,-0.86,0.83,-0.47,2,1,4,2,0.83,-0.86,-1.71,-0.94,-0.47,0.40,-1.71,1.67,-0.39,-0.71,-0.94,0.33,1.05,-0.41,0.07
4,1.58,-0.86,0.83,-0.47,3,1,9,3,0.83,-0.86,-2.57,-1.41,-0.47,0.40,-2.57,2.50,-0.39,-0.71,-1.41,0.33,1.05,-0.41,0.07
4,1.71,-0.86,0.83,-0.47,4,1,16,4,0.83,-0.86,-3.42,-1.88,-0.47,0.40,-3.42,3.33,-0.39,-0.71,-1.88,0.33,1.05,-0.41,0.07
4,1.56,-0.86,0.83,-0.47,5,1,25,5,0.83,-0.86,-4.28,-2.35,-0.47,0.40,-4.28,4.16,-0.39,-0.71,-2.35,0.33,1.05,-0.41,0.07
4,1.26,-0.86,0.83,-0.47,6,1,36,6,0.83,-0.86,-5.14,-2.81,-0.47,0.40,-5.14,5.00,-0.39,-0.71,-2.81,0.33,0.31,-0.41,0.07
4,1.36,-0.86,0.83,-0.47,7,1,49,7,0.83,-0.86,-5.99,-3.28,-0.47,0.40,-5.99,5.83,-0.39,-0.71,-3.28,0.33,-0.44,-0.41,0.07
4,1.04,-0.86,0.83,-0.47,8,1,64,8,0.83,-0.86,-6.85,-3.75,-0.47,0.40,-6.85,6.66,-0.39,-0.71,-3.75,0.33,0.31,-0.41,0.07
14 changes: 14 additions & 0 deletions tests/testthat/test-runability_multilevel.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,17 @@ test_that("Works with slopes as factors and chars", {
X31 + X32 + X33 + factorSLP+(0+factorSLP| SID) | endo(X15),
data = dataMultilevelIV, verbose = FALSE), regexp = "singular")
})

test_that("Works with rank-deficient and all same-size groups, see issue #63",{
#Model specification and example data from pinson06
skip_on_cran()

# Is in tests/testthat folder
df.data.pinson06 <- read.csv("pinson06_rankdeficient_samesizegroup.csv", header=TRUE)
expect_message(multilevelIV(formula = y ~ e + a + f + w + l + w2 + w_l + f_l + e_l + e_w + a_w + a_l + a_e +
e_w_l + f_w_l + f_a_l + f_e_l + a_w_l + f_a_e_l + v + pr + t +
(1 | album_id) | endo(e,a,f),
data = df.data.pinson06, verbose=FALSE),
regexp = "matrix is rank deficient")

})

0 comments on commit 845b312

Please sign in to comment.