inverse function and one-dimensional matrices

Help
2013-11-12
2013-11-14
  • Philipp Doebler

    Philipp Doebler - 2013-11-12

    Dear Martyn, dear JAGS experts,

    the context of my question is a model for meta-analysis of dependent effect sizes. At some point, I want to calculate the inverse of a variance-covariance matrix (to supply to dmnorm later on). So I am using an array for this purpose and a vector that gives the dimension of the current array. A minimal example is as follows:

    model{
    
      for(i in 1:2){
        Omega[i,1:msize[i],1:msize[i]] <- inverse(R[i,1:msize[i],1:msize[i])
      }
    }
    

    Here the data is (as R code):

      R <- array(NA, dim = c(2,2,2))
    
      R[1,1,1] <-1
      R[1,2,2] <-1
      R[1,2,1] <-0.5
      R[1,1,2] <-0.5
    
      R[2,1,1] <-1
      R[2,2,2] <-NA
      R[2,2,1] <-NA
      R[2,1,2] <-NA
    
      msize <- c(2,1)
    

    The trouble is, that inverse does not like one dimensional matrices (only during RUNTIME though): RUNTIME ERROR: Non-conforming parameters in function inverse

    I tried the old step-function trick to emulate an if-statement http://www.mrc-bsu.cam.ac.uk/bugs/faqs/contents.shtml#q15 but the JAGS compiler seems to check the dimension nevertheless.

    I would be very grateful for a work-around that does not involve splitting the data and having two separate likelihoods, as I want to keep the code compact.

    Is there a special reason that inverse does not work on one-dimensional matrices?

    Thanks for reading this far,
    Philipp

     
  • Martyn Plummer

    Martyn Plummer - 2013-11-12

    You must be using a very old version of JAGS. Try upgrading to 3.4.0.

     
  • Philipp Doebler

    Philipp Doebler - 2013-11-14

    Dear Martyn,

    after upgrading to 3.4 the error message is indeed history. Thanks a lot for the quick help so far :)

    Another problem came up though (not sure if I should have started a new thread): If I try to compile a model with a multivariate normal and some of the data is merely one-dimensional, the dmnorm distribution will not work on the special case of one-dimensional data. Here is a minimal example:

    model{
      x ~ dmnorm(0,1)
    }
    

    I understand that this is similar to, say, the implementation in R in the package mvtnorm where

    dmvnorm(1,0,1)
    

    does not work, but

    dmvnorm(1,0,matrix(1,ncol = 1, nrow = 1))
    

    works nicely. Would it be possible to include something like matrix into JAGS? Is there a reason why your dmnorm does not interpret a single double as a 1x1 variance covariance matrix?

    With best wishes,
    Philipp

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks