***** To join INSNA, visit http://www.insna.org *****
On 08/23/2015 04:54 PM, Ian McCulloh wrote:
> ***** To join INSNA, visit http://www.insna.org *****
>
> Hello!
>
> I'm trying to use blockmodels in statnet. I see there is plenty of
> documentation for using to play around with equivalence clustering and I
> see that there is supposed to be an option for a membership vector.
> Unfortunately, I cannot seem to get the membership vector to work. Does
> anyone have some sample code that would demonstrate this?
I'm assuming you are talking about the sna blockmodel command? I'm not
very familiar with blockmodeling, but would that just be the
$block.membership element?
library(sna)
g.p<-sapply(runif(20,0,1),rep,20) #Create a matrix of edge
#probabilities
g<-rgraph(20,tprob=g.p) #Draw from a Bernoulli graph
#distribution
#Cluster based on structural equivalence
eq<-equiv.clust(g)
#Form a blockmodel with distance relaxation of 10
b<-blockmodel(g,eq,h=10)
b$block.membership
[1] 9 9 6 8 8 3 10 2 7 7 4 4 4 5 11 1 1 1 1 1
I believe this would mean that the first and second vertices are in
block 9, 3rd in block 6, etc.
you can print the names of the various elements of the blockmodel object
with names(b) . probably the sna docs should be updated to give the names.
>
> Another issue is coloring nodes by a node attribute. I can do this when
> the attributes are numeric using a rainbow command. Is there an easy way
> to do this when the attributes are categorical? Or do I have to convert
> the categorical attributes to numeric to make this work. Again, sample
> code is appreciated.
depends if you want to control which colors you get. If you don't care,
you can use network's as.color() command (which I think converts to
integers via a factor)
> as.color(c('a','b','c'))
[1] 1 2 3
which will be mapped to colors according to R's current palette:
palette()
[1] "black" "red" "green3" "blue" "cyan" "magenta" "yellow"
"gray"
If I want to map specific categorical values to specific colors (usually
the case) then I generally right some kind of color map function:
myColors<-function(c){
sapply(c,function(c){
switch(c,
'frosh'='pink',
'soph'= 'orange',
'junior'='blue',
'senior'='green')
})
}
You can also just change the order of colors in the current palette, see
?palette
best,
-skye
_____________________________________________________________________
SOCNET is a service of INSNA, the professional association for social
network researchers (http://www.insna.org). To unsubscribe, send
an email message to [log in to unmask] containing the line
UNSUBSCRIBE SOCNET in the body of the message.
|