How to view/read the adjancency matrix

825 views
Skip to first unread message

Eddie

unread,
Apr 29, 2013, 11:08:46 AM4/29/13
to r-inla-disc...@googlegroups.com
Hi guys,

I am new to INLA and currently wok on the tutorial. How could I view/read the adjancency matirx nc.nb as below?

#Load data from a shapefile included in the spdep package
nc.sids <- readShapePoly(system.file("etc/shapes/sids.shp", package="spdep")[1])

#Create adjacency matrix
nc.nb <- poly2nb(nc.sids)

#Convert the adjacency matrix into a file in the INLA format
nb2INLA("nc.adj", nc.nb)

#Create areas IDs to match the values in nc.adj
nc.sids$ID<-1:100
m1<-inla(SID74~NWPROP+f(nc.sids$ID, model="besag", graph="nc.adj"),
   family="poisson", E=nc.sids$EXP, data=as.data.frame(nc.sids),
   control.predictor=list(compute=TRUE))

Håvard Rue

unread,
Apr 29, 2013, 12:08:22 PM4/29/13
to Eddie, r-inla-disc...@googlegroups.com
On Mon, 2013-04-29 at 08:08 -0700, Eddie wrote:
> Hi guys,
>
>
> I am new to INLA and currently wok on the tutorial. How could I
> view/read the adjancency matirx nc.nb as below?
>
>
> #Load data from a shapefile included in the spdep package
> nc.sids <-
> readShapePoly(system.file("etc/shapes/sids.shp", package="spdep")[1])
>
>
> #Create adjacency matrix
> nc.nb <- poly2nb(nc.sids)
>
>
> #Convert the adjacency matrix into a file in the INLA format
>
> nb2INLA("nc.adj", nc.nb)

this would create a file 'nc.adj', which you can look at (its an ascii
file). If you have install graphviz and its R-interface, then you can do
plot as well

g = inla.read.graph("nc.adj")
summary(g)
plot(g) ## unless its huge...

there are more options at

http://www.r-inla.org/faq#TOC-Some-of-the-models-needs-a-graph-how-do-I-specify-it-


Best
H



--
Håvard Rue
Department of Mathematical Sciences
Norwegian University of Science and Technology
N-7491 Trondheim, Norway
Voice: +47-7359-3533 URL : http://www.math.ntnu.no/~hrue
Mobile: +47-9260-0021 Email: havar...@math.ntnu.no

R-INLA: www.r-inla.org

Eddie

unread,
Apr 29, 2013, 2:13:01 PM4/29/13
to r-inla-disc...@googlegroups.com, Eddie, hr...@r-inla.org
Thank you very much! :)
Reply all
Reply to author
Forward
0 new messages