Segue o script e os dados em anexo.<br><br>event=Caso22<br>x <- c(0,6,6,0)<br>y <- c(0,0,8,8)<br>poly=cbind(x,y)<br>s=seq(1,5,1)<br>tm=seq(1,5,1)<br><br>anaksenv<-function(event, poly, s, tm, nsim = 10){<br>#<br># This function implements monte-carlo simulations<br>
# to create and plot simulation envelopes to test <br># against the hypothesis of complete temporal randomness (CTR)<br># of an observed spatial-temporal point pattern.<br># It uses the spatial k-function and the cramer-vonMises measure of distance.<br>
# <br># OBS: You need splancs loaded<br>#<br># Where:<br># - event: A 3xn matrix that contains the coordinates and times of the events<br># - poly: A polygon enclosing the points<br># - s: A vector of spatial distances for the analysis.<br>
# - tm: A vector of times for the analysis<br># - nsim: Number of monte-carlo simulations<br>#<br>#<br> library(splancs)<br>#<br># Starting values<br>#<br> x<-event[,1]<br> y<-event[,2]<br> t<-event[,3]<br>
maxx<-max(x)<br> maxy<-max(y)<br> minx<-min(x)<br> miny<-min(y)<br> lent<-length(x)<br> pontos<-cbind(x,y)<br> tl<-cbind(min(t),max(t))<br>#<br># Get the K-function for space and time of the observed point pattern<br>
# <br> ksto <- stkhat(pts=pontos, times=t, poly=poly, tlimits=tl, s=s, tm=tm)<br> ko <- ksto$ks<br># <br># Doing Monte-Carlo simulation under the CSR<br># <br> hold<-matrix(0,nsim,length(s))<br> for(i in (1:nsim)) {<br>
tt<-floor(runif(lent,min(t),max(t)))<br> xx<-floor(runif(lent,minx,maxx))<br> yy<-floor(runif(lent,miny,maxy))<br> pont<-cbind(xx,yy)<br> tll<-cbind(min(tt),max(tt))<br> kstmc<-stkhat(pts=pont, times=tt, poly=poly, tlimits=tll, s=s, tm=tm)<br>
kko<-kstmc$ks<br> hold[i,]<-kko<br>}<br>#<br> up<- apply(hold,2,max)<br> dow<- apply(hold,2,min)<br>#<br># Creating plot<br># <br> par(pty = "s")<br> plot(s, up, type = "n", xlab = "Distância", ylab = "Função K espacial")<br>
lines(s, ko, col="blue")<br> lines(s, up, lty=2, col="red")<br> lines(s, dow,lty=2,col="red") <br>}<br><br>Desde já muito obrigada!!<br><br><br><br>