set.seed(1000579855)
Seqlat<-seq(from=-73.3, to=-73.25, by=.001)
Seqlong<-seq(from=5.54,to=5.58,by=.001)
Latitude<- sample(Seqlat,size=100,replace=TRUE)
Longitude<-sample(Seqlong,size=100,replace=TRUE)
xy<-data.frame(x=Longitude,y=Latitude)
plot(xy$x,xy$y)

SMI=sort.int(runif(100,0.7,0.95),partial =10)
NDVI=sort.int(rnorm(100,0.45,0.06), partial = 10)
LST=sort.int(26*rbeta(100,shape1=0.87,shape2=0.91),partial = 10)
crop=factor(ifelse(rgamma(n=100,rate=0.8,shape=0.5)<0.5,0,1))
df1=data.frame(xy,SMI,NDVI,LST,crop)
df1
##         x       y       SMI      NDVI         LST crop
## 1   5.577 -73.270 0.7110707 0.3378694  0.42589995    1
## 2   5.575 -73.298 0.7045101 0.3466406  0.41286542    1
## 3   5.557 -73.288 0.7087018 0.3729947  0.42622543    0
## 4   5.546 -73.280 0.7080012 0.3568273  0.09257365    0
## 5   5.545 -73.264 0.7159930 0.3655546  0.81252482    0
## 6   5.547 -73.271 0.7019546 0.3735510  0.56147691    0
## 7   5.556 -73.268 0.7152981 0.3733371  0.75609694    0
## 8   5.563 -73.286 0.7169576 0.3788267  0.52093506    0
## 9   5.553 -73.279 0.7188258 0.3803645  1.19552604    0
## 10  5.540 -73.257 0.7190025 0.3810685  1.19658615    0
## 11  5.549 -73.264 0.7190369 0.3814067  1.34499416    1
## 12  5.580 -73.273 0.7338021 0.3972094  1.38168675    1
## 13  5.572 -73.291 0.7347987 0.3871763  6.35020169    1
## 14  5.543 -73.285 0.7202338 0.3908236 11.04652599    0
## 15  5.559 -73.282 0.7320041 0.3942129  6.21859948    1
## 16  5.547 -73.277 0.7294736 0.3935539  4.30681980    0
## 17  5.555 -73.250 0.7386254 0.3920445 14.18158307    1
## 18  5.547 -73.254 0.7374480 0.3906205 14.49186671    0
## 19  5.545 -73.296 0.7416434 0.3946744 10.21982328    1
## 20  5.577 -73.253 0.7380110 0.3964335 11.20813874    1
## 21  5.545 -73.298 0.7584693 0.3884163 13.66946826    0
## 22  5.561 -73.300 0.7697956 0.4491871  6.29672710    0
## 23  5.551 -73.289 0.7567680 0.4700328  9.70089049    0
## 24  5.550 -73.294 0.7770173 0.4488691  7.69773606    1
## 25  5.549 -73.252 0.7482631 0.4625960  2.09936555    0
## 26  5.563 -73.296 0.7433650 0.4084605 11.55034137    1
## 27  5.580 -73.287 0.7469922 0.4313955  7.22300236    1
## 28  5.546 -73.273 0.7691206 0.4135666  3.24344481    1
## 29  5.568 -73.261 0.7566106 0.4054611  3.46134301    1
## 30  5.565 -73.282 0.7423937 0.4441127  5.64214584    0
## 31  5.545 -73.264 0.7467557 0.4596761 10.99215288    0
## 32  5.560 -73.290 0.8835611 0.4185906  9.89531118    0
## 33  5.548 -73.263 0.9363114 0.4229683  6.05606421    1
## 34  5.571 -73.290 0.8327370 0.4684080  7.13610701    0
## 35  5.575 -73.260 0.9487781 0.4393326  3.86150726    0
## 36  5.551 -73.267 0.9202944 0.4184583  3.43661932    1
## 37  5.577 -73.289 0.8957445 0.4419551  8.35327481    1
## 38  5.545 -73.298 0.9428688 0.4239987  9.01921544    1
## 39  5.573 -73.264 0.9426985 0.4525001  8.09327091    0
## 40  5.551 -73.254 0.8360254 0.4291286 10.94965588    1
## 41  5.569 -73.265 0.8474294 0.4645766  7.83494604    0
## 42  5.549 -73.265 0.8593841 0.4554685  2.91986904    0
## 43  5.580 -73.267 0.9024785 0.4518823  9.09754992    0
## 44  5.573 -73.262 0.7935286 0.4335222  2.70033511    0
## 45  5.563 -73.253 0.9071142 0.3984627  8.42126515    1
## 46  5.546 -73.258 0.8058787 0.4644484  9.89877747    1
## 47  5.574 -73.254 0.7936852 0.4622095  6.98432405    1
## 48  5.554 -73.299 0.8109977 0.4062288  2.77108840    0
## 49  5.540 -73.299 0.8000597 0.4367658  4.89101267    1
## 50  5.570 -73.279 0.8538442 0.4613475 13.63556628    1
## 51  5.554 -73.251 0.9035943 0.4398300  6.93182457    1
## 52  5.552 -73.276 0.8813359 0.4234928  5.41928287    1
## 53  5.547 -73.280 0.8683766 0.4638765  7.73024695    0
## 54  5.545 -73.252 0.8195909 0.4126734  2.66443029    0
## 55  5.578 -73.260 0.9096037 0.4342406  3.14084693    0
## 56  5.540 -73.270 0.8005186 0.4018448 14.04958141    0
## 57  5.575 -73.289 0.8843469 0.4176299  7.16174132    0
## 58  5.574 -73.270 0.7862926 0.4436692 15.80485938    1
## 59  5.544 -73.294 0.8814684 0.4504637 21.75577526    1
## 60  5.546 -73.290 0.7931877 0.4634360 17.91751894    0
## 61  5.576 -73.268 0.8419918 0.4709403 17.21845353    0
## 62  5.568 -73.256 0.8096942 0.4564409 19.65261254    0
## 63  5.558 -73.285 0.8770435 0.4690268 17.86453803    1
## 64  5.557 -73.278 0.9052334 0.4670000 21.71478240    0
## 65  5.573 -73.260 0.8082419 0.4478923 17.95328560    1
## 66  5.553 -73.287 0.8737961 0.4231107 20.00049780    0
## 67  5.566 -73.284 0.9399988 0.5413283 21.91175245    1
## 68  5.567 -73.266 0.8579748 0.4845414 16.45308889    0
## 69  5.580 -73.287 0.8456122 0.5123793 19.55470052    1
## 70  5.576 -73.294 0.8996512 0.5298505 17.58907590    0
## 71  5.555 -73.259 0.9458732 0.5327747 20.80298240    0
## 72  5.541 -73.258 0.8792382 0.5414217 17.07974429    1
## 73  5.574 -73.297 0.8855610 0.4749562 21.11227030    0
## 74  5.545 -73.299 0.9108187 0.5150462 17.06846987    0
## 75  5.560 -73.267 0.8426215 0.5782634 16.79374111    0
## 76  5.556 -73.269 0.7853216 0.4812471 20.68221081    1
## 77  5.555 -73.291 0.9027559 0.4751730 19.79326771    0
## 78  5.559 -73.252 0.8687392 0.5435544 21.94185458    1
## 79  5.561 -73.259 0.9428625 0.5136234 21.75379109    0
## 80  5.562 -73.254 0.8472902 0.4726600 20.08445494    0
## 81  5.552 -73.292 0.8623980 0.5928488 15.72687230    0
## 82  5.557 -73.268 0.7898995 0.5103821 20.55782129    0
## 83  5.574 -73.281 0.9186096 0.4860201 21.25512167    0
## 84  5.559 -73.286 0.9359754 0.5458797 17.89271229    1
## 85  5.575 -73.278 0.8354318 0.5101896 16.68875759    1
## 86  5.558 -73.285 0.8324613 0.5651807 24.00791902    1
## 87  5.542 -73.270 0.8787350 0.4863785 25.25284123    0
## 88  5.577 -73.272 0.8490814 0.4798723 23.76197107    1
## 89  5.556 -73.270 0.9077144 0.5505521 23.74986918    1
## 90  5.568 -73.299 0.8852120 0.5271529 22.24167996    0
## 91  5.548 -73.266 0.8119120 0.5325476 24.68434904    0
## 92  5.543 -73.253 0.9451603 0.5561369 23.63501988    1
## 93  5.555 -73.267 0.9407233 0.5561518 23.78582354    1
## 94  5.572 -73.282 0.8153107 0.4864211 23.95958793    0
## 95  5.565 -73.290 0.8871847 0.4960460 23.36287041    0
## 96  5.579 -73.273 0.8283922 0.5318362 23.60495650    1
## 97  5.545 -73.267 0.8502388 0.5014892 22.05131932    0
## 98  5.561 -73.290 0.8216787 0.4713482 25.67151845    1
## 99  5.540 -73.256 0.7929413 0.5011147 25.59871889    1
## 100 5.560 -73.253 0.8251805 0.4937176 25.32399297    1
#1
#xy<-xy[!duplicated(xy),]
df1<-df1[!duplicated(df1),]
plot(xy$x,xy$y)

#2
dataxy=ppp(xy$x,xy$y,xrange=c(min(xy$x),max(xy$x)),yrange=c(min(xy$y),max(xy$y)))
## Warning: data contain duplicated points
any(duplicated(dataxy))
## [1] TRUE
Y<-unique(dataxy)
any(duplicated(Y))
## [1] FALSE
#3
dataxy1=ppp(xy$x,xy$y,xrange=c(min(xy$x),max(xy$x)),yrange=c(min(xy$y),max(xy$y)),marks=df1$crop)
## Warning: data contain duplicated points
any(duplicated(dataxy1))
## [1] TRUE
Y1<-unique(dataxy1)
any(duplicated(Y1))
## [1] FALSE
#4
dataxy2=ppp(xy$x,xy$y,xrange=c(min(xy$x),max(xy$x)),yrange=c(min(xy$y),max(xy$y)),marks=df1$NDVI)
any(duplicated(dataxy2))
## [1] FALSE
Y2<-unique(dataxy2)
#5
plot(Y,size=0.7,main = "Grafico Marca xy", cols= "green")

plot(Y1,size=0.8,main = "Grafico Marca crop", cols= "red")

plot(Y2,size=0.00155,main = "Grafico Marca NDVI",cols = "blue")

#6
dataxy3=ppp(xy$x,xy$y,xrange=c(min(xy$x),max(xy$x)),yrange=c(min(xy$y),max(xy$y)),marks=df1[,c(3:6)])
Y3<-unique(dataxy3)
par(mfrow=c(1,2))
plot(Y3,which.marks = "NDVI",size=0.0009)  
plot(Y3,which.marks="crop",size=0.7)  

par(mfrow=c(1,1))
plot(Y3,size=0.002,main = "GrƔfica de todas las marcas")

windo1=owin(c(4.456,4.528),c(-73.289,-73.277));windo1
## window: rectangle = [4.456, 4.528] x [-73.289, -73.277] units
#7 
npoints(Y3)  
## [1] 100
marks(Y3)   
##           SMI      NDVI         LST crop
## 1   0.7110707 0.3378694  0.42589995    1
## 2   0.7045101 0.3466406  0.41286542    1
## 3   0.7087018 0.3729947  0.42622543    0
## 4   0.7080012 0.3568273  0.09257365    0
## 5   0.7159930 0.3655546  0.81252482    0
## 6   0.7019546 0.3735510  0.56147691    0
## 7   0.7152981 0.3733371  0.75609694    0
## 8   0.7169576 0.3788267  0.52093506    0
## 9   0.7188258 0.3803645  1.19552604    0
## 10  0.7190025 0.3810685  1.19658615    0
## 11  0.7190369 0.3814067  1.34499416    1
## 12  0.7338021 0.3972094  1.38168675    1
## 13  0.7347987 0.3871763  6.35020169    1
## 14  0.7202338 0.3908236 11.04652599    0
## 15  0.7320041 0.3942129  6.21859948    1
## 16  0.7294736 0.3935539  4.30681980    0
## 17  0.7386254 0.3920445 14.18158307    1
## 18  0.7374480 0.3906205 14.49186671    0
## 19  0.7416434 0.3946744 10.21982328    1
## 20  0.7380110 0.3964335 11.20813874    1
## 21  0.7584693 0.3884163 13.66946826    0
## 22  0.7697956 0.4491871  6.29672710    0
## 23  0.7567680 0.4700328  9.70089049    0
## 24  0.7770173 0.4488691  7.69773606    1
## 25  0.7482631 0.4625960  2.09936555    0
## 26  0.7433650 0.4084605 11.55034137    1
## 27  0.7469922 0.4313955  7.22300236    1
## 28  0.7691206 0.4135666  3.24344481    1
## 29  0.7566106 0.4054611  3.46134301    1
## 30  0.7423937 0.4441127  5.64214584    0
## 31  0.7467557 0.4596761 10.99215288    0
## 32  0.8835611 0.4185906  9.89531118    0
## 33  0.9363114 0.4229683  6.05606421    1
## 34  0.8327370 0.4684080  7.13610701    0
## 35  0.9487781 0.4393326  3.86150726    0
## 36  0.9202944 0.4184583  3.43661932    1
## 37  0.8957445 0.4419551  8.35327481    1
## 38  0.9428688 0.4239987  9.01921544    1
## 39  0.9426985 0.4525001  8.09327091    0
## 40  0.8360254 0.4291286 10.94965588    1
## 41  0.8474294 0.4645766  7.83494604    0
## 42  0.8593841 0.4554685  2.91986904    0
## 43  0.9024785 0.4518823  9.09754992    0
## 44  0.7935286 0.4335222  2.70033511    0
## 45  0.9071142 0.3984627  8.42126515    1
## 46  0.8058787 0.4644484  9.89877747    1
## 47  0.7936852 0.4622095  6.98432405    1
## 48  0.8109977 0.4062288  2.77108840    0
## 49  0.8000597 0.4367658  4.89101267    1
## 50  0.8538442 0.4613475 13.63556628    1
## 51  0.9035943 0.4398300  6.93182457    1
## 52  0.8813359 0.4234928  5.41928287    1
## 53  0.8683766 0.4638765  7.73024695    0
## 54  0.8195909 0.4126734  2.66443029    0
## 55  0.9096037 0.4342406  3.14084693    0
## 56  0.8005186 0.4018448 14.04958141    0
## 57  0.8843469 0.4176299  7.16174132    0
## 58  0.7862926 0.4436692 15.80485938    1
## 59  0.8814684 0.4504637 21.75577526    1
## 60  0.7931877 0.4634360 17.91751894    0
## 61  0.8419918 0.4709403 17.21845353    0
## 62  0.8096942 0.4564409 19.65261254    0
## 63  0.8770435 0.4690268 17.86453803    1
## 64  0.9052334 0.4670000 21.71478240    0
## 65  0.8082419 0.4478923 17.95328560    1
## 66  0.8737961 0.4231107 20.00049780    0
## 67  0.9399988 0.5413283 21.91175245    1
## 68  0.8579748 0.4845414 16.45308889    0
## 69  0.8456122 0.5123793 19.55470052    1
## 70  0.8996512 0.5298505 17.58907590    0
## 71  0.9458732 0.5327747 20.80298240    0
## 72  0.8792382 0.5414217 17.07974429    1
## 73  0.8855610 0.4749562 21.11227030    0
## 74  0.9108187 0.5150462 17.06846987    0
## 75  0.8426215 0.5782634 16.79374111    0
## 76  0.7853216 0.4812471 20.68221081    1
## 77  0.9027559 0.4751730 19.79326771    0
## 78  0.8687392 0.5435544 21.94185458    1
## 79  0.9428625 0.5136234 21.75379109    0
## 80  0.8472902 0.4726600 20.08445494    0
## 81  0.8623980 0.5928488 15.72687230    0
## 82  0.7898995 0.5103821 20.55782129    0
## 83  0.9186096 0.4860201 21.25512167    0
## 84  0.9359754 0.5458797 17.89271229    1
## 85  0.8354318 0.5101896 16.68875759    1
## 86  0.8324613 0.5651807 24.00791902    1
## 87  0.8787350 0.4863785 25.25284123    0
## 88  0.8490814 0.4798723 23.76197107    1
## 89  0.9077144 0.5505521 23.74986918    1
## 90  0.8852120 0.5271529 22.24167996    0
## 91  0.8119120 0.5325476 24.68434904    0
## 92  0.9451603 0.5561369 23.63501988    1
## 93  0.9407233 0.5561518 23.78582354    1
## 94  0.8153107 0.4864211 23.95958793    0
## 95  0.8871847 0.4960460 23.36287041    0
## 96  0.8283922 0.5318362 23.60495650    1
## 97  0.8502388 0.5014892 22.05131932    0
## 98  0.8216787 0.4713482 25.67151845    1
## 99  0.7929413 0.5011147 25.59871889    1
## 100 0.8251805 0.4937176 25.32399297    1
coords(Y3)  
##         x       y
## 1   5.577 -73.270
## 2   5.575 -73.298
## 3   5.557 -73.288
## 4   5.546 -73.280
## 5   5.545 -73.264
## 6   5.547 -73.271
## 7   5.556 -73.268
## 8   5.563 -73.286
## 9   5.553 -73.279
## 10  5.540 -73.257
## 11  5.549 -73.264
## 12  5.580 -73.273
## 13  5.572 -73.291
## 14  5.543 -73.285
## 15  5.559 -73.282
## 16  5.547 -73.277
## 17  5.555 -73.250
## 18  5.547 -73.254
## 19  5.545 -73.296
## 20  5.577 -73.253
## 21  5.545 -73.298
## 22  5.561 -73.300
## 23  5.551 -73.289
## 24  5.550 -73.294
## 25  5.549 -73.252
## 26  5.563 -73.296
## 27  5.580 -73.287
## 28  5.546 -73.273
## 29  5.568 -73.261
## 30  5.565 -73.282
## 31  5.545 -73.264
## 32  5.560 -73.290
## 33  5.548 -73.263
## 34  5.571 -73.290
## 35  5.575 -73.260
## 36  5.551 -73.267
## 37  5.577 -73.289
## 38  5.545 -73.298
## 39  5.573 -73.264
## 40  5.551 -73.254
## 41  5.569 -73.265
## 42  5.549 -73.265
## 43  5.580 -73.267
## 44  5.573 -73.262
## 45  5.563 -73.253
## 46  5.546 -73.258
## 47  5.574 -73.254
## 48  5.554 -73.299
## 49  5.540 -73.299
## 50  5.570 -73.279
## 51  5.554 -73.251
## 52  5.552 -73.276
## 53  5.547 -73.280
## 54  5.545 -73.252
## 55  5.578 -73.260
## 56  5.540 -73.270
## 57  5.575 -73.289
## 58  5.574 -73.270
## 59  5.544 -73.294
## 60  5.546 -73.290
## 61  5.576 -73.268
## 62  5.568 -73.256
## 63  5.558 -73.285
## 64  5.557 -73.278
## 65  5.573 -73.260
## 66  5.553 -73.287
## 67  5.566 -73.284
## 68  5.567 -73.266
## 69  5.580 -73.287
## 70  5.576 -73.294
## 71  5.555 -73.259
## 72  5.541 -73.258
## 73  5.574 -73.297
## 74  5.545 -73.299
## 75  5.560 -73.267
## 76  5.556 -73.269
## 77  5.555 -73.291
## 78  5.559 -73.252
## 79  5.561 -73.259
## 80  5.562 -73.254
## 81  5.552 -73.292
## 82  5.557 -73.268
## 83  5.574 -73.281
## 84  5.559 -73.286
## 85  5.575 -73.278
## 86  5.558 -73.285
## 87  5.542 -73.270
## 88  5.577 -73.272
## 89  5.556 -73.270
## 90  5.568 -73.299
## 91  5.548 -73.266
## 92  5.543 -73.253
## 93  5.555 -73.267
## 94  5.572 -73.282
## 95  5.565 -73.290
## 96  5.579 -73.273
## 97  5.545 -73.267
## 98  5.561 -73.290
## 99  5.540 -73.256
## 100 5.560 -73.253
as.owin(Y3)  
## window: rectangle = [5.54, 5.58] x [-73.3, -73.25] units
as.data.frame(Y3) 
##         x       y       SMI      NDVI         LST crop
## 1   5.577 -73.270 0.7110707 0.3378694  0.42589995    1
## 2   5.575 -73.298 0.7045101 0.3466406  0.41286542    1
## 3   5.557 -73.288 0.7087018 0.3729947  0.42622543    0
## 4   5.546 -73.280 0.7080012 0.3568273  0.09257365    0
## 5   5.545 -73.264 0.7159930 0.3655546  0.81252482    0
## 6   5.547 -73.271 0.7019546 0.3735510  0.56147691    0
## 7   5.556 -73.268 0.7152981 0.3733371  0.75609694    0
## 8   5.563 -73.286 0.7169576 0.3788267  0.52093506    0
## 9   5.553 -73.279 0.7188258 0.3803645  1.19552604    0
## 10  5.540 -73.257 0.7190025 0.3810685  1.19658615    0
## 11  5.549 -73.264 0.7190369 0.3814067  1.34499416    1
## 12  5.580 -73.273 0.7338021 0.3972094  1.38168675    1
## 13  5.572 -73.291 0.7347987 0.3871763  6.35020169    1
## 14  5.543 -73.285 0.7202338 0.3908236 11.04652599    0
## 15  5.559 -73.282 0.7320041 0.3942129  6.21859948    1
## 16  5.547 -73.277 0.7294736 0.3935539  4.30681980    0
## 17  5.555 -73.250 0.7386254 0.3920445 14.18158307    1
## 18  5.547 -73.254 0.7374480 0.3906205 14.49186671    0
## 19  5.545 -73.296 0.7416434 0.3946744 10.21982328    1
## 20  5.577 -73.253 0.7380110 0.3964335 11.20813874    1
## 21  5.545 -73.298 0.7584693 0.3884163 13.66946826    0
## 22  5.561 -73.300 0.7697956 0.4491871  6.29672710    0
## 23  5.551 -73.289 0.7567680 0.4700328  9.70089049    0
## 24  5.550 -73.294 0.7770173 0.4488691  7.69773606    1
## 25  5.549 -73.252 0.7482631 0.4625960  2.09936555    0
## 26  5.563 -73.296 0.7433650 0.4084605 11.55034137    1
## 27  5.580 -73.287 0.7469922 0.4313955  7.22300236    1
## 28  5.546 -73.273 0.7691206 0.4135666  3.24344481    1
## 29  5.568 -73.261 0.7566106 0.4054611  3.46134301    1
## 30  5.565 -73.282 0.7423937 0.4441127  5.64214584    0
## 31  5.545 -73.264 0.7467557 0.4596761 10.99215288    0
## 32  5.560 -73.290 0.8835611 0.4185906  9.89531118    0
## 33  5.548 -73.263 0.9363114 0.4229683  6.05606421    1
## 34  5.571 -73.290 0.8327370 0.4684080  7.13610701    0
## 35  5.575 -73.260 0.9487781 0.4393326  3.86150726    0
## 36  5.551 -73.267 0.9202944 0.4184583  3.43661932    1
## 37  5.577 -73.289 0.8957445 0.4419551  8.35327481    1
## 38  5.545 -73.298 0.9428688 0.4239987  9.01921544    1
## 39  5.573 -73.264 0.9426985 0.4525001  8.09327091    0
## 40  5.551 -73.254 0.8360254 0.4291286 10.94965588    1
## 41  5.569 -73.265 0.8474294 0.4645766  7.83494604    0
## 42  5.549 -73.265 0.8593841 0.4554685  2.91986904    0
## 43  5.580 -73.267 0.9024785 0.4518823  9.09754992    0
## 44  5.573 -73.262 0.7935286 0.4335222  2.70033511    0
## 45  5.563 -73.253 0.9071142 0.3984627  8.42126515    1
## 46  5.546 -73.258 0.8058787 0.4644484  9.89877747    1
## 47  5.574 -73.254 0.7936852 0.4622095  6.98432405    1
## 48  5.554 -73.299 0.8109977 0.4062288  2.77108840    0
## 49  5.540 -73.299 0.8000597 0.4367658  4.89101267    1
## 50  5.570 -73.279 0.8538442 0.4613475 13.63556628    1
## 51  5.554 -73.251 0.9035943 0.4398300  6.93182457    1
## 52  5.552 -73.276 0.8813359 0.4234928  5.41928287    1
## 53  5.547 -73.280 0.8683766 0.4638765  7.73024695    0
## 54  5.545 -73.252 0.8195909 0.4126734  2.66443029    0
## 55  5.578 -73.260 0.9096037 0.4342406  3.14084693    0
## 56  5.540 -73.270 0.8005186 0.4018448 14.04958141    0
## 57  5.575 -73.289 0.8843469 0.4176299  7.16174132    0
## 58  5.574 -73.270 0.7862926 0.4436692 15.80485938    1
## 59  5.544 -73.294 0.8814684 0.4504637 21.75577526    1
## 60  5.546 -73.290 0.7931877 0.4634360 17.91751894    0
## 61  5.576 -73.268 0.8419918 0.4709403 17.21845353    0
## 62  5.568 -73.256 0.8096942 0.4564409 19.65261254    0
## 63  5.558 -73.285 0.8770435 0.4690268 17.86453803    1
## 64  5.557 -73.278 0.9052334 0.4670000 21.71478240    0
## 65  5.573 -73.260 0.8082419 0.4478923 17.95328560    1
## 66  5.553 -73.287 0.8737961 0.4231107 20.00049780    0
## 67  5.566 -73.284 0.9399988 0.5413283 21.91175245    1
## 68  5.567 -73.266 0.8579748 0.4845414 16.45308889    0
## 69  5.580 -73.287 0.8456122 0.5123793 19.55470052    1
## 70  5.576 -73.294 0.8996512 0.5298505 17.58907590    0
## 71  5.555 -73.259 0.9458732 0.5327747 20.80298240    0
## 72  5.541 -73.258 0.8792382 0.5414217 17.07974429    1
## 73  5.574 -73.297 0.8855610 0.4749562 21.11227030    0
## 74  5.545 -73.299 0.9108187 0.5150462 17.06846987    0
## 75  5.560 -73.267 0.8426215 0.5782634 16.79374111    0
## 76  5.556 -73.269 0.7853216 0.4812471 20.68221081    1
## 77  5.555 -73.291 0.9027559 0.4751730 19.79326771    0
## 78  5.559 -73.252 0.8687392 0.5435544 21.94185458    1
## 79  5.561 -73.259 0.9428625 0.5136234 21.75379109    0
## 80  5.562 -73.254 0.8472902 0.4726600 20.08445494    0
## 81  5.552 -73.292 0.8623980 0.5928488 15.72687230    0
## 82  5.557 -73.268 0.7898995 0.5103821 20.55782129    0
## 83  5.574 -73.281 0.9186096 0.4860201 21.25512167    0
## 84  5.559 -73.286 0.9359754 0.5458797 17.89271229    1
## 85  5.575 -73.278 0.8354318 0.5101896 16.68875759    1
## 86  5.558 -73.285 0.8324613 0.5651807 24.00791902    1
## 87  5.542 -73.270 0.8787350 0.4863785 25.25284123    0
## 88  5.577 -73.272 0.8490814 0.4798723 23.76197107    1
## 89  5.556 -73.270 0.9077144 0.5505521 23.74986918    1
## 90  5.568 -73.299 0.8852120 0.5271529 22.24167996    0
## 91  5.548 -73.266 0.8119120 0.5325476 24.68434904    0
## 92  5.543 -73.253 0.9451603 0.5561369 23.63501988    1
## 93  5.555 -73.267 0.9407233 0.5561518 23.78582354    1
## 94  5.572 -73.282 0.8153107 0.4864211 23.95958793    0
## 95  5.565 -73.290 0.8871847 0.4960460 23.36287041    0
## 96  5.579 -73.273 0.8283922 0.5318362 23.60495650    1
## 97  5.545 -73.267 0.8502388 0.5014892 22.05131932    0
## 98  5.561 -73.290 0.8216787 0.4713482 25.67151845    1
## 99  5.540 -73.256 0.7929413 0.5011147 25.59871889    1
## 100 5.560 -73.253 0.8251805 0.4937176 25.32399297    1
marks(Y3)=seq(1,100) 
coords(Y3)=matrix(seq(6.54,6.58,0.001),seq(-72.3,-72.25,0.001),ncol = 2,nrow = 100)  
## Warning in matrix(seq(6.54, 6.58, 0.001), seq(-72.3, -72.25, 0.001), ncol =
## 2, : la longitud de los datos [41] no es un submĆŗltiplo o mĆŗltiplo del nĆŗmero de
## filas [100] en la matriz
## Warning: 100 points were rejected as lying outside the specified window
Y3[windo1]
## Marked planar point pattern: 0 points
## marks are numeric, of storage type  'integer'
## window: rectangle = [4.456, 4.528] x [-73.289, -73.277] units
#8
dataxy3=ppp(xy$x,xy$y,xrange=c(min(xy$x),max(xy$x)),yrange=c(min(xy$y),max(xy$y)),marks = df1[,3:6])
Y3=unique(dataxy3)
#9
plot(density(Y))

contour(density(Y))

#10
hist(xy$x,xlab = "x",ylab="Frecuencia",main = "Histograma frecuencia de X",
     col = "yellow")   # Histograma de la longitud.

hist(xy$y,xlab = "y",ylab="Frecuencia",main = "Histograma frecuencia de Y",
     col = "pink")  #Histograma de la latitud.

#11
plot(density(Y))
plot(Y,add=TRUE)

#12

sep=split(df1,crop,drop = TRUE)
dividir=split(df1,crop,drop = TRUE)
ausen=dividir$"1";ausen
##         x       y       SMI      NDVI        LST crop
## 1   5.577 -73.270 0.7110707 0.3378694  0.4258999    1
## 2   5.575 -73.298 0.7045101 0.3466406  0.4128654    1
## 11  5.549 -73.264 0.7190369 0.3814067  1.3449942    1
## 12  5.580 -73.273 0.7338021 0.3972094  1.3816868    1
## 13  5.572 -73.291 0.7347987 0.3871763  6.3502017    1
## 15  5.559 -73.282 0.7320041 0.3942129  6.2185995    1
## 17  5.555 -73.250 0.7386254 0.3920445 14.1815831    1
## 19  5.545 -73.296 0.7416434 0.3946744 10.2198233    1
## 20  5.577 -73.253 0.7380110 0.3964335 11.2081387    1
## 24  5.550 -73.294 0.7770173 0.4488691  7.6977361    1
## 26  5.563 -73.296 0.7433650 0.4084605 11.5503414    1
## 27  5.580 -73.287 0.7469922 0.4313955  7.2230024    1
## 28  5.546 -73.273 0.7691206 0.4135666  3.2434448    1
## 29  5.568 -73.261 0.7566106 0.4054611  3.4613430    1
## 33  5.548 -73.263 0.9363114 0.4229683  6.0560642    1
## 36  5.551 -73.267 0.9202944 0.4184583  3.4366193    1
## 37  5.577 -73.289 0.8957445 0.4419551  8.3532748    1
## 38  5.545 -73.298 0.9428688 0.4239987  9.0192154    1
## 40  5.551 -73.254 0.8360254 0.4291286 10.9496559    1
## 45  5.563 -73.253 0.9071142 0.3984627  8.4212651    1
## 46  5.546 -73.258 0.8058787 0.4644484  9.8987775    1
## 47  5.574 -73.254 0.7936852 0.4622095  6.9843240    1
## 49  5.540 -73.299 0.8000597 0.4367658  4.8910127    1
## 50  5.570 -73.279 0.8538442 0.4613475 13.6355663    1
## 51  5.554 -73.251 0.9035943 0.4398300  6.9318246    1
## 52  5.552 -73.276 0.8813359 0.4234928  5.4192829    1
## 58  5.574 -73.270 0.7862926 0.4436692 15.8048594    1
## 59  5.544 -73.294 0.8814684 0.4504637 21.7557753    1
## 63  5.558 -73.285 0.8770435 0.4690268 17.8645380    1
## 65  5.573 -73.260 0.8082419 0.4478923 17.9532856    1
## 67  5.566 -73.284 0.9399988 0.5413283 21.9117525    1
## 69  5.580 -73.287 0.8456122 0.5123793 19.5547005    1
## 72  5.541 -73.258 0.8792382 0.5414217 17.0797443    1
## 76  5.556 -73.269 0.7853216 0.4812471 20.6822108    1
## 78  5.559 -73.252 0.8687392 0.5435544 21.9418546    1
## 84  5.559 -73.286 0.9359754 0.5458797 17.8927123    1
## 85  5.575 -73.278 0.8354318 0.5101896 16.6887576    1
## 86  5.558 -73.285 0.8324613 0.5651807 24.0079190    1
## 88  5.577 -73.272 0.8490814 0.4798723 23.7619711    1
## 89  5.556 -73.270 0.9077144 0.5505521 23.7498692    1
## 92  5.543 -73.253 0.9451603 0.5561369 23.6350199    1
## 93  5.555 -73.267 0.9407233 0.5561518 23.7858235    1
## 96  5.579 -73.273 0.8283922 0.5318362 23.6049565    1
## 98  5.561 -73.290 0.8216787 0.4713482 25.6715184    1
## 99  5.540 -73.256 0.7929413 0.5011147 25.5987189    1
## 100 5.560 -73.253 0.8251805 0.4937176 25.3239930    1
Y4=unique(ppp(ausen$x,ausen$y,xrange=c(min(ausen$x),max(ausen$x)),yrange=c(min(ausen$y),
                                                  max(ausen$y)),marks = ausen[,6]))
## Warning: data contain duplicated points
any(duplicated(Y4))  
## [1] FALSE
plot(Y4,cols = "blue",main = "Ausencia de cultivos")

#13
plot(density(Y4))

contour(density(Y4))

#14
x=seq(-4,4,length=110)  
y=seq(-4,4,length=110)  
cono=function(x,y) sqrt(x^2+y^2)  
z=outer(x, y, cono)
persp(x,y,z) 

parab=function(x,y) x^2+y^2  
z=outer(x, y, parab)

persp(x,y,z)

#15
ml=as.im(Y4)     
plot(ml)         
plot(Y4,add = TRUE)

#16
summary(Y3)
## Marked planar point pattern:  100 points
## Average intensity 50000 points per square unit
## 
## Coordinates are given to 3 decimal places
## i.e. rounded to the nearest multiple of 0.001 units
## 
## Mark variables: SMI, NDVI, LST, crop
## Summary:
##       SMI              NDVI             LST           crop  
##  Min.   :0.7020   Min.   :0.3379   Min.   : 0.09257   0:54  
##  1st Qu.:0.7545   1st Qu.:0.4079   1st Qu.: 5.58643   1:46  
##  Median :0.8304   Median :0.4522   Median :11.12733         
##  Mean   :0.8249   Mean   :0.4538   Mean   :12.47099         
##  3rd Qu.:0.8846   3rd Qu.:0.4864   3rd Qu.:20.20280         
##  Max.   :0.9488   Max.   :0.5928   Max.   :25.67152         
## 
## Window: rectangle = [5.54, 5.58] x [-73.3, -73.25] units
##                     (0.04 x 0.05 units)
## Window area = 0.002 square units
set.seed(1000579855)
seqlat=seq(from=0,to=2000,by=2) #cm
seqlong=seq(from=0,to=500,by=2)#cm
lat=sample(seqlat,size = 150,replace = TRUE)
lon=sample(seqlong,size=150,replace=TRUE)
xyn=data.frame(x=lon,y=lat)
SMI=sort.int(runif(150,0.7,0.95),partial=10)
NDVI=sort.int(rnorm(150,0.45,0.06),partial=10)
LST=sort.int(26*rbeta(150,shape1=0.87,shape2=0.91),partial=10)
crop=factor(ifelse(rgamma(n=150,rate=0.8,shape=0.5)<0.5,0,1))
df2=data.frame(xyn,SMI,NDVI,LST,crop)
library(spatstat)
dataxyn=ppp(xyn$x,xyn$y,xrange=c(min(xyn$x),max(xyn$x)),yrange=(c(min(xyn$y),max(xyn$y))))
any(duplicated(dataxyn))
## [1] FALSE
yn=unique(dataxyn)
plot(yn,size=0.5)

summary(yn)
## Planar point pattern:  150 points
## Average intensity 0.0001510574 points per square unit
## 
## Coordinates are integers
## i.e. rounded to the nearest unit
## 
## Window: rectangle = [0, 500] x [4, 1990] units
##                     (500 x 1986 units)
## Window area = 993000 square units
#17
dens=summary(yn)$intensity*(1000)^2;dens 
## [1] 151.0574
lambda=summary(yn)$intensity*(1000)^2;lambda 
## [1] 151.0574
#18

quadratcount(yn, nx = 4, ny = 4) 
##                      x
## y                     [0,125) [125,250) [250,375) [375,500]
##   [1.49e+03,1.99e+03]      11         8         7        11
##   [997,1.49e+03)           12        15         7         6
##   [500,997)                 8         9         5        10
##   [4,500)                   9        19         5         8
Q <- quadratcount(yn, nx = 4, ny = 4)
plot(yn,size=0.7)  
plot(Q, add = TRUE)

#19
dens =density(yn) 
plot(dens)         
plot(yn,add=TRUE)

persp(dens) 

#20
contour(dens)

#21
#Grafico covariable índice de vegetación de diferencia normalizado.
par(mfrow = c(1, 2))
plot(yn)
plot(NDVI)

par(mfrow = c(1, 1))

#Grafico de la temperatura en el suelo
par(mfrow = c(1, 2))
plot(yn)
plot(LST)

par(mfrow = c(1, 1))

#Existencia de vegetación.
par(mfrow = c(1, 2))
plot(yn)
plot(crop)

par(mfrow = c(1, 1))

#humedad del suelo.
par(mfrow = c(1, 2))
plot(yn)
plot(SMI)

par(mfrow = c(1, 1))
#22

\(H_0:\) Es aleatorea la distribucion de los cuadrantes (Distribucion poisson) \(H_0:\) Los cuadrantes no son aleatorios

H = quadrat.test(yn, nx = 4, ny = 4); H
## 
##  Chi-squared test of CSR using quadrat counts
## 
## data:  yn
## X2 = 21.733, df = 15, p-value = 0.23
## alternative hypothesis: two.sided
## 
## Quadrats: 4 by 4 grid of tiles
plot(yn,size=0.01)
plot(H, add = TRUE, cex = 0.9)

\(No \thinspace existen \thinspace pruebas \thinspace suficientes \thinspace para \thinspace rechazar \thinspace la \thinspace hipotesis \thinspace nula\)

#23
#24
A <- quantile(NDVI, probs = (0:4)/4)
NDVI_cortado <- cut(NDVI, breaks = A, labels = 1:4)
#Z <- tess(image= NDVI_cortado) Genera un error que dice, "Error in as.im.default(image) : Can't convert X to a pixel image"
#quadrat.test(yn, tess = Z)
#25
PoisModel= ppm(yn, ~1)
PoisModel
## Stationary Poisson process
## Intensity: 0.0001510574
##              Estimate       S.E.   CI95.lo  CI95.hi Ztest      Zval
## log(lambda) -8.797851 0.08164966 -8.957881 -8.63782   *** -107.7512
#26
Model_Lat=ppm(yn~y)
Model_Lat
## Nonstationary Poisson process
## 
## Log intensity:  ~y
## 
## Fitted trend coefficients:
##   (Intercept)             y 
## -8.785105e+00 -1.281177e-05 
## 
##                  Estimate         S.E.      CI95.lo       CI95.hi Ztest
## (Intercept) -8.785105e+00 0.1632721269 -9.105112145 -8.4650971682   ***
## y           -1.281177e-05 0.0001424211 -0.000291952  0.0002663284      
##                     Zval
## (Intercept) -53.80651813
## y            -0.08995701
#27
Model_Long=ppm(yn~x)
Model_Long
## Nonstationary Poisson process
## 
## Log intensity:  ~x
## 
## Fitted trend coefficients:
##   (Intercept)             x 
## -8.6439005707 -0.0006322991 
## 
##                  Estimate         S.E.     CI95.lo       CI95.hi Ztest
## (Intercept) -8.6439005707 0.1572144119 -8.95203516 -8.3357659855   ***
## x           -0.0006322991 0.0005670975 -0.00174379  0.0004791917      
##                   Zval
## (Intercept) -54.981604
## x            -1.114974
#28
Modelo_sumaxy =ppm(yn, ~x + y)
Modelo_sumaxy
## Nonstationary Poisson process
## 
## Log intensity:  ~x + y
## 
## Fitted trend coefficients:
##   (Intercept)             x             y 
## -8.631185e+00 -6.322901e-04 -1.278328e-05 
## 
##                  Estimate         S.E.      CI95.lo       CI95.hi Ztest
## (Intercept) -8.631185e+00 0.2114250551 -9.045570614 -8.2167996271   ***
## x           -6.322901e-04 0.0005670977 -0.001743781  0.0004792009      
## y           -1.278328e-05 0.0001424203 -0.000291922  0.0002663555      
##                     Zval
## (Intercept) -40.82385182
## x            -1.11495797
## y            -0.08975738

\(\lambda_{\theta}((x, y))=\exp \left(\theta_{0}+\theta_{1} x+\theta_{2} y\right)\) Formula pag. 97

#29

\(\lambda_{\theta}((x, y))= \begin{cases}\exp (-5.1222) & \text { if } x<300 \\ \exp (-5.1222055+0.5283049) & \text { if } x \geq 300\end{cases}\)

Modelo_polino= ppm(yn, ~polynom(x, y, 2))
Modelo_polino
## Nonstationary Poisson process
## 
## Log intensity:  ~x + y + I(x^2) + I(x * y) + I(y^2)
## 
## Fitted trend coefficients:
##   (Intercept)             x             y        I(x^2)      I(x * y) 
## -8.537772e+00 -1.819548e-04 -4.011439e-04 -9.742665e-07  2.677938e-08 
##        I(y^2) 
##  1.919375e-07 
## 
##                  Estimate         S.E.       CI95.lo       CI95.hi Ztest
## (Intercept) -8.537772e+00 3.962618e-01 -9.314431e+00 -7.761113e+00   ***
## x           -1.819548e-04 2.435064e-03 -4.954593e-03  4.590683e-03      
## y           -4.011439e-04 6.061152e-04 -1.589108e-03  7.868201e-04      
## I(x^2)      -9.742665e-07 4.419827e-06 -9.636968e-06  7.688435e-06      
## I(x * y)     2.677938e-08 9.720067e-07 -1.878319e-06  1.931877e-06      
## I(y^2)       1.919375e-07 2.732659e-07 -3.436539e-07  7.275289e-07      
##                     Zval
## (Intercept) -21.54578552
## x            -0.07472278
## y            -0.66182784
## I(x^2)       -0.22043090
## I(x * y)      0.02755061
## I(y^2)        0.70238363
side = function(s) factor(ifelse(s < 300, "izquierda","derecha"))
ppm(bei, ~side(x))
## Nonstationary Poisson process
## 
## Log intensity:  ~side(x)
## 
## Fitted trend coefficients:
##      (Intercept) side(x)izquierda 
##       -5.1222055        0.5283049 
## 
##                    Estimate       S.E.    CI95.lo    CI95.hi Ztest       Zval
## (Intercept)      -5.1222055 0.02188965 -5.1651084 -5.0793026   *** -234.00128
## side(x)izquierda  0.5283049 0.03373948  0.4621768  0.5944331   ***   15.65836
#30
#desviación de y, x, x+y
anova(Model_Lat)  
## Analysis of Deviance Table
## Terms added sequentially (first to last)
## 
##      Df  Deviance Npar
## NULL                 1
## y     1 0.0080924    2
anova(Model_Long)
## Analysis of Deviance Table
## Terms added sequentially (first to last)
## 
##      Df Deviance Npar
## NULL                1
## x     1   1.2463    2
anova(Modelo_sumaxy)  
## Analysis of Deviance Table
## Terms added sequentially (first to last)
## 
##      Df Deviance Npar
## NULL                1
## x     1  1.24626    2
## y     1  0.00806    3
#31
summary(anova(Modelo_polino,Modelo_sumaxy,test="Chi"))
##       Npar            Df        Deviance          Pr(>Chi)     
##  Min.   :3.00   Min.   :-3   Min.   :-0.5372   Min.   :0.9107  
##  1st Qu.:3.75   1st Qu.:-3   1st Qu.:-0.5372   1st Qu.:0.9107  
##  Median :4.50   Median :-3   Median :-0.5372   Median :0.9107  
##  Mean   :4.50   Mean   :-3   Mean   :-0.5372   Mean   :0.9107  
##  3rd Qu.:5.25   3rd Qu.:-3   3rd Qu.:-0.5372   3rd Qu.:0.9107  
##  Max.   :6.00   Max.   :-3   Max.   :-0.5372   Max.   :0.9107  
##                 NA's   :1    NA's   :1         NA's   :1