{"id":269,"date":"2011-11-02T14:32:10","date_gmt":"2011-11-02T18:32:10","guid":{"rendered":"http:\/\/web.colby.edu\/mgimond\/?p=269"},"modified":"2011-11-02T14:32:10","modified_gmt":"2011-11-02T18:32:10","slug":"r-k-function","status":"publish","type":"post","link":"https:\/\/web.colby.edu\/mgimond\/2011\/11\/02\/r-k-function\/","title":{"rendered":"R: K-function"},"content":{"rendered":"<h2><span style=\"color: #3366ff\">The following example assumes a stationary point process.<\/span><\/h2>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\nlibrary(spatstat)\r\ndata(simdat)\r\nX = simdat\r\nplot(X)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-270\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot01.jpg\" alt=\"\" width=\"302\" height=\"298\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot01.jpg 302w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot01-300x296.jpg 300w\" sizes=\"(max-width: 302px) 100vw, 302px\" \/><\/a><\/p>\n<pre class=\"brush: r; first-line: 5; title: ; notranslate\" title=\"\">\r\nE = envelope(X, Kest,nsim=99)\r\nplot(E, sqrt(.\/pi)-r ~ r)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot02.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-271\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot02.jpeg\" alt=\"\" width=\"356\" height=\"246\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot02.jpeg 743w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot02-300x206.jpg 300w\" sizes=\"(max-width: 356px) 100vw, 356px\" \/><\/a><\/p>\n<h2><strong><span style=\"color: #3366ff\">This example does NOT assume a stationary process.<\/span><\/strong><\/h2>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\nlibrary(spatstat)\r\ndata(lansing)\r\n# inhomogeneous pattern of maples\r\nX = unmark(split(lansing)$maple)\r\nplot(X)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-272\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03.jpg\" alt=\"\" width=\"272\" height=\"274\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03.jpg 272w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03-150x150.jpg 150w\" sizes=\"(max-width: 272px) 100vw, 272px\" \/><\/a><\/p>\n<pre class=\"brush: r; first-line: 6; title: ; notranslate\" title=\"\">\r\n# Intensity function estimated by model-fitting\r\n# Fit spatial trend: polynomial in x and y coordinates\r\nfit = ppm(X, ~ polynom(x,y,2), Poisson())\r\n# (a) predict intensity values at points themselves,\r\n#      obtaining a vector of lambda values\r\nlambda = predict(fit, locations=X, type=&quot;trend&quot;)\r\n# inhomogeneous K function\r\nKi = Kinhom(X, lambda)\r\nplot(Ki)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot1.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-273\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot1.jpeg\" alt=\"\" width=\"366\" height=\"372\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot1.jpeg 610w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot1-295x300.jpg 295w\" sizes=\"(max-width: 366px) 100vw, 366px\" \/><\/a><\/p>\n<pre class=\"brush: r; first-line: 15; title: ; notranslate\" title=\"\">\r\n# (b) predict intensity at all locations,\r\n#      obtaining a pixel image\r\nlambda = predict(fit, type=&quot;trend&quot;)\r\nplot(lambda)\r\nplot(X,add=T)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot011.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-275\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot011.jpeg\" alt=\"\" width=\"366\" height=\"372\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot011.jpeg 610w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot011-295x300.jpg 295w\" sizes=\"(max-width: 366px) 100vw, 366px\" \/><\/a><\/p>\n<pre class=\"brush: r; first-line: 20; title: ; notranslate\" title=\"\">\r\nKi = Kinhom(X, lambda)\r\nplot(Ki)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot021.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-276\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot021.jpeg\" alt=\"\" width=\"366\" height=\"372\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot021.jpeg 610w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot021-295x300.jpg 295w\" sizes=\"(max-width: 366px) 100vw, 366px\" \/><\/a><\/p>\n<pre class=\"brush: r; first-line: 22; title: ; notranslate\" title=\"\">\r\n# How to make simulation envelopes:\r\n#      Example shows method (1b)\r\nlambda = predict(fit, type=&quot;trend&quot;)\r\nKen = envelope(X, Kinhom, nsim=99,\r\n                 simulate=expression(rpoispp(lambda)),\r\n                 lambda=lambda, correction=&quot;trans&quot;)\r\nplot(Ken, sqrt(.) - r ~ r)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-277\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03.jpeg\" alt=\"\" width=\"366\" height=\"372\" srcset=\"https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03.jpeg 610w, https:\/\/web.colby.edu\/mgimond\/files\/2011\/10\/Rplot03-295x300.jpg 295w\" sizes=\"(max-width: 366px) 100vw, 366px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following example assumes a stationary point process. This example does NOT assume a stationary process.<\/p>\n","protected":false},"author":1199,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[12807,12808],"tags":[],"_links":{"self":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/269"}],"collection":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/users\/1199"}],"replies":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/comments?post=269"}],"version-history":[{"count":22,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/269\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/269\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/media?parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/categories?post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/tags?post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}