kathryntmorrison / inla

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

inla.surv and A matrix problem 2 #15

Closed GoogleCodeExporter closed 9 years ago

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

What is the expected output? What do you see instead?
---------------------------------------------------------
working model
instead:
Error in data.frame(time = c(2.44903693885522, 1.30286351291472, 
0.561343518260757,  : 
  arguments imply differing number of rows: 200, 399

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

Please provide any additional information below.
-----------------------------------------------------------------
There seems to be a problem when the number of observations and covariates are 
not a multiplier (integer) of each other.

Reason seems to be that:
inla.R  uses
inla.interpret.formula which uses
terms.formula  which uses
as.data.frame(data, optional = TRUE)
where data is a list of objects and this will not always work.
ex:
suppose 
A = c(1,2,3)
B = rep(1,6)
listAB = list(A=A,B=B)
WORKS: as.data.frame(listAB, optional = TRUE)

but if 
A = c(1,2,3,4)
FAILS: as.data.frame(listAB, optional = TRUE)

code
------------------------------------

rate = log(1 / 10) # log of lambda
n = 200
n2 = 2*n -1 # if one removes -1 the code works
x <-  cumsum(rnorm(n2) * 0.05) 
i_x = 1:n2
Q = toeplitz(c(2,-1, rep(0,(n2)-3),-1))
Q[1,1] = 1.01 #adding small 0 prior on first observation
Q[n2,n2] = 1
Q[n2,1] = Q[1,n2] = 0

A = matrix(data = 0, ncol = n2, nrow = n)
count = 1
for(i in 1:n){
    A[i,i] = 1
    A[i,count] = 1
    count = count + 2
}
rate_x = exp(A%*%x + rate)  
time_1 <- rexp(n, rate = rate_x) # 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)
data = list(time = time, event = event, x = i_x)
formula <- inla.surv(time,event)  ~ f(x, model="generic", Cmatrix = Q)  - 1 
model   <- inla(formula, family = "exponential" ,data = data, 
control.predictor= list(A=A), debug =FALSE )
data2 <

Original issue reported on code.google.com by jonas.wa...@gmail.com on 9 Dec 2011 at 1:24

GoogleCodeExporter commented 9 years ago
These two issues are aspects of the same problem.

Original comment by finn.lin...@gmail.com on 10 Dec 2011 at 7:49