grantbrown / inla

Automatically exported from code.google.com/p/inla
5 stars 6 forks source link

error: running inla iwth inla.surv and A matrix #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
---------------------------------------------------
see code below

What is the expected output? What do you see instead?
---------------------------------------------------
EXPCTED: An inla model.
INSTEAD:
Error: length(yy) == MPredictor is not TRUE

What version of the product are you using? On what operating system?
---------------------------------------------------
    INLA build date ...: Wed Dec 7 09:37:12 CET 2011 
    Revision...........: hgid: 74fcd284508c date: Wed Dec 07 09:30:34 2011 +0100 

Please provide any additional information below.
---------------------------------------------------
The error appears to come from line 976:
stopifnot(length(yy) == MPredictor)
Where yy is an list with 5 objects so length(yy)=5
what I belive it should be is for example:
stopifnot(length(yy$time) == MPredictor)

---------------------------------------------------
Jonas Wallin 
jonas.wallin81@gmail.com

code:

---------------------------------------------------

rm(list=ls())
library(INLA)
graphics.off()
n = 200
Q = toeplitz(c(2,-1, rep(0,n-3),-1))
Q[1,1] = 1.1 #adding small 0 prior on first observation
Q[n,n] = 1
Q[n,1] = Q[1,n] = 0
rate = log(1 / 10) # log of lambda
x <-  cumsum(rnorm(n) * 0.05) 
rate_x <- exp(x + rate)

x2 <- cumsum(rnorm(n) * 0.1)
index_x2 = seq(1,n,4)
rate_x2            = rate_x
rate_x2[index_x2] <- rate_x[index_x2] * exp(x2[index_x2])

time_1 <- rexp(n, rate = rate_x2) # time of death
time_2 <- rexp(n, rate = exp(rate)) # censor time
event = (time_1 <= time_2 ) * 1
time = apply(cbind(time_1,time_2),1,min)

A = matrix(data = 0, ncol = 2*n, nrow = n)
A[,1:n] = diag(1, nrow = n)
xdiag_2 = rep(0,n)
xdiag_2[index_x2]  = 1
A[,n+(1:n)] = diag(xdiag_2)

i_x2 <- c(rep(NA,n),1:n)
i_x <- c(1:n,rep(NA,n))
data = list(time = time, event = event, i_x2 = i_x2, i_x = i_x)
formula <- inla.surv(time,event)  ~ f(i_x, model="generic", Cmatrix = Q) + 
f(i_x2, model="generic", Cmatrix = Q) - 1   
model   <- inla(formula, family = "exponential" ,data = data, 
control.predictor= list(A=A), debug =TRUE )

Original issue reported on code.google.com by jonas.wa...@gmail.com on 7 Dec 2011 at 3:32

GoogleCodeExporter commented 9 years ago
Fixed. Thanks...

Original comment by h...@r-inla.org on 7 Dec 2011 at 5:19

GoogleCodeExporter commented 9 years ago
The change for this is done now.

Original comment by havard.rue on 7 Dec 2011 at 5:21