Menu

diag() function in the model

Help
dyil
2016-08-08
2016-08-12
  • dyil

    dyil - 2016-08-08

    Hi,
    I am new in using rjags and trying to generate a leslie matrix in the model. When i use the diag() function I get the error: Unknown function: diag. Is there any solution to this rather than generating the matrix in a loop? I tried the loop but it requires couple of more lines when I am trying to fill the off-diagonal cells with zeros. Additionally, I wonder if using a loop would make the model run slower?
    I'd much appreciate any help either using the diag() function or alternatives- generating the leslie matirx within a loop.

    lesM[2:A,1:(A-1)] <- diag(s[2:A,i])

     
  • Martyn Plummer

    Martyn Plummer - 2016-08-09

    No there is no diag() function in the BUGS language (either in OpenBUGS or JAGS). There is no speed penalty for doing it in a loop, although it is quite verbose.

    for (j in 1:(A-1)) {
       lesM[j+1,j] <- s[j+1,i]
       for (k in 1:(j-1)) {
          lesM[j+1,k] <- 0
       }
        for (k in (j+1):(A-1)) {
          lesM[j+1,k] <- 0
       }
    }
    
     
  • dyil

    dyil - 2016-08-12

    Thanks Martyn

     

Log in to post a comment.