Hi all,
I'm modeling the probability that a subject attacks or rejects a prey
item based on its proportion of yellow coloration and size. There are
two populations of prey, one defended and the other undefended, so
subjects should reject one type and accept others. Each subject has a
unique rejection threshold that is a line on a contour plot with
coloration and size on the x and y axes. I want to estimate the error
around that line's slope, and believe that I need to estimate two random
slopes per subject to do so, one in the color dimension and the other in
the size dimension. The code that I think I should use to do this is:
glmer(attack ~ prop.color + size + (prop.color + size|subject, family =
binomial), but I cannot find a reference or example for fitting random
slopes in different continuous dimensions. I would appreciate any
pointers in the right direction.
Thanks,
David
In case I've given a poor description of the problem, below is code to
visualize the rejection threshold, using an optimal decision threshold
rather than one estimated from the data:
library(mnormt)
library(lattice)
modelms<- 31.2
mimicms<- 24
sds<- 4*4
modelmc<- 0.7
mimicmc<- 0.4
sdc<- 0.15*0.15
xv<-seq(0,1,0.01)
yv<-seq(10,50,0.1)
ys <- matrix(NA,length(xv),length(coeffs[1,]))
for(i in 1:length(xv)) ys[i,] <-
(coeffs[1,]+coeffs[2,]*xv[i])/(coeffs[3,]*-1)
mu <- c(modelmc,modelms) #model
sigma <- matrix(c(sdc,0,0,sds),2,2)
z1<-NULL
for(x in xv){
f <- dmnorm(cbind(x,yv), mu, sigma)
z1<-rbind(z1,f)
}
contour(xv,yv,z1, nlevels = 5,col = "blue", lty = "solid",
lwd = 1.8,
xlab = "proportion yellow", ylab = "size")
mu <- c(mimicmc,mimicms) #mimic
sigma <- matrix(c(sdc,0,0,sds),2,2)
z2<-NULL
for(x in xv){
f <- dmnorm(cbind(x,yv), mu, sigma)
z2<-rbind(z2,f)
}
contour(xv,yv,z2, nlevels = 5,add = TRUE,col = "red", lty =
"solid", lwd
= 1.8)
contour(xv,yv,z2-z1, nlevels = 1,add = TRUE, col = "black", lty =
"solid", lwd = 2.5)