{"id":611,"date":"2014-04-21T15:59:58","date_gmt":"2014-04-21T20:59:58","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=611"},"modified":"2014-04-21T15:59:58","modified_gmt":"2014-04-21T20:59:58","slug":"neighbourhood-graphs","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/04\/21\/neighbourhood-graphs\/","title":{"rendered":"Neighbourhood Graphs"},"content":{"rendered":"<table style=\"color: #000000;\" summary=\"page for neig\" width=\"100%\">\n<tbody>\n<tr>\n<td>neig<\/td>\n<td align=\"right\">R Documentation<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"color: #000000;\">Neighbourhood Graphs<\/h2>\n<h3 style=\"color: #000000;\">Description<\/h3>\n<p style=\"color: #000000;\"><code>neig<\/code>\u00a0creates objects of class\u00a0<code>neig<\/code>\u00a0with :<br \/>\na list of edges<br \/>\na binary square matrix<br \/>\na list of vectors of neighbours<br \/>\nan integer (linear and circular graphs)<br \/>\na data frame of polygons (area)<\/p>\n<p style=\"color: #000000;\">scores.neig returns the eigenvectors of neighbouring,<br \/>\northonormalized scores (null average, unit variance 1\/n and null covariances) of maximal autocorrelation.<\/p>\n<p style=\"color: #000000;\">nb2neig returns an object of class\u00a0<code>neig<\/code>\u00a0using an object of class\u00a0<code>nb<\/code>\u00a0in the library &#8216;spdep&#8217;<\/p>\n<p style=\"color: #000000;\">neig2nb returns an object of class\u00a0<code>nb<\/code>\u00a0using an object of class\u00a0<code>neig<\/code><\/p>\n<p style=\"color: #000000;\">neig2mat returns the incidence matrix between edges (1 = neighbour ; 0 = no neighbour)<\/p>\n<p style=\"color: #000000;\">neig.util.GtoL and neig.util.LtoG are utilities.<\/p>\n<h3 style=\"color: #000000;\">Usage<\/h3>\n<pre style=\"color: #000000;\">neig(list = NULL, mat01 = NULL, edges = NULL,\n    n.line = NULL, n.circle = NULL, area = NULL)\n\nscores.neig  (obj) \n## S3 method for class 'neig'\nprint(x, ...) \n## S3 method for class 'neig'\nsummary(object, ...)\nnb2neig (nb)\nneig2nb (neig)\nneig2mat (neig)\n<\/pre>\n<h3 style=\"color: #000000;\">Arguments<\/h3>\n<table style=\"color: #000000;\" summary=\"R argblock\">\n<tbody>\n<tr valign=\"top\">\n<td><code>list<\/code><\/td>\n<td>a list which each component gives the number of neighbours<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>mat01<\/code><\/td>\n<td>a symmetric square matrix of 0-1 values<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>edges<\/code><\/td>\n<td>a matrix of 2 columns with integer values giving a list of edges<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>n.line<\/code><\/td>\n<td>the number of points for a linear plot<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>n.circle<\/code><\/td>\n<td>the number of points for a circular plot<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>area<\/code><\/td>\n<td>a data frame containing a polygon set (see area.plot)<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>nb<\/code><\/td>\n<td>an object of class &#8216;nb&#8217;<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>neig, x, obj, object<\/code><\/td>\n<td>an object of class &#8216;neig&#8217;<\/td>\n<\/tr>\n<tr valign=\"top\">\n<td><code>...<\/code><\/td>\n<td>further arguments passed to or from other methods<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 style=\"color: #000000;\">Author(s)<\/h3>\n<p style=\"color: #000000;\">Daniel Chessel<\/p>\n<h3 style=\"color: #000000;\">References<\/h3>\n<p style=\"color: #000000;\">Thioulouse, J., D. Chessel, and S. Champely. 1995. Multivariate analysis of spatial patterns: a unified approach to local and global structures.\u00a0<em>Environmental and Ecological Statistics<\/em>,\u00a0<b>2<\/b>, 1\u201314.<\/p>\n<h3 style=\"color: #000000;\">Examples<\/h3>\n<pre style=\"color: #000000;\">data(mafragh)\nif (require(deldir, quietly=TRUE)) {\n    par(mfrow = c(2,1))\n    provi &lt;- deldir(mafragh$xy)\n    provi.neig &lt;- neig(edges = as.matrix(provi$delsgs[,5:6]))\n    \n    s.label(mafragh$xy, neig = provi.neig, inc = FALSE, \n        addax = FALSE, clab = 0, cnei = 2)\n    dist &lt;- apply(provi.neig, 1, function(x) \n        sqrt(sum((mafragh$xy[x[1],] - mafragh$xy[x[2],])^2)))\n    #hist(dist, nclass = 50)\n    mafragh.neig &lt;- neig(edges = provi.neig[dist&lt;50,])\n    s.label(mafragh$xy, neig = mafragh.neig, inc = FALSE, \n        addax = FALSE, clab = 0, cnei = 2)\n    par(mfrow = c(1,1))\n    \n    data(irishdata)\n    irish.neig &lt;- neig(area = irishdata$area)\n      summary(irish.neig)\n      print(irish.neig)\n    s.label(irishdata$xy, neig = irish.neig, cneig = 3,\n        area = irishdata$area, clab = 0.8, inc = FALSE)\n    \n    irish.scores &lt;- scores.neig(irish.neig)\n    par(mfrow = c(2,3))\n    for (i in 1:6) s.value(irishdata$xy, irish.scores[,i],\n        inc = FALSE, grid = FALSE, addax = FALSE,\n        neig = irish.neig,\n        csi = 2, cleg = 0, sub = paste(\"Eigenvector \",i), csub = 2)\n    par(mfrow = c(1,1))\n    \n    a.neig &lt;- neig(n.circle = 16)\n    a.scores &lt;- scores.neig(a.neig)\n    xy &lt;- cbind.data.frame(cos((1:16) * pi \/ 8), sin((1:16) * pi \/ 8))\n    par(mfrow = c(4,4))\n    for (i in 1:15) s.value(xy, a.scores[,i], neig = a.neig, \n        csi = 3, cleg = 0)\n    par(mfrow = c(1,1))\n    \n    a.neig &lt;- neig(n.line = 28)\n    a.scores &lt;- scores.neig(a.neig)\n    par(mfrow = c(7,4))\n    par(mar = c(1.1,2.1,0.1,0.1))\n    for (i in 1:27) barplot(a.scores[,i], col = grey(0.8))\n}\npar(mfrow = c(1,1))\n\nif (require(maptools, quiet = TRUE) &amp; require(spdep, quiet = TRUE)) {\n    data(columbus)\n    par(mfrow = c(2,1))\n    par(mar = c(0.1,0.1,0.1,0.1))\n    plot(col.gal.nb, coords)\n    s.label(data.frame(coords), neig = neig(list = col.gal.nb),\n        inc = FALSE, clab = 0.6, cneig = 1)\n    par(mfrow = c(1,1))\n    \n    data(mafragh)\n    maf.rel &lt;- relativeneigh(as.matrix(mafragh$xy))\n    maf.rel &lt;- graph2nb(maf.rel)\n    s.label(mafragh$xy, neig = neig(list = maf.rel), inc = FALSE,\n        clab = 0, addax = FALSE, cne = 1, cpo = 2)\n    \n    par(mfrow = c(2,2))\n    w &lt;- matrix(runif(100), 50, 2)\n    x.gab &lt;- gabrielneigh(w)\n    x.gab &lt;- graph2nb(x.gab)\n    s.label(data.frame(w), neig = neig(list = x.gab), inc = FALSE,\n        clab = 0, addax = FALSE, cne = 1, cpo = 2, sub = \"relative\")\n    x.rel &lt;- relativeneigh(w)\n    x.rel &lt;- graph2nb(x.rel)\n    s.label(data.frame(w), neig = neig(list = x.rel), inc = FALSE,\n        clab = 0, addax = FALSE, cne = 1, cpo = 2, sub = \"Gabriel\")\n    k1 &lt;- knn2nb(knearneigh(w))\n    s.label(data.frame(w), neig = neig(list = k1), inc = FALSE,\n        clab = 0, addax = FALSE, cne = 1, cpo = 2, sub = \"k nearest neighbours\")\n    \n    all.linked &lt;- max(unlist(nbdists(k1, w)))\n    z &lt;- dnearneigh(w, 0, all.linked)\n    s.label(data.frame(w), neig = neig(list = z), inc = FALSE,\n        clab = 0, addax = FALSE, cne = 1, cpo = 2, \n        sub = \"Neighbourhood contiguity by distance\")\n}\npar(mfrow = c(1,1))\n<\/pre>\n<h3 style=\"color: #000000;\">Results<\/h3>\n<pre style=\"color: #000000;\">R version 3.0.2 (2013-09-25) -- \"Frisbee Sailing\"\nCopyright (C) 2013 The R Foundation for Statistical Computing\nPlatform: x86_64-unknown-linux-gnu (64-bit)\n\nR is free software and comes with ABSOLUTELY NO WARRANTY.\nYou are welcome to redistribute it under certain conditions.\nType 'license()' or 'licence()' for distribution details.\n\nR is a collaborative project with many contributors.\nType 'contributors()' for more information and\n'citation()' on how to cite R or R packages in publications.\n\nType 'demo()' for some demos, 'help()' for on-line help, or\n'help.start()' for an HTML browser interface to help.\nType 'q()' to quit R.\n\n&gt; library(ade4)\n\nAttaching package: 'ade4'\n\nThe following object is masked from 'package:base':\n\n    within\n\n&gt; png(filename=\"\/home\/oogasawa\/snapshot\/RGM3\/R_CC\/result\/ade4\/neig.Rd_%03d_medium.png\", width=480, height=480)\n&gt; ### Name: neig\n&gt; ### Title: Neighbourhood Graphs\n&gt; ### Aliases: neig neig.util.GtoL neig.util.LtoG print.neig summary.neig\n&gt; ###   scores.neig nb2neig neig2nb neig2mat\n&gt; ### Keywords: utilities\n&gt; \n&gt; ### ** Examples\n&gt; \n&gt; data(mafragh)\n&gt; if (require(deldir, quietly=TRUE)) {\n+     par(mfrow = c(2,1))\n+     provi &lt;- deldir(mafragh$xy)\n+     provi.neig &lt;- neig(edges = as.matrix(provi$delsgs[,5:6]))\n+     \n+     s.label(mafragh$xy, neig = provi.neig, inc = FALSE, \n+         addax = FALSE, clab = 0, cnei = 2)\n+     dist &lt;- apply(provi.neig, 1, function(x) \n+         sqrt(sum((mafragh$xy[x[1],] - mafragh$xy[x[2],])^2)))\n+     #hist(dist, nclass = 50)\n+     mafragh.neig &lt;- neig(edges = provi.neig[dist&lt;50,])\n+     s.label(mafragh$xy, neig = mafragh.neig, inc = FALSE, \n+         addax = FALSE, clab = 0, cnei = 2)\n+     par(mfrow = c(1,1))\n+     \n+     data(irishdata)\n+     irish.neig &lt;- neig(area = irishdata$area)\n+       summary(irish.neig)\n+       print(irish.neig)\n+     s.label(irishdata$xy, neig = irish.neig, cneig = 3,\n+         area = irishdata$area, clab = 0.8, inc = FALSE)\n+     \n+     irish.scores &lt;- scores.neig(irish.neig)\n+     par(mfrow = c(2,3))\n+     for (i in 1:6) s.value(irishdata$xy, irish.scores[,i],\n+         inc = FALSE, grid = FALSE, addax = FALSE,\n+         neig = irish.neig,\n+         csi = 2, cleg = 0, sub = paste(\"Eigenvector \",i), csub = 2)\n+     par(mfrow = c(1,1))\n+     \n+     a.neig &lt;- neig(n.circle = 16)\n+     a.scores &lt;- scores.neig(a.neig)\n+     xy &lt;- cbind.data.frame(cos((1:16) * pi \/ 8), sin((1:16) * pi \/ 8))\n+     par(mfrow = c(4,4))\n+     for (i in 1:15) s.value(xy, a.scores[,i], neig = a.neig, \n+         csi = 3, cleg = 0)\n+     par(mfrow = c(1,1))\n+     \n+     a.neig &lt;- neig(n.line = 28)\n+     a.scores &lt;- scores.neig(a.neig)\n+     par(mfrow = c(7,4))\n+     par(mar = c(1.1,2.1,0.1,0.1))\n+     for (i in 1:27) barplot(a.scores[,i], col = grey(0.8))\n+ }\ndeldir 0.0-22\n\n     PLEASE NOTE:  The components \"delsgs\" and \"summary\" of the \n     object returned by deldir() are now DATA FRAMES rather than \n     matrices (as they were prior to release 0.0-18). \n     See help(\"deldir\").\n \n     PLEASE NOTE: The process that deldir() uses for determining\n     duplicated points has changed from that used in version\n     0.0-9 of this package (and previously). See help(\"deldir\").\n\nNeigbourhood undirected graph\nVertices: 25 \nDegrees: 5 5 4 4 1 5 3 6 5 5 5 4 4 2 3 7 3 7 7 3 8 4 6 4 4 \nEdges (pairs of vertices): 57 \nS01 .\nS02 ..\nS03 ...\nS04 ....\nS05 .....\nS06 ..1...\nS07 ..11...\nS08 1.......\nS09 1........\nS10 1......11.\nS11 .1..1......\nS12 ..11..1.....\nS13 .1........1..\nS14 ..............\nS15 .....1.........\nS16 .1.....1.....1..\nS17 .1...........1.1.\nS18 .....1.1.1.....1..\nS19 .....1....1.1.1..1.\nS20 ..........1...1...1.\nS21 ..11.1..11.1.....1...\nS22 ...1....1...........1.\nS23 .1.....1....1..1.11....\nS24 1.......1............1..\nS25 1......1.......1.......1.\n&gt; par(mfrow = c(1,1))\n&gt; \n&gt; if (require(maptools, quiet = TRUE) &amp; require(spdep, quiet = TRUE)) {\n+     data(columbus)\n+     par(mfrow = c(2,1))\n+     par(mar = c(0.1,0.1,0.1,0.1))\n+     plot(col.gal.nb, coords)\n+     s.label(data.frame(coords), neig = neig(list = col.gal.nb),\n+         inc = FALSE, clab = 0.6, cneig = 1)\n+     par(mfrow = c(1,1))\n+     \n+     data(mafragh)\n+     maf.rel &lt;- relativeneigh(as.matrix(mafragh$xy))\n+     maf.rel &lt;- graph2nb(maf.rel)\n+     s.label(mafragh$xy, neig = neig(list = maf.rel), inc = FALSE,\n+         clab = 0, addax = FALSE, cne = 1, cpo = 2)\n+     \n+     par(mfrow = c(2,2))\n+     w &lt;- matrix(runif(100), 50, 2)\n+     x.gab &lt;- gabrielneigh(w)\n+     x.gab &lt;- graph2nb(x.gab)\n+     s.label(data.frame(w), neig = neig(list = x.gab), inc = FALSE,\n+         clab = 0, addax = FALSE, cne = 1, cpo = 2, sub = \"relative\")\n+     x.rel &lt;- relativeneigh(w)\n+     x.rel &lt;- graph2nb(x.rel)\n+     s.label(data.frame(w), neig = neig(list = x.rel), inc = FALSE,\n+         clab = 0, addax = FALSE, cne = 1, cpo = 2, sub = \"Gabriel\")\n+     k1 &lt;- knn2nb(knearneigh(w))\n+     s.label(data.frame(w), neig = neig(list = k1), inc = FALSE,\n+         clab = 0, addax = FALSE, cne = 1, cpo = 2, sub = \"k nearest neighbours\")\n+     \n+     all.linked &lt;- max(unlist(nbdists(k1, w)))\n+     z &lt;- dnearneigh(w, 0, all.linked)\n+     s.label(data.frame(w), neig = neig(list = z), inc = FALSE,\n+         clab = 0, addax = FALSE, cne = 1, cpo = 2, \n+         sub = \"Neighbourhood contiguity by distance\")\n+ }\nChecking rgeos availability: TRUE\n\nAttaching package: 'boot'\n\nThe following object is masked from 'package:lattice':\n\n    melanoma\n\n\nAttaching package: 'spdep'\n\nThe following object is masked from 'package:ade4':\n\n    mstree\n\n&gt; par(mfrow = c(1,1))\n&gt; \n&gt; \n&gt; \n&gt; \n&gt; \n&gt; dev.off()\nnull device \n          1 \n&gt;\n<\/pre>\n<p>&nbsp;<\/p>\n<table style=\"color: #000000;\">\n<tbody>\n<tr>\n<td><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_001_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_001_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_002_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_002_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_003_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_003_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_004_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_004_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_005_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_005_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_006_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_006_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_007_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_007_medium.png\" alt=\"\" \/><\/a><a style=\"color: #708090;\" href=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_008_large.png\"><img decoding=\"async\" src=\"http:\/\/rgm3.lab.nig.ac.jp\/RGM-files\/R_CC\/result\/ade4\/neig.Rd_008_medium.png\" alt=\"\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>neig R Documentation Neighbourhood Graphs Description neig\u00a0creates objects of class\u00a0neig\u00a0with : a list of edges a binary square matrix a list of vectors of neighbours&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-611","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=611"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/611\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}