9

I have some repeated measures, ordinal response data:

dat <- data.frame(
  id = factor(sample(letters[1:5], 50, replace = T)),
  response = factor(sample(1:7, 50, replace = T), ordered = T),
  x1 = runif(n = 50, min = 1, max = 10),
  x2 = runif(n = 50, min = 100, max = 1000)
)

I have built the following model:

library(ordinal)

model <- clmm(response ~ x1 + x2 + (1|id), data = dat)

I have some new data:

new_dat <- data.frame(
  id = factor(sample(letters[1:5], 5, replace = T)),
  x1 = runif(n = 5, min = 1, max = 10),
  x2 = runif(n = 5, min = 100, max = 1000)
)

I want to be able to use the model to predict the probability of each level of dat$response occurring for new_dat, whilst still also accounting for id.

Unfortunately predict() does not work for clmm objects. predict() does work for clmm2 objects but it ignores any random effects included.

What I want to achieve is something similar to what has been done in Figure 3 of the following using this code:

library(ordinal)

fm2 <- clmm2(rating ~ temp + contact, random=judge, data=wine, Hess=TRUE, nAGQ=10)

pred <- function(eta, theta, cat = 1:(length(theta)+1), inv.link = plogis){
Theta <- c(-1e3, theta, 1e3)
sapply(cat, function(j)
inv.link(Theta[j+1] - eta) - inv.link(Theta[j] - eta))
}

mat <- expand.grid(judge = qnorm(0.95) * c(-1, 0, 1) * fm2$stDev,
contact = c(0, fm2$beta[2]),
temp = c(0, fm2$beta[1]))

pred.mat <- pred(eta=rowSums(mat), theta=fm2$Theta)

lab <- paste("contact=", rep(levels(wine$contact), 2), ", ", "temp=", rep(levels(wine$temp), each=2), sep="")

par(mfrow=c(2, 2))

for(k in c(1, 4, 7, 10)) {
plot(1:5, pred.mat[k,], lty=2, type = "l", ylim=c(0,1),
xlab="Bitterness rating scale", axes=FALSE,
ylab="Probability", main=lab[ceiling(k/3)], las=1)
axis(1); axis(2)
lines(1:5, pred.mat[k+1, ], lty=1)
lines(1:5, pred.mat[k+2, ], lty=3)
legend("topright",
c("avg. judge", "5th %-tile judge", "95th %-tile judge"),
lty=1:3, bty="n")
}

Except, my model contains multiple continuous covariates (as opposed to binary factors).

How can I use the model data to predict the probability of each level of dat$response occurring for new_dat, whilst still also accounting for id?

Many thanks.

jrudd
  • 91
  • 2

0 Answers0