Hello,
I have this r code and i want to create a shiny in order to change pcolonisation and pextinction parameters but i don't succeed.
Thank you so much !
metapop_2<-function(temps=seq(1,20), riviere=seq(1,100), pcolonisation=0.9, pextinction=0.9){
occupation<-matrix(data=0,length(riviere),length(temps))
occupation[floor(runif(1)*length(riviere)),1]<-1
for(t in seq(1,(max(temps)-1)))
for(x in riviere[min(riviere):max(riviere)])
{
if(occupation[x,t]==0)
occupation[x,t+1]<-rbinom(1,1,pcolonisation*sum(occupation[,t])/length(riviere))
if(occupation[x,t]==1)
occupation[x,t+1]<-rbinom(1,1,1-pextinction)
}
windows(width=800, height=400)
par(mfrow=c(1,2))
image(riviere,temps,occupation,xlab="Point de la rivière", ylab="Année", col=grey(seq(1,0,-1/max(occupation))))
abline(h=temps-0.5,v=riviere-0.5)
plot(temps,colSums(occupation)/length(riviere),type="b", ylab="Proportion de sites occupés")
}
metapop_2()