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