Greetings all,
I have a question about the proper procedure for examining interactions within the context of a joint likelihood model. The following is example code for a model where the first stage is a 0/1 binary dependent variable, and then the second stage with a continuous dependent variable only for observations where u_i == 1 at the first stage. The basic procedure borrows from the code found in the Blangiardi/Cameletti book. In any case, I wish to generate and then plot marginal effects for an interaction term that is present in both stages of the model. The way that I can get the models with linear combinations (rr and rr2) to run without an error message is to index the linear combinations row-wise by stage (i.e., 1:n, or (n+1:n*2)).
So, I have two (probably rudimentary) questions:
1. Is this procedure correct, or is something different required for the joint likelihood model?
n = 100
u <- (rnorm(n)>0) + 0
y <- rgamma(n,10)
y[u==0] <- NA
idat <- list(Y=matrix(NA,2*n,2))
idat$Y[1:n,1] <- u
idat$Y[n+1:n,2] <- y
idat$mu.u <- rep(1:0, each=n)
idat$mu.y <- rep(0:1, each=n)
idat$u_violation <- c((rnorm(n)>0) + 0, rep(0,n))
idat$y_violation <- c(rep(0,n),idat$u_violation[1:n])
idat$u_revenue <- c(runif(n,0,100), rep(0,n))
idat$y_revenue <- c(rep(0,n),idat$u_revenue[1:n])
form = Y ~ 0 + mu.u + mu.y + u_revenue + y_revenue + u_violation + y_violation +
u_revenue:u_violation + y_revenue:y_violation
r = inla(form,c('binomial', 'gamma'),
data=idat,control.predictor=list(compute=TRUE),verbose=F)
lc_u = inla.make.lincombs(
u_revenue = r$model.matrix[1:n, "u_revenue"],
`u_revenue:u_violation` = r$model.matrix[1:n, "u_revenue:u_violation"])
lc_y = inla.make.lincombs(
y_revenue = r$model.matrix[(n+1):(n*2), "y_revenue"],
`y_revenue:y_violation` = r$model.matrix[(n+1):(n*2), "y_revenue:y_violation"])
rr = inla(form,c('binomial', 'gamma'),
data=idat,control.predictor=list(compute=TRUE),verbose=F,lincomb = lc_u)
rr2 = inla(form,c('binomial', 'gamma'),
data=idat,control.predictor=list(compute=TRUE),verbose=F,lincomb = lc_y)
2. Am I correct in assuming then that the following code then plots the posterior density of the revenue parameter for the first stage of the model, for non-violators and then for violators?
plot(density(rr$summary.lincomb.derived$mean[idat$u_violation[1:100]==0]),ylim=c(0,2))
lines(density(rr$summary.lincomb.derived$mean[idat$u_violation[1:100]==1]),col='red')
thank you for your time.