I'm hoping someone might have some tips for me on modeling prediction surfaces for nest survival models. Using the code from the mallard example, I am able to plot the prediction surface for a model with 2 explanatory variables. However, I am struggling to extend it to the case of a model with 3 variables. The code below plots the model: ~fail+elevation, where fail is a 4 level factor and elevation is continuous. I'm trying to plot the model: ~fail+elevation+init, where init is also continuous, plotting the first two variables and holding init constant at its mean value. No adjustments I've made to the code have accomplished this successfully. If anyone has any tips, or other code that has worked for them, it would be much appreciated!
Thank you!
Kristen
- Code: Select all
failelev=rfwa2.results$failstage.elevation
fc<-find.covariates(failelev, rfwa2)
seq.elevation <- seq(1799, 2779, by=10)
seq.fail<-c(1,2,3,4)
point <- matrix(nrow=4, ncol=length(seq.elevation))
lower <- matrix(nrow=4, ncol=length(seq.elevation))
upper <- matrix(nrow=4, ncol=length(seq.elevation))
colnum<-0
for (ielevation in seq.elevation) {
fc$value[1:4]=ielevation
colnum <- colnum + 1
fc$value[fc$var=="stagefailed"]=seq.fail
design=fill.covariates(failelev,fc)
point[,colnum] <- compute.real(failelev,design=design)[,"estimate"]
lower[,colnum] <- compute.real(failelev,design=design)[,"lcl"]
upper[,colnum] <- compute.real(failelev,design=design)[,"ucl"]
}
library(rgl)
open3d()
bg3d("white")
material3d(col="black")
persp3d(seq.fail, seq.elevation, point, aspect=c(1, 1, 0.5), col = "lightblue",
xlab = "stage", ylab = "elevation", zlab = "DSR", zlim=range(c(upper,lower)),
main="Daily survival rate")