[R-br] Problemas com o R
Ana Lúcia Souza Silva Mateus
anawilson.ufam em gmail.com
Sexta Junho 22 12:27:17 BRT 2012
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!!
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20120622/8c920cad/attachment.html>
-------------- Próxima Parte ----------
1 3 1
1 6 1
1 7 1
2 1 1
2 2 1
3 2 1
5 5 1
2 4 2
2 7 2
4 1 2
4 3 2
4 7 2
5 5 2
1 1 3
4 7 4
2 2 5
4 3 6
2 3 7
1 1 8
1 2 8
1 5 8
2 1 8
2 7 8
5 3 8
5 5 8
1 4 9
2 5 9
2 6 9
3 6 9
4 7 10
5 3 11
4 1 12
4 2 13
2 1 14
1 4 15
2 5 15
3 4 15
5 5 15
5 7 15
3 2 16
3 3 16
3 6 16
5 4 16
6 6 16
2 4 17
5 1 18
5 4 19
4 7 20
3 5 21
5 7 22
4 3 23
Mais detalhes sobre a lista de discussão R-br