<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3753480659605799991</id><updated>2011-11-27T17:20:43.685-08:00</updated><category term='layout'/><category term='igraph'/><category term='table'/><category term='plot'/><category term='graph'/><category term='CRAN'/><category term='help'/><category term='library'/><category term='edge list'/><title type='text'>R in 15 minutes a day</title><subtitle type='html'>This blog will help you to get started with R. Our intitial focus will be on modeling social networks using the igraph package.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rin15minaday.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3753480659605799991/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://rin15minaday.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Michael Weiss</name><uri>http://www.blogger.com/profile/13096234851246024945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_S6lHimIMz4k/Ss0BKJMBmWI/AAAAAAAAAB4/fvmkWriLTQc/s1600-R/weiss.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3753480659605799991.post-8118424222967494705</id><published>2009-10-14T09:46:00.000-07:00</published><updated>2009-10-14T09:59:34.945-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='layout'/><category scheme='http://www.blogger.com/atom/ns#' term='edge list'/><category scheme='http://www.blogger.com/atom/ns#' term='plot'/><category scheme='http://www.blogger.com/atom/ns#' term='graph'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><category scheme='http://www.blogger.com/atom/ns#' term='igraph'/><title type='text'>Day 2</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Today,&lt;/span&gt; we will create a simple network, read it into R, and draw it using igraph. One way of representing a network is as an edge list. Edge lists are easy to create. Consider yourself and a few of your immediate friends. Then think of some of your friends' immediate friends. You can represent this in a file that contains one line for each friendship, like this:&lt;br /&gt;&lt;br /&gt;Charlie Lucy&lt;br /&gt;Charlie Patty&lt;br /&gt;Charlie Linus&lt;br /&gt;Charlie Sally&lt;br /&gt;Charlie Snoopy&lt;br /&gt;Patty Marcie&lt;br /&gt;Lucy Linus&lt;br /&gt;Lucy Schroeder&lt;br /&gt;Snoopy Woodstock&lt;br /&gt;Snoopy Spike&lt;br /&gt;Snoopy Patty&lt;br /&gt;Sally Linus&lt;br /&gt;&lt;br /&gt;Save this list in a file, and start up R. In the Misc menu change the working directory to the directory that contains the file. Now, load the file into a data frame, which is the way R represents data internally. Since we have not provided table heads (think columns in Excel) for the two columns in the file, we turn table heads off:&lt;br /&gt;&lt;br /&gt;&gt; friends.data &lt;- read.table("peanuts.txt", head=F)   &lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;Create a graph from this edge list. &lt;/span&gt;Load the igraph library (see Day 1 for how to do this), then enter:&lt;br /&gt;&lt;br /&gt;&gt; friends &lt;- graph.data.frame(friends.data, directed=F)   &lt;br /&gt;&lt;br /&gt;Note that we specify the graph as undirected. This means that all links between nodes of the graph are bidirectional. Since Lucy is a friend Charlie, Charlie is also a friend of Lucy. We could model directionality as well, but won't do this in most of this course. To get a summary of the graph:   &lt;br /&gt;&lt;br /&gt;&gt; summary(friends)&lt;br /&gt;Vertices: 10&lt;br /&gt;Edges: 12&lt;br /&gt;Directed: FALSE&lt;br /&gt;No graph attributes.&lt;br /&gt;Vertex attributes: name.&lt;br /&gt;No edge attributes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Now that we have created the graph,&lt;/span&gt; we can draw it. In R you use the plot command to draw a graph. If you provide the graph as the only argument to plot, the result will be less than satisfying (try it!). Instead, you want to specify a layout that will draw the graph nicely according to criteria of what constitutes a good visualization. For example:&lt;br /&gt;&lt;br /&gt;&gt; plot(friends, layout=layout.kamada.kawai)&lt;br /&gt;&lt;br /&gt;BTW, if you can't remember the names of the layouts, remember just one thing: help is only a few clicks away. Enter "layout" in the search box on the R GUI, or enter the following on the command line:&lt;br /&gt;&lt;br /&gt;&gt; help(layout)&lt;br /&gt;&lt;br /&gt;One thing we would like to improve in the resulting diagram is that we would like to see the names of our friends instead of the numerical index of each node. We can get a more readable diagram by adding a parameter vertex.label to the plot command like this:&lt;br /&gt;&lt;br /&gt;&gt; plot(friends, layout=layout.kamada.kawai, vertex.label=V(friends)$name)&lt;br /&gt;&lt;br /&gt;This tells R to use the names of the nodes instead of their indices. V(friends) returns a list of the names, and $name refers to the name attribute of a node. V(friends)$name returns a vector of node names. You can convince yourself as follows:&lt;br /&gt;&lt;br /&gt;&gt; V(friends)$name&lt;br /&gt;[1] "Charlie" "Patty" "Lucy" "Snoopy" "Sally" "Linus"&lt;br /&gt;[7] "Marcie" "Schroeder" "Woodstock" "Spike"&lt;br /&gt;&lt;br /&gt;This is the output of drawing the friendship network:&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_S6lHimIMz4k/StYBzlTMpII/AAAAAAAAACc/tMrVSedPxQU/s1600-h/friends_smaller.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 288px;" src="http://3.bp.blogspot.com/_S6lHimIMz4k/StYBzlTMpII/AAAAAAAAACc/tMrVSedPxQU/s320/friends_smaller.png" alt="" id="BLOGGER_PHOTO_ID_5392499589520336002" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;With that, we should call it a day.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3753480659605799991-8118424222967494705?l=rin15minaday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rin15minaday.blogspot.com/feeds/8118424222967494705/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rin15minaday.blogspot.com/2009/10/day-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3753480659605799991/posts/default/8118424222967494705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3753480659605799991/posts/default/8118424222967494705'/><link rel='alternate' type='text/html' href='http://rin15minaday.blogspot.com/2009/10/day-2.html' title='Day 2'/><author><name>Michael Weiss</name><uri>http://www.blogger.com/profile/13096234851246024945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_S6lHimIMz4k/Ss0BKJMBmWI/AAAAAAAAAB4/fvmkWriLTQc/s1600-R/weiss.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_S6lHimIMz4k/StYBzlTMpII/AAAAAAAAACc/tMrVSedPxQU/s72-c/friends_smaller.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3753480659605799991.post-5531556573484700877</id><published>2009-10-07T13:19:00.000-07:00</published><updated>2009-10-07T14:03:11.071-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CRAN'/><category scheme='http://www.blogger.com/atom/ns#' term='help'/><category scheme='http://www.blogger.com/atom/ns#' term='library'/><category scheme='http://www.blogger.com/atom/ns#' term='igraph'/><title type='text'>Day 1</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Start by installing R. &lt;/span&gt;R is an open source platform for statistical computing. The R project is hosted at the &lt;a href="http://www.r-project.org/"&gt;R Project&lt;/a&gt; site. Download R for your platform. The current version is 2.9.2. But pretty much any version should work.&lt;br /&gt;&lt;br /&gt;Pick up a cup of coffee while you are waiting for the file to download.&lt;br /&gt;&lt;br /&gt;Install R by following the instructions. Usually this means little more than clicking on the disk image and running the installer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Test the installation. &lt;/span&gt;You can think of R as a gigantic calculator. Start up R and run a few tests to see that your install worked:&lt;br /&gt;&lt;br /&gt;&gt; 2+2&lt;br /&gt;[1] 4&lt;br /&gt;&gt; exp(-2)&lt;br /&gt;[1] 0.1353353&lt;br /&gt;&gt; &lt;blockquote&gt;&lt;/blockquote&gt;The &gt; is the prompt, and the numbers in parentheses in the answer help you find your way through the result. Often, the results are given as a vector as in the examples above.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Next, install igraph.&lt;/span&gt; &lt;a href="http://igraph.sourceforge.net/"&gt;igraph&lt;/a&gt; is an R package for social network analysis. Many packages have been written for R for all kinds of purposes. You can find most of them on CRAN, the R archive. Here is a Canadian CRAN mirror site: &lt;a href="http://cran.stat.sfu.ca/"&gt;http://cran.stat.sfu.ca&lt;/a&gt;. Select the Package Installer from the Packages &amp;amp; Data menu, click Get List and enter "igraph" in the search box. Select igraph and hit Install Selected. The current version of igraph is 0.5.2-2.&lt;br /&gt;&lt;br /&gt;If you were successful, you should see something like the following:&lt;br /&gt;&lt;br /&gt;trying URL 'http://probability.ca/cran/bin/macosx/universal/contrib/2.9/igraph_0.5.2-2.tgz'&lt;br /&gt;Content type 'application/x-gzip' length 2401199 bytes (2.3 Mb)&lt;br /&gt;opened URL&lt;br /&gt;==================================================&lt;br /&gt;downloaded 2.3 Mb&lt;br /&gt;&lt;br /&gt;The downloaded packages are in&lt;br /&gt;/var/folders/A6/A6HuYMhtGsSKIXTAuzxo9U+++TI/-Tmp-//RtmpX7GvKg/downloaded_packages&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To verify the installation,&lt;/span&gt; load the igraph library and search for the help page on an igraph function. Something like this:&lt;br /&gt;&lt;br /&gt;&gt; library(igraph)&lt;br /&gt;&gt; help(degree)&lt;br /&gt;&gt;&lt;br /&gt;&lt;br /&gt;Enough for today. Give yourself a pat on the back.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3753480659605799991-5531556573484700877?l=rin15minaday.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rin15minaday.blogspot.com/feeds/5531556573484700877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rin15minaday.blogspot.com/2009/10/day-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3753480659605799991/posts/default/5531556573484700877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3753480659605799991/posts/default/5531556573484700877'/><link rel='alternate' type='text/html' href='http://rin15minaday.blogspot.com/2009/10/day-1.html' title='Day 1'/><author><name>Michael Weiss</name><uri>http://www.blogger.com/profile/13096234851246024945</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_S6lHimIMz4k/Ss0BKJMBmWI/AAAAAAAAAB4/fvmkWriLTQc/s1600-R/weiss.jpg'/></author><thr:total>0</thr:total></entry></feed>
