File: spatial-Ex.Rout.save

package info (click to toggle)
r-cran-spatial 7.3-2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 352 kB
  • ctags: 47
  • sloc: ansic: 849; makefile: 1
file content (513 lines) | stat: -rw-r--r-- 11,991 bytes parent folder | download
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513

R version 2.11.0 alpha (2010-03-28 r51461)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> pkgname <- "spatial"
> source(file.path(R.home("share"), "R", "examples-header.R"))
> options(warn = 1)
> library('spatial')
> 
> assign(".oldSearch", search(), pos = 'CheckExEnv')
> cleanEx()
> nameEx("Kaver")
> ### * Kaver
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: Kaver
> ### Title: Average K-functions from Simulations
> ### Aliases: Kaver
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty="s")
> plot(Kfn(towns, 40), type="b")
> plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)")
> for(i in 1:10) lines(Kfn(Psim(69), 10))
> lims <- Kenvl(10,100,Psim(69))
> lines(lims$x,lims$lower, lty=2, col="green")
> lines(lims$x,lims$upper, lty=2, col="green")
> lines(Kaver(10,25,Strauss(69,0.5,3.5)),  col="red")
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("Kenvl")
> ### * Kenvl
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: Kenvl
> ### Title: Compute Envelope and Average of Simulations of K-fns
> ### Aliases: Kenvl
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty="s")
> plot(Kfn(towns, 40), type="b")
> plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)")
> for(i in 1:10) lines(Kfn(Psim(69), 10))
> lims <- Kenvl(10,100,Psim(69))
> lines(lims$x,lims$lower, lty=2, col="green")
> lines(lims$x,lims$upper, lty=2, col="green")
> lines(Kaver(10,25,Strauss(69,0.5,3.5)), col="red")
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("Kfn")
> ### * Kfn
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: Kfn
> ### Title: Compute K-fn of a Point Pattern
> ### Aliases: Kfn
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty="s")
> plot(Kfn(towns, 10), type="s", xlab="distance", ylab="L(t)")
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("Psim")
> ### * Psim
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: Psim
> ### Title: Simulate Binomial Spatial Point Process
> ### Aliases: Psim
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty="s")
> plot(Kfn(towns, 10), type="s", xlab="distance", ylab="L(t)")
> for(i in 1:10) lines(Kfn(Psim(69), 10))
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("SSI")
> ### * SSI
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: SSI
> ### Title: Simulates Sequential Spatial Inhibition Point Process
> ### Aliases: SSI
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty = "s")
> plot(Kfn(towns, 10), type = "b", xlab = "distance", ylab = "L(t)")
> lines(Kaver(10, 25, SSI(69, 1.2)))
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("Strauss")
> ### * Strauss
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: Strauss
> ### Title: Simulates Strauss Spatial Point Process
> ### Aliases: Strauss
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty="s")
> plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)")
> lines(Kaver(10, 25, Strauss(69,0.5,3.5)))
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("anova.trls")
> ### * anova.trls
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: anova.trls
> ### Title: Anova tables for fitted trend surface objects
> ### Aliases: anova.trls anovalist.trls
> ### Keywords: spatial
> 
> ### ** Examples
> 
> library(stats)
> data(topo, package="MASS")
> topo0 <- surf.ls(0, topo)
> topo1 <- surf.ls(1, topo)
> topo2 <- surf.ls(2, topo)
> topo3 <- surf.ls(3, topo)
> topo4 <- surf.ls(4, topo)
> anova(topo0, topo1, topo2, topo3, topo4)
Analysis of Variance Table

Model 1: surf.ls(np = 0, x = topo)
Model 2: surf.ls(np = 1, x = topo)
Model 3: surf.ls(np = 2, x = topo)
Model 4: surf.ls(np = 3, x = topo)
Model 5: surf.ls(np = 4, x = topo)
  Res.Df Res.Sum Sq Df Sum Sq F value    Pr(>F)
1     51     196030                            
2     49      67186  2 128844 46.9843 4.040e-12
3     46      39958  3  27228 10.4482 2.325e-05
4     42      21577  4  18381  8.9447 2.558e-05
5     37      14886  5   6691  3.3265     0.014
> summary(topo4)
Analysis of Variance Table
 Model: surf.ls(np = 4, x = topo)
              Sum Sq Df    Mean Sq  F value     Pr(>F)
Regression 181143.99 14 12938.8567 32.16092 2.2204e-16
Deviation   14885.70 37   402.3162                    
Total      196029.69 51                               
Multiple R-Squared: 0.924,	Adjusted R-squared: 0.8953 
AIC: (df = 15) 324.1594
Fitted:
   Min     1Q Median     3Q    Max 
 702.1  785.0  836.3  880.5  939.1 
Residuals:
    Min      1Q  Median      3Q     Max 
-34.077 -12.568  -2.085  14.056  50.161 
> 
> 
> 
> cleanEx()
> nameEx("correlogram")
> ### * correlogram
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: correlogram
> ### Title: Compute Spatial Correlograms
> ### Aliases: correlogram
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo.kr <- surf.ls(2, topo)
> correlogram(topo.kr, 25)
> d <- seq(0, 7, 0.1)
> lines(d, expcov(d, 0.7))
> 
> 
> 
> cleanEx()
> nameEx("expcov")
> ### * expcov
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: expcov
> ### Title: Spatial Covariance Functions
> ### Aliases: expcov gaucov sphercov
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo.kr <- surf.ls(2, topo)
> correlogram(topo.kr, 25)
> d <- seq(0, 7, 0.1)
> lines(d, expcov(d, 0.7))
> 
> 
> 
> cleanEx()
> nameEx("ppinit")
> ### * ppinit
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: ppinit
> ### Title: Read a Point Process Object from a File
> ### Aliases: ppinit
> ### Keywords: spatial
> 
> ### ** Examples
> 
> towns <- ppinit("towns.dat")
> par(pty="s")
> plot(Kfn(towns, 10), type="b", xlab="distance", ylab="L(t)")
> 
> 
> 
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("pplik")
> ### * pplik
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: pplik
> ### Title: Pseudo-likelihood Estimation of a Strauss Spatial Point Process
> ### Aliases: pplik
> ### Keywords: spatial
> 
> ### ** Examples
> 
> pines <- ppinit("pines.dat")
> pplik(pines, 0.7)
[1] 0.1508756
> 
> 
> 
> cleanEx()
> nameEx("predict.trls")
> ### * predict.trls
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: predict.trls
> ### Title: Predict method for trend surface fits
> ### Aliases: predict.trls
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo2 <- surf.ls(2, topo)
> topo4 <- surf.ls(4, topo)
> x <- c(1.78, 2.21)
> y <- c(6.15, 6.15)
> z2 <- predict(topo2, x, y)
> z4 <- predict(topo4, x, y)
> cat("2nd order predictions:", z2, "\n4th order predictions:", z4, "\n")
2nd order predictions: 756.0682 747.0624 
4th order predictions: 765.5547 742.3738 
> 
> 
> 
> cleanEx()
> nameEx("prmat")
> ### * prmat
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: prmat
> ### Title: Evaluate Kriging Surface over a Grid
> ### Aliases: prmat
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo.kr <- surf.gls(2, expcov, topo, d=0.7)
> prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50)
> contour(prsurf, levels=seq(700, 925, 25))
> 
> 
> 
> cleanEx()
> nameEx("semat")
> ### * semat
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: semat
> ### Title: Evaluate Kriging Standard Error of Prediction over a Grid
> ### Aliases: semat
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo.kr <- surf.gls(2, expcov, topo, d=0.7)
> prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50)
> contour(prsurf, levels=seq(700, 925, 25))
> sesurf <- semat(topo.kr, 0, 6.5, 0, 6.5, 30)
> contour(sesurf, levels=c(22,25))
> 
> 
> 
> cleanEx()
> nameEx("surf.gls")
> ### * surf.gls
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: surf.gls
> ### Title: Fits a Trend Surface by Generalized Least-squares
> ### Aliases: surf.gls
> ### Keywords: spatial
> 
> ### ** Examples
> 
> library(MASS)  # for eqscplot
> data(topo, package="MASS")
> topo.kr <- surf.gls(2, expcov, topo, d=0.7)
> trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50)
> eqscplot(trsurf, type = "n")
> contour(trsurf, add = TRUE)
> 
> prsurf <- prmat(topo.kr, 0, 6.5, 0, 6.5, 50)
> contour(prsurf, levels=seq(700, 925, 25))
> sesurf <- semat(topo.kr, 0, 6.5, 0, 6.5, 30)
> eqscplot(sesurf, type = "n")
> contour(sesurf, levels = c(22, 25), add = TRUE)
> 
> 
> 
> cleanEx()

detaching ‘package:MASS’

> nameEx("surf.ls")
> ### * surf.ls
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: surf.ls
> ### Title: Fits a Trend Surface by Least-squares
> ### Aliases: surf.ls
> ### Keywords: spatial
> 
> ### ** Examples
> 
> library(MASS)  # for eqscplot
> data(topo, package="MASS")
> topo.kr <- surf.ls(2, topo)
> trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50)
> eqscplot(trsurf, type = "n")
> contour(trsurf, add = TRUE)
> points(topo)
> 
> eqscplot(trsurf, type = "n")
> contour(trsurf, add = TRUE)
> plot(topo.kr, add = TRUE)
> title(xlab= "Circle radius proportional to Cook's influence statistic")
> 
> 
> 
> cleanEx()

detaching ‘package:MASS’

> nameEx("trls.influence")
> ### * trls.influence
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: trls.influence
> ### Title: Regression diagnostics for trend surfaces
> ### Aliases: trls.influence plot.trls
> ### Keywords: spatial
> 
> ### ** Examples
> 
> library(MASS)  # for eqscplot
> data(topo, package = "MASS")
> topo2 <- surf.ls(2, topo)
> infl.topo2 <- trls.influence(topo2)
> (cand <- as.data.frame(infl.topo2)[abs(infl.topo2$stresid) > 1.5, ])
           r        hii   stresid         Di
1   61.21889 0.35476783  2.585852 0.61275133
4  -45.58507 0.13493260 -1.662930 0.07188916
12  44.71663 0.21022336  1.707234 0.12930392
31  52.05575 0.07154233  1.833006 0.04314966
37  54.75944 0.06974770  1.926349 0.04637112
48  97.75499 0.08574061  3.468809 0.18807312
50 -63.25149 0.27530059 -2.520972 0.40237779
> cand.xy <- topo[as.integer(rownames(cand)), c("x", "y")]
> trsurf <- trmat(topo2, 0, 6.5, 0, 6.5, 50)
> eqscplot(trsurf, type = "n")
> contour(trsurf, add = TRUE, col = "grey")
> plot(topo2, add = TRUE, div = 3)
> points(cand.xy, pch = 16, col = "orange")
> text(cand.xy, labels = rownames(cand.xy), pos = 4, offset = 0.5)
> 
> 
> 
> cleanEx()

detaching ‘package:MASS’

> nameEx("trmat")
> ### * trmat
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: trmat
> ### Title: Evaluate Trend Surface over a Grid
> ### Aliases: trmat
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo.kr <- surf.ls(2, topo)
> trsurf <- trmat(topo.kr, 0, 6.5, 0, 6.5, 50)
> 
> 
> 
> cleanEx()
> nameEx("variogram")
> ### * variogram
> 
> flush(stderr()); flush(stdout())
> 
> ### Name: variogram
> ### Title: Compute Spatial Variogram
> ### Aliases: variogram
> ### Keywords: spatial
> 
> ### ** Examples
> 
> data(topo, package="MASS")
> topo.kr <- surf.ls(2, topo)
> variogram(topo.kr, 25)
> 
> 
> 
> ### * <FOOTER>
> ###
> cat("Time elapsed: ", proc.time() - get("ptime", pos = 'CheckExEnv'),"\n")
Time elapsed:  0.601 0.012 0.615 0 0 
> grDevices::dev.off()
null device 
          1 
> ###
> ### Local variables: ***
> ### mode: outline-minor ***
> ### outline-regexp: "\\(> \\)?### [*]+" ***
> ### End: ***
> quit('no')