R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
library(readxl)
Fresno_1_Da <- read_excel("C:/Users/linam/Downloads/Fresno_1_Da.xlsx", 
                          sheet = "Sheet1")
Fresno_1_Da
## # A tibble: 2,363 x 9
##    id_arbol Latitude Longitude Date2 `Psychro Wet Bu~ `Station Pressu~
##    <chr>       <dbl>     <dbl> <chr>            <dbl>            <dbl>
##  1 1            2.38     -76.6 21/0~             14.8             805.
##  2 2            2.38     -76.6 21/0~             11.6             805.
##  3 3            2.38     -76.6 21/0~             12.9             806.
##  4 4            2.38     -76.6 21/0~             14.1             806.
##  5 5            2.38     -76.6 21/0~             14.3             805.
##  6 6            2.38     -76.6 21/0~             14.2             805.
##  7 7            2.38     -76.6 21/0~             14.4             805.
##  8 8            2.38     -76.6 21/0~             12.8             805.
##  9 9            2.38     -76.6 21/0~             15               805 
## 10 10           2.38     -76.6 21/0~             14               805.
## # ... with 2,353 more rows, and 3 more variables: `Relative Humidity` <dbl>,
## #   Crosswind <dbl>, Temperature <dbl>
plot(Fresno_1_Da[,3:2])
require(ggplot2)
## Loading required package: ggplot2

ggplot(Fresno_1_Da,aes(x=Longitude, y=Longitude))+geom_point()+theme_bw()

ggplot(Fresno_1_Da,aes(x=Longitude, y=Longitude))+geom_point()+theme_bw()+facet_wrap(~Date2)

ggplot(Fresno_1_Da,aes(x=Longitude, y=Latitude, color=Temperature))+geom_point()+theme_bw()+facet_wrap(~Date2)+scale_color_continuous(type="viridis")

###Filtramos el instante 1 del tiempo

fechas=unique(Fresno_1_Da$Date2)
pos=which(Fresno_1_Da$Date2==fechas[4])
datos_m1=Fresno_1_Da[pos,]
datos_m1
## # A tibble: 394 x 9
##    id_arbol Latitude Longitude Date2 `Psychro Wet Bu~ `Station Pressu~
##    <chr>       <dbl>     <dbl> <chr>            <dbl>            <dbl>
##  1 1            2.38     -76.6 1/10~             17.4             799.
##  2 2            2.38     -76.6 1/10~             18.4             800.
##  3 3            2.38     -76.6 1/10~             17.4             800 
##  4 4            2.38     -76.6 1/10~             16.9             800.
##  5 5            2.38     -76.6 1/10~             17.3             800.
##  6 6            2.38     -76.6 1/10~             18.4             799.
##  7 7            2.38     -76.6 1/10~             16.6             799.
##  8 8            2.38     -76.6 1/10~             17.1             799.
##  9 9            2.38     -76.6 1/10~             17               800.
## 10 10           2.38     -76.6 1/10~             16.4             800.
## # ... with 384 more rows, and 3 more variables: `Relative Humidity` <dbl>,
## #   Crosswind <dbl>, Temperature <dbl>
require(leaflet)
## Loading required package: leaflet
leaflet() %>% addCircleMarkers(lng=datos_m1$Longitude,lat=datos_m1$Latitude, radius=0.05, color= "Black", opacity=0.9, label = datos_m1$id_arbol)%>% addTiles()
require(geoR)
## Loading required package: geoR
## --------------------------------------------------------------
##  Analysis of Geostatistical Data
##  For an Introduction to geoR go to http://www.leg.ufpr.br/geoR
##  geoR version 1.8-1 (built on 2020-02-08) is now loaded
## --------------------------------------------------------------
geo_datos=as.geodata(datos_m1,coords.col=3:2,data.col=9)
geo_datos
## $coords
##        Longitude Latitude
##   [1,] -76.61264 2.381290
##   [2,] -76.61259 2.381320
##   [3,] -76.61254 2.381353
##   [4,] -76.61261 2.381374
##   [5,] -76.61266 2.381335
##   [6,] -76.61271 2.381313
##   [7,] -76.61282 2.381298
##   [8,] -76.61276 2.381342
##   [9,] -76.61270 2.381366
##  [10,] -76.61263 2.381415
##  [11,] -76.61268 2.381459
##  [12,] -76.61271 2.381429
##  [13,] -76.61275 2.381400
##  [14,] -76.61283 2.381336
##  [15,] -76.61286 2.381292
##  [16,] -76.61293 2.381310
##  [17,] -76.61288 2.381354
##  [18,] -76.61284 2.381396
##  [19,] -76.61280 2.381428
##  [20,] -76.61273 2.381484
##  [21,] -76.61280 2.381517
##  [22,] -76.61282 2.381486
##  [23,] -76.61286 2.381453
##  [24,] -76.61290 2.381405
##  [25,] -76.61292 2.381355
##  [26,] -76.61296 2.381295
##  [27,] -76.61301 2.381266
##  [28,] -76.61310 2.381211
##  [29,] -76.61306 2.381251
##  [30,] -76.61303 2.381306
##  [31,] -76.61299 2.381364
##  [32,] -76.61294 2.381411
##  [33,] -76.61291 2.381464
##  [34,] -76.61288 2.381514
##  [35,] -76.61284 2.381542
##  [36,] -76.61282 2.381568
##  [37,] -76.61284 2.381621
##  [38,] -76.61287 2.381598
##  [39,] -76.61291 2.381561
##  [40,] -76.61294 2.381508
##  [41,] -76.61298 2.381460
##  [42,] -76.61301 2.381415
##  [43,] -76.61304 2.381366
##  [44,] -76.61308 2.381309
##  [45,] -76.61311 2.381264
##  [46,] -76.61315 2.381207
##  [47,] -76.61319 2.381144
##  [48,] -76.61341 2.380892
##  [49,] -76.61337 2.380951
##  [50,] -76.61333 2.380991
##  [51,] -76.61330 2.381045
##  [52,] -76.61325 2.381096
##  [53,] -76.61319 2.381201
##  [54,] -76.61316 2.381255
##  [55,] -76.61313 2.381313
##  [56,] -76.61309 2.381361
##  [57,] -76.61305 2.381414
##  [58,] -76.61302 2.381482
##  [59,] -76.61299 2.381522
##  [60,] -76.61296 2.381580
##  [61,] -76.61292 2.381630
##  [62,] -76.61289 2.381655
##  [63,] -76.61286 2.381673
##  [64,] -76.61292 2.381715
##  [65,] -76.61294 2.381688
##  [66,] -76.61298 2.381630
##  [67,] -76.61301 2.381581
##  [68,] -76.61304 2.381528
##  [69,] -76.61307 2.381467
##  [70,] -76.61311 2.381419
##  [71,] -76.61319 2.381319
##  [72,] -76.61322 2.381265
##  [73,] -76.61325 2.381210
##  [74,] -76.61328 2.381153
##  [75,] -76.61333 2.381113
##  [76,] -76.61336 2.381052
##  [77,] -76.61339 2.380998
##  [78,] -76.61343 2.380950
##  [79,] -76.61346 2.380900
##  [80,] -76.61350 2.380856
##  [81,] -76.61353 2.380799
##  [82,] -76.61357 2.380830
##  [83,] -76.61354 2.380869
##  [84,] -76.61351 2.380917
##  [85,] -76.61344 2.381013
##  [86,] -76.61340 2.381068
##  [87,] -76.61336 2.381111
##  [88,] -76.61333 2.381169
##  [89,] -76.61330 2.381216
##  [90,] -76.61326 2.381268
##  [91,] -76.61323 2.381324
##  [92,] -76.61319 2.381377
##  [93,] -76.61316 2.381428
##  [94,] -76.61312 2.381487
##  [95,] -76.61306 2.381590
##  [96,] -76.61303 2.381647
##  [97,] -76.61299 2.381697
##  [98,] -76.61296 2.381750
##  [99,] -76.61295 2.381833
## [100,] -76.61299 2.381804
## [101,] -76.61302 2.381751
## [102,] -76.61306 2.381697
## [103,] -76.61309 2.381633
## [104,] -76.61312 2.381590
## [105,] -76.61315 2.381542
## [106,] -76.61319 2.381486
## [107,] -76.61322 2.381426
## [108,] -76.61325 2.381364
## [109,] -76.61328 2.381322
## [110,] -76.61331 2.381276
## [111,] -76.61334 2.381214
## [112,] -76.61337 2.381156
## [113,] -76.61341 2.381103
## [114,] -76.61346 2.381059
## [115,] -76.61350 2.381014
## [116,] -76.61355 2.380968
## [117,] -76.61357 2.380924
## [118,] -76.61362 2.380876
## [119,] -76.61365 2.380837
## [120,] -76.61366 2.380887
## [121,] -76.61362 2.380931
## [122,] -76.61341 2.381209
## [123,] -76.61337 2.381247
## [124,] -76.61333 2.381320
## [125,] -76.61329 2.381371
## [126,] -76.61327 2.381426
## [127,] -76.61323 2.381493
## [128,] -76.61321 2.381536
## [129,] -76.61317 2.381583
## [130,] -76.61314 2.381636
## [131,] -76.61307 2.381751
## [132,] -76.61305 2.381799
## [133,] -76.61301 2.381855
## [134,] -76.61304 2.381912
## [135,] -76.61307 2.381864
## [136,] -76.61311 2.381810
## [137,] -76.61313 2.381759
## [138,] -76.61316 2.381701
## [139,] -76.61321 2.381644
## [140,] -76.61324 2.381594
## [141,] -76.61326 2.381538
## [142,] -76.61330 2.381485
## [143,] -76.61333 2.381434
## [144,] -76.61336 2.381383
## [145,] -76.61340 2.381325
## [146,] -76.61338 2.381448
## [147,] -76.61335 2.381497
## [148,] -76.61331 2.381545
## [149,] -76.61329 2.381598
## [150,] -76.61322 2.381711
## [151,] -76.61319 2.381769
## [152,] -76.61316 2.381816
## [153,] -76.61312 2.381866
## [154,] -76.61308 2.381913
## [155,] -76.61306 2.381973
## [156,] -76.61308 2.382037
## [157,] -76.61311 2.381975
## [158,] -76.61315 2.381930
## [159,] -76.61317 2.381872
## [160,] -76.61321 2.381814
## [161,] -76.61328 2.381707
## [162,] -76.61334 2.381606
## [163,] -76.61337 2.381541
## [164,] -76.61341 2.381488
## [165,] -76.61338 2.381606
## [166,] -76.61335 2.381665
## [167,] -76.61332 2.381724
## [168,] -76.61329 2.381770
## [169,] -76.61326 2.381828
## [170,] -76.61324 2.381882
## [171,] -76.61320 2.381932
## [172,] -76.61316 2.381988
## [173,] -76.61312 2.382038
## [174,] -76.61310 2.382097
## [175,] -76.61309 2.382195
## [176,] -76.61312 2.382148
## [177,] -76.61318 2.382037
## [178,] -76.61322 2.381989
## [179,] -76.61324 2.381935
## [180,] -76.61328 2.381876
## [181,] -76.61333 2.381821
## [182,] -76.61335 2.381782
## [183,] -76.61338 2.381724
## [184,] -76.61342 2.381663
## [185,] -76.61347 2.381676
## [186,] -76.61343 2.381738
## [187,] -76.61339 2.381781
## [188,] -76.61336 2.381840
## [189,] -76.61334 2.381896
## [190,] -76.61330 2.381942
## [191,] -76.61327 2.381983
## [192,] -76.61323 2.382044
## [193,] -76.61318 2.382151
## [194,] -76.61315 2.382200
## [195,] -76.61311 2.382245
## [196,] -76.61307 2.382297
## [197,] -76.61306 2.382402
## [198,] -76.61311 2.382333
## [199,] -76.61314 2.382300
## [200,] -76.61317 2.382255
## [201,] -76.61320 2.382198
## [202,] -76.61323 2.382146
## [203,] -76.61327 2.382098
## [204,] -76.61329 2.382049
## [205,] -76.61334 2.381987
## [206,] -76.61336 2.381932
## [207,] -76.61339 2.381879
## [208,] -76.61343 2.381822
## [209,] -76.61346 2.381784
## [210,] -76.61350 2.381727
## [211,] -76.61352 2.381671
## [212,] -76.61354 2.381738
## [213,] -76.61351 2.381798
## [214,] -76.61347 2.381851
## [215,] -76.61344 2.381892
## [216,] -76.61342 2.381937
## [217,] -76.61338 2.381996
## [218,] -76.61335 2.382055
## [219,] -76.61332 2.382108
## [220,] -76.61328 2.382167
## [221,] -76.61325 2.382213
## [222,] -76.61322 2.382263
## [223,] -76.61319 2.382322
## [224,] -76.61316 2.382362
## [225,] -76.61312 2.382405
## [226,] -76.61307 2.382451
## [227,] -76.61310 2.382497
## [228,] -76.61315 2.382458
## [229,] -76.61318 2.382406
## [230,] -76.61322 2.382367
## [231,] -76.61323 2.382319
## [232,] -76.61326 2.382266
## [233,] -76.61330 2.382216
## [234,] -76.61334 2.382155
## [235,] -76.61337 2.382111
## [236,] -76.61340 2.382053
## [237,] -76.61343 2.382002
## [238,] -76.61347 2.381950
## [239,] -76.61351 2.381889
## [240,] -76.61354 2.381839
## [241,] -76.61358 2.381777
## [242,] -76.61362 2.381766
## [243,] -76.61364 2.381813
## [244,] -76.61359 2.381858
## [245,] -76.61356 2.381904
## [246,] -76.61352 2.381949
## [247,] -76.61349 2.381994
## [248,] -76.61346 2.382058
## [249,] -76.61342 2.382103
## [250,] -76.61339 2.382166
## [251,] -76.61336 2.382219
## [252,] -76.61332 2.382270
## [253,] -76.61329 2.382326
## [254,] -76.61326 2.382380
## [255,] -76.61324 2.382442
## [256,] -76.61320 2.382480
## [257,] -76.61316 2.382527
## [258,] -76.61322 2.382524
## [259,] -76.61326 2.382482
## [260,] -76.61328 2.382422
## [261,] -76.61331 2.382363
## [262,] -76.61335 2.382325
## [263,] -76.61338 2.382267
## [264,] -76.61341 2.382226
## [265,] -76.61344 2.382160
## [266,] -76.61348 2.382106
## [267,] -76.61352 2.382052
## [268,] -76.61355 2.382005
## [269,] -76.61358 2.381961
## [270,] -76.61362 2.381913
## [271,] -76.61366 2.381857
## [272,] -76.61369 2.381802
## [273,] -76.61372 2.381852
## [274,] -76.61368 2.381917
## [275,] -76.61364 2.381964
## [276,] -76.61361 2.382025
## [277,] -76.61357 2.382074
## [278,] -76.61353 2.382113
## [279,] -76.61350 2.382169
## [280,] -76.61347 2.382227
## [281,] -76.61343 2.382275
## [282,] -76.61340 2.382334
## [283,] -76.61336 2.382377
## [284,] -76.61333 2.382442
## [285,] -76.61331 2.382489
## [286,] -76.61327 2.382551
## [287,] -76.61335 2.382532
## [288,] -76.61338 2.382480
## [289,] -76.61341 2.382436
## [290,] -76.61344 2.382384
## [291,] -76.61347 2.382326
## [292,] -76.61351 2.382271
## [293,] -76.61355 2.382211
## [294,] -76.61357 2.382162
## [295,] -76.61361 2.382118
## [296,] -76.61365 2.382067
## [297,] -76.61367 2.382013
## [298,] -76.61372 2.381961
## [299,] -76.61375 2.381922
## [300,] -76.61379 2.381871
## [301,] -76.61378 2.381960
## [302,] -76.61374 2.382011
## [303,] -76.61370 2.382054
## [304,] -76.61367 2.382114
## [305,] -76.61360 2.382220
## [306,] -76.61356 2.382270
## [307,] -76.61350 2.382361
## [308,] -76.61347 2.382426
## [309,] -76.61344 2.382471
## [310,] -76.61339 2.382535
## [311,] -76.61346 2.382526
## [312,] -76.61350 2.382476
## [313,] -76.61353 2.382430
## [314,] -76.61356 2.382378
## [315,] -76.61366 2.382214
## [316,] -76.61370 2.382173
## [317,] -76.61373 2.382116
## [318,] -76.61377 2.382066
## [319,] -76.61381 2.382011
## [320,] -76.61385 2.381955
## [321,] -76.61389 2.381983
## [322,] -76.61386 2.382025
## [323,] -76.61383 2.382080
## [324,] -76.61379 2.382119
## [325,] -76.61376 2.382171
## [326,] -76.61371 2.382228
## [327,] -76.61369 2.382286
## [328,] -76.61365 2.382331
## [329,] -76.61359 2.382436
## [330,] -76.61355 2.382486
## [331,] -76.61352 2.382525
## [332,] -76.61354 2.382587
## [333,] -76.61358 2.382533
## [334,] -76.61361 2.382485
## [335,] -76.61365 2.382441
## [336,] -76.61375 2.382274
## [337,] -76.61378 2.382226
## [338,] -76.61382 2.382176
## [339,] -76.61386 2.382119
## [340,] -76.61389 2.382062
## [341,] -76.61400 2.382030
## [342,] -76.61398 2.382076
## [343,] -76.61393 2.382136
## [344,] -76.61390 2.382175
## [345,] -76.61386 2.382224
## [346,] -76.61382 2.382271
## [347,] -76.61377 2.382325
## [348,] -76.61374 2.382368
## [349,] -76.61371 2.382424
## [350,] -76.61367 2.382486
## [351,] -76.61364 2.382538
## [352,] -76.61360 2.382581
## [353,] -76.61363 2.382629
## [354,] -76.61368 2.382582
## [355,] -76.61371 2.382540
## [356,] -76.61373 2.382481
## [357,] -76.61376 2.382433
## [358,] -76.61382 2.382375
## [359,] -76.61384 2.382331
## [360,] -76.61388 2.382293
## [361,] -76.61391 2.382226
## [362,] -76.61397 2.382176
## [363,] -76.61397 2.382129
## [364,] -76.61405 2.382061
## [365,] -76.61408 2.382066
## [366,] -76.61405 2.382136
## [367,] -76.61402 2.382188
## [368,] -76.61398 2.382236
## [369,] -76.61395 2.382279
## [370,] -76.61391 2.382331
## [371,] -76.61387 2.382377
## [372,] -76.61382 2.382436
## [373,] -76.61379 2.382487
## [374,] -76.61376 2.382535
## [375,] -76.61374 2.382582
## [376,] -76.61370 2.382639
## [377,] -76.61373 2.382694
## [378,] -76.61375 2.382641
## [379,] -76.61379 2.382588
## [380,] -76.61383 2.382536
## [381,] -76.61385 2.382484
## [382,] -76.61389 2.382430
## [383,] -76.61395 2.382374
## [384,] -76.61396 2.382333
## [385,] -76.61401 2.382278
## [386,] -76.61406 2.382220
## [387,] -76.61408 2.382183
## [388,] -76.61412 2.382121
## [389,] -76.61415 2.382056
## [390,] -76.61391 2.382486
## [391,] -76.61388 2.382543
## [392,] -76.61385 2.382596
## [393,] -76.61382 2.382643
## [394,] -76.61379 2.382693
## 
## $data
##   [1] 22.9 23.8 22.6 22.3 22.7 23.1 21.0 21.6 21.4 20.8 21.3 21.1 21.1 21.3 21.5
##  [16] 21.6 21.4 21.2 21.4 21.3 21.1 21.4 21.4 21.3 21.2 21.1 21.0 21.1 21.0 21.2
##  [31] 21.2 21.4 21.4 21.0 21.0 21.1 21.0 20.9 21.0 21.0 21.2 21.2 21.2 21.5 21.7
##  [46] 21.3 21.1 21.1 21.0 21.0 21.1 21.2 21.2 21.4 21.5 21.8 21.9 21.6 21.6 21.5
##  [61] 21.6 21.5 21.6 21.9 21.5 21.7 22.7 22.7 22.5 22.8 23.0 22.1 22.2 21.8 21.7
##  [76] 21.2 21.9 21.7 21.4 21.5 21.8 21.9 21.7 21.6 21.6 21.4 21.4 21.5 21.5 22.0
##  [91] 22.0 22.0 22.1 22.0 22.1 22.5 21.4 20.6 21.0 20.7 20.9 21.3 21.3 21.3 21.1
## [106] 21.4 21.2 21.1 21.3 21.2 21.2 21.2 21.2 21.3 21.3 21.1 21.6 21.6 21.8 24.1
## [121] 23.6 23.3 24.0 24.2 24.2 25.0 25.1 24.6 24.9 25.1 25.0 25.6 25.2 24.6 25.6
## [136] 26.8 26.5 25.7 26.5 26.8 26.2 26.5 25.9 26.7 27.2 27.2 26.7 26.5 26.6 25.6
## [151] 28.1 27.2 27.2 26.9 26.4 28.2 27.4 27.7 27.7 26.8 26.4 25.5 26.0 25.7 25.4
## [166] 25.3 25.0 25.2 25.5 24.8 25.4 25.6 26.4 25.8 25.5 23.4 23.5 23.0 23.1 23.0
## [181] 23.9 23.9 23.6 25.8 25.7 27.3 24.7 26.2 26.2 28.6 28.4 31.4 30.9 30.5 29.7
## [196] 30.5 27.6 29.2 25.6 26.7 25.9 25.2 26.1 26.2 25.8 26.8 25.5 25.3 27.1 29.3
## [211] 29.8 28.5 27.7 29.0 29.4 29.5 29.7 29.5 29.9 28.3 29.4 29.8 29.8 29.7 28.9
## [226] 29.3 28.1 27.1 25.7 25.7 28.2 27.5 27.7 28.1 27.9 27.4 26.2 27.1 27.3 25.8
## [241] 26.8 29.2 30.0 28.7 29.8 29.4 28.6 29.4 29.3 28.2 29.5 30.3 30.4 29.0 28.4
## [256] 28.7 28.2 28.4 28.9 27.4 29.0 28.9 28.2 27.3 28.6 28.2 27.7 26.9 28.1 27.8
## [271] 27.0 27.7 27.6 28.6 28.5 27.5 27.3 26.5 26.3 26.0 26.2 27.2 26.9 28.7 26.4
## [286] 25.1 25.4 25.3 26.1 26.8 27.0 27.3 27.1 26.1 28.4 27.2 27.5 26.6 27.4 28.3
## [301] 26.8 26.1 25.4 24.7 26.3 24.9 27.0 26.3 25.2 25.3 25.6 25.4 24.8 23.5 23.8
## [316] 24.0 24.2 25.2 24.6 23.2 23.4 22.0 22.3 22.5 22.3 22.7 23.5 23.1 24.5 24.8
## [331] 25.0 25.9 25.5 24.1 28.0 25.8 25.1 24.4 26.4 25.0 24.8 26.0 26.3 25.7 25.2
## [346] 27.0 27.1 29.4 26.7 29.6 30.0 22.6 24.0 23.8 22.4 21.4 21.7 22.3 22.9 23.3
## [361] 23.0 22.9 22.4 22.1 23.0 22.6 23.3 22.3 22.4 23.2 23.4 22.9 25.4 24.2 22.0
## [376] 21.5 22.0 22.7 22.7 21.4 21.9 22.0 21.1 21.8 23.4 22.1 22.0 21.8 21.6 23.5
## [391] 22.4 23.3 21.8 24.4
## 
## attr(,"class")
## [1] "geodata"
plot(geo_datos)

summary(dist(geo_datos[[1]]))
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
## 3.302e-05 4.017e-04 6.544e-04 7.038e-04 9.703e-04 1.912e-03
variograma=variog(geo_datos, option = "bin", uvec =seq(0,0.0009703,0.00003))
## variog: computing omnidirectional variogram
plot(variograma)

variograma.env=variog.mc.env(geo_datos,obj=variograma)
## variog.env: generating 99 simulations by permutating data values
## variog.env: computing the empirical variogram for the 99 simulations
## variog.env: computing the envelops
plot (variograma, envelope=variograma.env)

###Ajuste del Modelo de Semivarianza"

ini.vals=expand.grid(seq(8,12,l=10), seq(0.0006,0.0008,l=10))
model_mco_gaus=variofit(variograma,ini=ini.vals,cov.model="gaussian",wei="npair", min="optim", nugget=0)
## variofit: covariance model used is gaussian 
## variofit: weights used: npairs 
## variofit: minimisation function used: optim 
## variofit: searching for best initial value ... selected values:
##               sigmasq phi   tausq kappa
## initial.value "12"    "0"   "0"   "0.5"
## status        "est"   "est" "est" "fix"
## loss value: 128786.888699576
model_mco_exp=variofit(variograma,ini=ini.vals,cov.model="exponential",wei="npair", min="optim", nugget=0)  
## variofit: covariance model used is exponential 
## variofit: weights used: npairs 
## variofit: minimisation function used: optim 
## variofit: searching for best initial value ... selected values:
##               sigmasq phi   tausq kappa
## initial.value "12"    "0"   "0"   "0.5"
## status        "est"   "est" "est" "fix"
## loss value: 161534.404990903
model_mco_sphe=variofit(variograma,ini=ini.vals,cov.model="spheric",wei="npair", min="optim", nugget=0) 
## variofit: covariance model used is spherical 
## variofit: weights used: npairs 
## variofit: minimisation function used: optim 
## variofit: searching for best initial value ... selected values:
##               sigmasq phi   tausq kappa
## initial.value "10.22" "0"   "0"   "0.5"
## status        "est"   "est" "est" "fix"
## loss value: 99030.0417375569
lines(model_mco_gaus, col="red")
lines(model_mco_exp, col="blue")
lines( model_mco_sphe,col="purple")

##El gausiano presenta el mejor ajuste
model_mco_gaus
## variofit: model parameters estimated by WLS (weighted least squares):
## covariance model is: gaussian
## parameter estimates:
##   tausq sigmasq     phi 
##  1.2062 12.6072  0.0006 
## Practical Range with cor=0.05 for asymptotic range: 0.00108736
## 
## variofit: minimised weighted sum of squares = 14912.21
min(geo_datos$coords[,1])
## [1] -76.61415
max(geo_datos$coords[,1])
## [1] -76.61254
min(geo_datos$coords[,2])
## [1] 2.380799
max(geo_datos$coords[,2])
## [1] 2.382694
geodatos_grid=expand.grid(lat=seq(-76.61415,-76.61254,l=100),long=seq(2.380799,2.382694,l=100))
plot(geodatos_grid)
points(geo_datos$coords,col="red", pch="16")

geodatos_ko=krige.conv(geo_datos,loc=geodatos_grid,krige=krige.control(nugget=0,trend.d = "cte", trend.l= "cte", cov.pars =c(sigmasq=1.5665, phi=0.0004)))
## krige.conv: model with constant mean
## krige.conv: Kriging performed using global neighbourhood
par(mfrow=c(1,1))
image(geodatos_ko,main="kriging predict", xlab="Lat", ylab="Long")
contour(geodatos_ko,main="Kriging Predict", add=TRUE, drawlabels=TRUE) 

image(geodatos_ko,main="kriging StDv predict", val=sqrt(geodatos_ko$krige.var),xlab="East", ylab="North")

contour(geodatos_ko,main="kriging StDv predict", val=sqrt(geodatos_ko$krige.var),xlab="East", ylab="North")

valida=xvalid(geo_datos,model=model_mco_gaus)
## xvalid: number of data locations       = 394
## xvalid: number of validation locations = 394
## xvalid: performing cross-validation at location ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 
## xvalid: end of cross-validation
MAE=mean(abs(valida$error))
MAE
## [1] 1.10579
require(raster)
## Loading required package: raster
## Loading required package: sp
mat_imagen=data.frame(geodatos_grid, geodatos_ko$predict)
tem_m1_raster=rasterFromXYZ(mat_imagen)
plot(tem_m1_raster)


library(readr)
Fresno_area <- read_csv("C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   col_character()
## )
## Warning: 9 parsing failures.
## row col  expected        actual                                                                                                                    file
##   1               embedded null 'C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp'
##   3  -- 1 columns 2 columns     'C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp'
##  17               embedded null 'C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp'
##  17  -- 1 columns 2 columns     'C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp'
##  18               embedded null 'C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp'
## ... ... ......... ............. .......................................................................................................................
## See problems(...) for more details.
finca=shapefile("C:/Users/linam/Desktop/Doctorado-20201031T024248Z-001/Doctorado/Semestre V/Analisis Espacial de Datos/Fresno_area.shp")

plot(finca, add=TRUE)

tem_m1_raster_finca=mask(tem_m1_raster, finca)
plot(tem_m1_raster_finca)
plot(finca, add=TRUE)

crs(tem_m1_raster_finca)=crs(finca)
require(rasterVis)
## Loading required package: rasterVis
## Loading required package: lattice
## Loading required package: latticeExtra
## 
## Attaching package: 'latticeExtra'
## The following object is masked from 'package:ggplot2':
## 
##     layer
levelplot(tem_m1_raster_finca, par.settings=BuRdTheme)

require(leaflet)
leaflet() %>% addTiles() %>% addRasterImage(tem_m1_raster_finca,opacity = 0.5, colors="Spectral")
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj
## = prefer_proj): Discarded ellps WGS 84 in CRS definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in CRS definition