metapop = function (imi,ext,ini,alfa,dim,iffig, animation,nostep) { # This function simulates the proportion of occupied islands # imi - immigration rate # ext - extinction rate # ini - proportion of habitats initially occupied (0 - one individual in the centre) # dim - number of rows of cells (dim^2 is the number of habitats) # iffig - whether to draw a spatial figure # nostep - number of simulation steps if (ini > 0) a=matrix(as.numeric(runif(dim^2)0) / dim^2; n = c(n, nact) a = a * (as.numeric(runif(dim^2)> ext/(1+alfa*ext*nact))) anew = a + (as.numeric(runif(dim^2) < (imi * nact))) a = anew > 0; #plotting if (iffig) { image(a,col=c("white","green"),main=paste(t1)) if (animation) Sys.sleep(0.5) } } n }