Patrones puntuales

Author

Martha Bohorquez

Paquete spatstat

install.packages(c("spatstat", "spatstat.explore", "spatstat.model"))
Installing packages into '/cloud/lib/x86_64-pc-linux-gnu-library/4.6'
(as 'lib' is unspecified)
library(spatstat)
Loading required package: spatstat.data
Loading required package: spatstat.univar
spatstat.univar 3.1-7
Loading required package: spatstat.geom
spatstat.geom 3.7-3
Loading required package: spatstat.random
spatstat.random 3.4-5
Loading required package: spatstat.explore
Loading required package: nlme
spatstat.explore 3.8-0
Loading required package: spatstat.model
Loading required package: rpart
spatstat.model 3.7-0
Loading required package: spatstat.linnet
spatstat.linnet 3.5-0

spatstat 3.6-0 
For an introduction to spatstat, type 'beginner' 
options(repr.plot.width = 7, repr.plot.height = 7) # Tamaño gráficos

Lectura, creación y ubicación del patrón puntual

Lectura del borde de la región de interés y creación de la ventana que contiene el patrón de puntos

colomb <- read.table("clockwise4_colombia.txt")
plot(colomb)

cx<-colomb[,1]
cx<-as.vector(cx)
cy<-colomb[,2]
cy<-as.vector(cy)
poli<-owin(poly=list(x=cx, y=cy), unitname=c("Metro", "Metros"))
plot(poli)

Creación del objeto ppp en la ventana que contiene (aprox) los eventos registrados

sismos <- read.table("SismosPlanas.txt")
head(sismos)
       V1      V2
1 1108059 1243818
2 1038521 1075627
3 1108054 1246031
4 1104729 1250448
5 1101427 1242699
6 1124651 1240536
sismospp<-ppp(sismos[,1],sismos[,2],window=poli)
Warning: 16 points were rejected as lying outside the specified window
Warning: data contain duplicated points
summary(sismospp)
Warning in diff(xrange) * diff(yrange): NAs produced by integer overflow
Planar point pattern:  371 points
Average intensity 3.285698e-10 points per square Metro

*Pattern contains duplicated points*

Coordinates are given to 3 decimal places
i.e. rounded to the nearest multiple of 0.001 Metros

Window: polygonal boundary
single connected closed polygon with 216 vertices
enclosing rectangle: [452302, 1801101] x [68566, 1870203] Metros
                     (1349000 x 1802000 Metros)
Window area = 1.12914e+12 square Metros
Unit of length: 1 Metro
Fraction of frame area: NA

*** 16 illegal points stored in attr(,"rejects") ***

Gráfico de las ubicaciones que forma el patrón observado (muestreado)

plot(sismospp, main="")
Warning in plot.ppp(sismospp, main = ""): 16 illegal points also plotted
title("Patrón de sismos en Colombia (julio-diciembre 2008)", cex.main = 1, font.main= 2, col.main= "blue")

prueba_chi <- quadrat.test(sismospp)
Warning: Some expected counts are small; chi^2 approximation may be inaccurate
plot(quadrat.test(sismospp),cex=0.4)
Warning: Some expected counts are small; chi^2 approximation may be inaccurate

prueba_chi <- quadrat.test(sismospp)
Warning: Some expected counts are small; chi^2 approximation may be inaccurate
prueba_chi

    Chi-squared test of CSR using quadrat counts

data:  sismospp
X2 = 2359.8, df = 20, p-value < 2.2e-16
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
prueba_chi_2 <- quadrat.test(sismospp,method="MonteCarlo",CR=-2)
prueba_chi_1 <- quadrat.test(sismospp,method="MonteCarlo",CR=-1)
prueba_chi_05 <- quadrat.test(sismospp,method="MonteCarlo",CR=-1/2)
prueba_chi_1_3 <- quadrat.test(sismospp,method="MonteCarlo",CR=1/3)
prueba_chi_2_3 <- quadrat.test(sismospp,method="MonteCarlo",CR=2/3)
prueba_chi_1 <- quadrat.test(sismospp,method="MonteCarlo",CR=1)

prueba_chi_2

    Conditional Monte Carlo test of CSR using quadrat counts
    Test statistic: Neyman modified X2 statistic NM2

data:  sismospp
NM2 = 97.494, p-value = 0.001
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
prueba_chi_1

    Conditional Monte Carlo test of CSR using quadrat counts
    Test statistic: Pearson X2 statistic

data:  sismospp
X2 = 2359.8, p-value = 0.001
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
prueba_chi_05

    Conditional Monte Carlo test of CSR using quadrat counts
    Test statistic: Freeman-Tukey statistic T2

data:  sismospp
T2 = 1229.7, p-value = 0.001
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
prueba_chi_1_3

    Conditional Monte Carlo test of CSR using quadrat counts
    Test statistic: Cressie-Read statistic (lambda = 0.333333333333333)

data:  sismospp
CR = 1315.4, p-value = 0.001
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
prueba_chi_2_3

    Conditional Monte Carlo test of CSR using quadrat counts
    Test statistic: Cressie-Read statistic (lambda = 2/3)

data:  sismospp
CR = 1694, p-value = 0.001
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
prueba_chi_1

    Conditional Monte Carlo test of CSR using quadrat counts
    Test statistic: Pearson X2 statistic

data:  sismospp
X2 = 2359.8, p-value = 0.001
alternative hypothesis: two.sided

Quadrats: 21 tiles (irregular windows)
Distodas <- pairdist(sismospp)
Distodas[1:5, 1:8]
           [,1]     [,2]       [,3]       [,4]       [,5]      [,6]      [,7]
[1,]      0.000 181999.2   2212.122   7418.913   6725.055  16913.27  16627.71
[2,] 181999.174      0.0 184043.701 186937.812 178522.368 186046.29 197032.63
[3,]   2212.122 184043.7      0.000   5529.249   7416.962  17482.05  14421.24
[4,]   7418.913 186937.8   5529.249      0.000   8422.764  22251.13  10197.04
[5,]   6725.055 178522.4   7416.962   8422.764      0.000  23323.57  18539.85
          [,8]
[1,]  19900.96
[2,] 190531.63
[3,]  20023.13
[4,]  24146.16
[5,]  26557.69
nndista <- nndist(sismospp)
nndista[1:10]
 [1]  1105.575  1108.525     0.000  1563.765  1106.041     0.000  5635.643
 [8]     0.000  2472.937 15720.041
NN_1=nnwhich(nndista)
head(NN_1)
[1]  2  1  6 11  2  8
NN_2=nnwhich(nndista,k=2)
head(NN_2)
[1]  5  5  8 16  1  3
plot(nnmap(sismospp, 2, what="dist"),main="")

stienen(sismospp, border=list(bg=NULL, lwd=2, cols="red"))
plot(sismospp,cex=0.2,add=T)
Warning in plot.ppp(sismospp, cex = 0.2, add = T): 16 illegal points also
plotted

plot(dirichlet(sismospp))
Warning: 74 duplicated points were removed
plot(sismospp,cex=0.2,add=T)
Warning in plot.ppp(sismospp, cex = 0.2, add = T): 16 illegal points also
plotted

CE_sismos <- clarkevans.test(sismospp)
CE_sismos

    Clark-Evans test
    CDF correction
    Z-test

data:  sismospp
R = 0.30488, p-value < 2.2e-16
alternative hypothesis: two-sided
bordeCorCE<-clarkevans(sismospp)
bordeCorCE
    naive       cdf 
0.3317005 0.3048790 
bordeCorCE_n<-clarkevans(sismospp, correction="none")
bordeCorCE_n
[1] 0.3317005
bordeCorHE<-hopskel(sismospp)
bordeCorHE
[1] 0.004522184
HE_sismos_2=hopskel.test(sismospp)
HE_sismos_clust=hopskel.test(sismospp,alternative="clustered")
HE_sismos_reg=hopskel.test(sismospp,alternative="regular")
HE_sismos_2

    Hopkins-Skellam test of CSR
    using F distribution

data:  sismospp
A = 0.0048174, p-value < 2.2e-16
alternative hypothesis: two-sided
HE_sismos_clust

    Hopkins-Skellam test of CSR
    using F distribution

data:  sismospp
A = 0.0056189, p-value < 2.2e-16
alternative hypothesis: clustered (A < 1)
HE_sismos_reg

    Hopkins-Skellam test of CSR
    using F distribution

data:  sismospp
A = 0.0048705, p-value = 1
alternative hypothesis: regular (A > 1)
plot(density(sismospp))
contour(density(sismospp), add=TRUE)
title("Estimación de la intensidad de sismos en Colombia (julio-diciembre 2008)",cex.main = 1,font.main= 2,col.main= "black")

lambda_s=density(sismospp)
plot(Kest(sismospp,correction="border"))  ########error#######

Kenvel=envelope(sismospp,Kest,nsim=499,correction="border") ########error#######
Generating 499 simulated realisations of CSR  ...
1, 2, 3, .5....10....15....20....25....30....35....40....45....50..
..55....60....65....70....75....80....85....90....95....100....105....110
....115....120....125....130....135....140....145....150....155....160....165...
.170....175....180....185....190....195....200....205....210....215....220....225.
...230....235....240....245....250....255....260....265....270....275....280....
285....290....295....300....305....310....315....320....325....330....335....340..
..345....350....355....360....365....370....375....380....385....390....395....400
....405....410....415....420....425....430....435....440....445....450....455...
.460....465....470....475....480....485....490....495...
499.

Done.
plot(Kenvel)

KestEval=Kest(sismospp,correction="border")
Kfuncion=as.function(KestEval)
Kfuncion(50000)
[1] 423995827307
Kfuncion(300000)
[1] 646153464342
K_sismos_NH=Kinhom(sismospp,lambda_s,correction="border")
plot(K_sismos_NH)
Warning: Internal error: fvlabels truncated the function name
Warning: Internal error: fvlabels truncated the function name
Warning: Internal error: fvlabels truncated the function name

plot(pcf(K_sismos_NH))

Fest(sismospp)
Function value object (class 'fv')
for the function r -> F(r)
.....................................................................
        Math.label      Description                                  
r       r               distance argument r                          
theo    F[pois](r)      theoretical Poisson F(r)                     
cs      hat(F)[cs](r)   Chiu-Stoyan estimate of F(r)                 
rs      hat(F)[bord](r) border corrected estimate of F(r)            
km      hat(F)[km](r)   Kaplan-Meier estimate of F(r)                
hazard  hat(h)[km](r)   Kaplan-Meier estimate of hazard function h(r)
theohaz h[pois](r)      theoretical Poisson hazard h(r)              
.....................................................................
Default plot formula:  .~r
where "." stands for 'km', 'rs', 'cs', 'theo'
Recommended range of argument r: [0, 108010]
Available range of argument r: [0, 108010]
Unit of length: 1 Metro
plot(Fest(sismospp))

Jest(sismospp)
Function value object (class 'fv')
for the function r -> J(r)
......................................................................
       Math.label     Description                                     
r      r              distance argument r                             
theo   J[pois](r)     theoretical Poisson J(r)                        
rs     hat(J)[rs](r)  border corrected estimate of J(r)               
han    hat(J)[han](r) Hanisch-style estimate of J(r)                  
km     hat(J)[km](r)  Kaplan-Meier estimate of J(r)                   
hazard hazard(r)      Kaplan-Meier estimate of derivative of log(J(r))
......................................................................
Default plot formula:  .~r
where "." stands for 'km', 'han', 'rs', 'theo'
Recommended range of argument r: [0, 105610]
Available range of argument r: [0, 105610]
Unit of length: 1 Metro
plot(Jest(sismospp))

Gest(sismospp)
Function value object (class 'fv')
for the function r -> G(r)
.....................................................................
        Math.label      Description                                  
r       r               distance argument r                          
theo    G[pois](r)      theoretical Poisson G(r)                     
han     hat(G)[han](r)  Hanisch estimate of G(r)                     
rs      hat(G)[bord](r) border corrected estimate of G(r)            
km      hat(G)[km](r)   Kaplan-Meier estimate of G(r)                
hazard  hat(h)[km](r)   Kaplan-Meier estimate of hazard function h(r)
theohaz h[pois](r)      theoretical Poisson hazard function h(r)     
.....................................................................
Default plot formula:  .~r
where "." stands for 'km', 'rs', 'han', 'theo'
Recommended range of argument r: [0, 27846]
Available range of argument r: [0, 105610]
Unit of length: 1 Metro
plot(Gest(sismospp))

Hest(sismospp)
Function value object (class 'fv')
for the function r -> H(r)
.........................................................................
       Math.label      Description                                       
r      r               distance argument r                               
km     hat(H)[km](r)   Kaplan-Meier estimate of H(r)                     
hazard hat(lambda)(r)  Kaplan-Meier estimate of hazard function lambda(r)
han    hat(H)[han](r)  Hanisch estimate of H(r)                          
rs     hat(H)[bord](r) border corrected estimate of H(r)                 
.........................................................................
Default plot formula:  .~r
where "." stands for 'km', 'han', 'rs'
Recommended range of argument r: [0, 272730]
Available range of argument r: [0, 1126100]
Unit of length: 1 Metro
plot(Hest(sismospp))

Fenvel=envelope(sismospp,Fest,nsim=499)
Generating 499 simulated realisations of CSR  ...
1, 2, 3, .5....10....15....20....25....30....35....40....45....50..
..55....60....65....70....75....80....85....90....95....100....105....110
....115....120....125....130....135....140....145....150....155....160....165...
.170....175....180....185....190....195....200....205....210....215....220....225.
...230....235....240....245....250....255....260....265....270....275....280....
285....290....295....300....305....310....315....320....325....330....335....340..
..345....350....355....360....365....370....375....380....385....390....395....400
....405....410....415....420....425....430....435....440....445....450....455...
.460....465....470....475....480....485....490....495...
499.

Done.
plot(Fenvel)

Genvel=envelope(sismospp,Fest,nsim=499)
Generating 499 simulated realisations of CSR  ...
1, 2, 3, .5....10....15....20....25....30....35....40....45....50..
..55....60....65....70....75....80....85....90....95....100....105....110
....115....120....125....130....135....140....145....150....155....160....165...
.170....175....180....185....190....195....200....205....210....215....220....225.
...230....235....240....245....250....255....260....265....270....275....280....
285....290....295....300....305....310....315....320....325....330....335....340..
..345....350....355....360....365....370....375....380....385....390....395....400
....405....410....415....420....425....430....435....440....445....450....455...
.460....465....470....475....480....485....490....495...
499.

Done.
plot(Genvel)