show.plot AHM书

时间:2018-07-13 14:43:49

标签: r

我正在从《生态学中的应用层次建模》一书中运行某些模型,但出现此错误:

  

错误:找不到对象“ show.plot”。

我知道show.plot不是对象而是函数...这是给我麻烦的代码部分:

data.fn <- function(M = 267, J = 3, mean.lambda = 2, beta1 = -2, beta2 = 2, 
beta3 = 1,
                mean.detection = 0.3, alpha1 = 1, alpha2 = -3, alpha3 = 0, 
show.plot = TRUE){
elev <- runif(n = M, -1, 1) # Scaled elevation
forest <- runif(n = M, -1, 1) # Scaled forest cover
wind <- array(runif(n = M *J, -1, 1), dim = c(M, J)) # Scaled wind speed
# Model for abundance
beta0 <- log(mean.lambda) # Mean abundance on link scale
lambda <- exp(beta0 + beta1*elev + beta2*forest + beta3*elev*forest)
N <- rpois(n = M, lambda = lambda) # Realised abundance
Ntotal <- sum(N) # Total abundance (all sites)
psi.true <- mean(N>0) # True occupancy in sample
# Plots
if(show.plot){
par(mfrow = c(2, 2), cex.main = 1)
devAskNewPage(ask = TRUE)
curve(exp(beta0 + beta1*x), -1, 1, col = "red", main = "Relationship lambda- 
elevation
      \nat average forest cover", frame.plot = F, xlab = "Scaled elevation")
plot(elev, lambda, xlab = "Scaled elevation", main = "Relationship lambda- 
elevation
     \nat observed forest cover", frame.plot = F)
curve(exp(beta0 + beta2*x), -1, 1, col = "red", main = "Relationship lambda- 
forest \ncover
      at average elevation", xlab = "Scaled forest cover", frame.plot = F)
plot(forest, lambda, xlab = "Scaled forest cover", main = "Relationship 
lambda-forest
     cover \nat observed elevation", frame.plot = F)
 }

谢谢!

0 个答案:

没有答案