Legends and Dates in R plots

Posted: December 5th, 2011 | Author: | Filed under: Uncategorized | 1 Comment »

After looking up how to create a legend using ?legend and searching the R forums for the 86586586th time, I’ve decided to write my own post with a few examples and tricks I’ve picked up. I also provide example code for using dates as an x-axis.

I do most of my heavy computation in Python, leaving R for primarily making pretty plots, exploratory data analysis (EDA) when I first get my hands on a data set, and using my favorite R packages/functions that I’ll never implement on my own (ie Random Forests, CART, SVM). Below is an example plot, with two sets of numbers, a legend, and dates on the axis. Hopefully this is more helpful than the R documentation.

# pick a length, and generate two random normals of this length
len = 43
vals = rnorm(len,0,1)
vals2 = rnorm(len,0,.5)

# pick an initial date in form YYYYMMDD, then generate a years worth of weekly dates
date = 20110201
mydates<-as.Date(as.character(date),"%Y%m%d")
for(i in 1:52){ #
mydates = c(mydates,mydates[length(mydates)]+7)
}
# rename something shorter
x=mydates[2:(len+1)]

# set graphical parameters and plot both random normals, use xaxt="n" to eliminate the x-axis
par(mfrow=c(1,1))
plot(vals,type="l",col="blue",xaxt="n",ylab="y axis label",xlab="",main="Plot Title")
lines(vals2,col="red")
# add back an x-axis with dates, las and cex.axis set direction and size of dates
axis(1, at=1:len,x,las=2,cex.axis=.9)
# add a legend, lwd sets line width, you can use x,y coordinates instead of "bottomleft"
legend("bottomleft", c("thing1","thing2"), col = c("blue", "red"), lwd = 1, title="legend title")


Honey Cake Recipe

Posted: October 18th, 2011 | Author: | Filed under: Uncategorized | No Comments »

In addition to hating on Klout and writing random code blog posts, I’ve decided to branch out a bit with my posts and write about one of my other passions: baking and cooking. I recently had a Rosh Hashanah (Jewish New Year) dinner party with my roommates and made several desserts. The traditional dessert for the holiday is a Honey Cake, for a “sweet” new year. I’ve tried about 5 recipes and this is my favorite. Pictures, ingredient list and directions can be found below.

Ingredients:

  • 3 1/2 cups all-purpose flour
  • 1 tablespoon baking powder
  • 1 teaspoon baking soda
  • 1/2 teaspoon kosher salt
  • 4 teaspoons ground cinnamon
  • 1/2 teaspoon ground cloves
  • 1/2 teaspoon ground allspice
  • 1 cup vegetable oil
  • 1 cup honey
  • 1 1/2 cups granulated sugar
  • 1/2 cup brown sugar
  • 3 large eggs at room temperature
  • 1 teaspoon vanilla extract
  • 1 cup coffee
  • 1/2 cup fresh orange juice
  • 1/4 cup bourbon

Preparation Instructions:

  1. In a large bowl, whisk together the flour, baking powder, baking soda, salt, cinnamon, cloves and allspice
  2. Make a well in the center, and add oil, honey, granulated sugar, brown sugar, eggs, vanilla, coffee, orange juice and bourbon
  3. Mix well and then portion into tins. Do not overbeat! If you are using an electric mixer, do so at a low setting.

This is a huge recipe and its into FIVE 7.75 Inch x 3.75 Inch x 2.75 loaf pans. I normally just pick up a pack of 6 disposable aluminum tins at the grocery store.

The batter should look like this once combined:

The cakes keep for up to 5 days and honestly are better after sitting for a day, just cover with foil or cling wrap in the tin to store. Enjoy!


Installing MACS (Markovian Coalescent Simulator) on OS X 10.7 Lion

Posted: October 15th, 2011 | Author: | Filed under: Uncategorized | No Comments »

After a few years break from my dissertation research on coalescent modeling of HIV sequences, I’ve decided to dive in again. I am interested in generating some sequences from coalescent models with various characterestics. Though ms and msHOT from the Hudson lab are what I’ve used previously, I decided to see what else is out there.

The paper describing their methodology can be found here. The files are available here. In the extracted directory simply run “make all”.

I ran into two compilation errors:

g++ -Wall -g -I /Users/garychen/software/boost_1_36_0 -c algorithm.cpp
algorithm.cpp: In member function ‘void GraphBuilder::build()’:
algorithm.cpp:1272: error: ‘uint’ was not declared in this scope
algorithm.cpp:1272: error: expected `;’ before ‘iSegLength’
algorithm.cpp:1273: error: ‘iSegLength’ was not declared in this scope
make: *** [algorithm.o] Error 1

I changed uint to int on line 1272 and combined the cout onlines 1273 and 1274 into one line, which fixed the complaints. Then the build complained:

g++ -o macs simulator.o algorithm.o datastructures.o -static
ld: library not found for -lcrt0.o

Simply comment out “LINKFLAGS = -static” and everything should happily compile.


Notary in DC and Virginia

Posted: September 21st, 2011 | Author: | Filed under: Uncategorized | Tags: , , , , , | No Comments »

Was recently visiting Washington DC to see some friends from college and I had a notary emergency. It was late on Saturday, but My DC Notary came through. I’ve had to notarize a few things in DC and this was by far the best experience. Before this time I didn’t even know that mobile 24/7 notary services existed. If you need a notary in dc you should absolutely use this service. They also have a second service in Virginia, specifically Alexandria and Arlington. If you need a notary in either of these towns you should use notary in dc and Virginia.

While I hope I never have another notarizing emergency, I wanted to write them up because I know they happen often and this was as stress free as any emergency notary experience can be. The Yelp page of Mydcnotary is here.


Chomp August App Search Analytics

Posted: September 7th, 2011 | Author: | Filed under: Uncategorized | No Comments »

Today Chomp released its monthly App Search Analytics Report. Along with the standard set of analytics, we dug into search traffic for the queries hurricane and earthquake. Both saw huge temporal spikes in traffic, which are outlined in the highlights below:

  • Query traffic for the term hurricane spiked >2000% and Hurricane Irene’s formation, warning, and landfall were all correlated with movement in search traffic.
  • A 250% spike was seen during the formation of Tropical Storm Emily.
  • Search traffic for earthquake apps was up 2000% immediately after the 5.8 magnitude event in Virginia. 

  • Paid downloads dropped by 4% on Android, the first drop after three month of consecutive gains
  • iOS paid downloads increased by 1%

For a full summary see the Chomp Blog.

Chomp Charts August


Bike accident

Posted: May 6th, 2011 | Author: | Filed under: Uncategorized | No Comments »

This morning at 12:15AM riding back from a birthday party at Benders I was hit by a pickup truck. I was not drunk or even tipsy and neither was the driver of the vehicle. On 19th street as I was crossing Mission a car quickly took a left hand turn in front of me as did the car behind it, which could not see me coming because its view was blocked. I braked hard, but slammed into the passenger side door of the car, my bike absorbed some of the impact, bending my front wheel such that it can no longer turn and literally bending the top part of my frame (pics below).

Bent CAAD9-4 frame closeup
Bent CAAD9-4 frame weld
Bent CAAD9-4 frame
bent front wheel

I went over the handle bars and did a nice faceplant into the car with the left side of my face. By some statistically improbability, other than two nice cuts on my face, a very bloody nose, and a few scrapes and bruises, I am fine, just a bit shaken up (pic below from after initial cleanup, didn’t include the bloodier pics).
Alex Braunstein after a bike accident

I easily could have died or been seriously injured. I rarely think about my mortality or the general fragility of human life. This forced me to. I was lucky, literally walking away from the accident scene. As I initially lay in the middle of the intersection of 19th and Mission, what struck me immediately (other than how much my face hurt) was how many and how quickly people were willing to help a complete stranger. After they asked me a bunch of questions, such as my name, where I was, what happened, and established that I didn’t have any sort of spinal injury, several people helped a bloody stranger to the curb, retrieved me napkins from a nearby restaurant, offered me water, and someone even offered me their jacket, which would clearly be ruined. It was incredibly humbling and gratifying to see complete strangers go out of their way for me.

So what did I learn from this experience? In a way, nothing really. I wasn’t doing anything dangerous or silly, but sometimes random bad shit happens. I didn’t have an out of body or religious experience. I’m not going to change the way I live my life, get a tribal armband or tramp stamp tattoo, or move to Walden pond. I intend to get right back on a bike once I have one that’s rideable.


Leaving Google

Posted: May 2nd, 2011 | Author: | Filed under: Uncategorized | No Comments »

After 21 months in my current job, I’ve decided that I’m ready for a new challenge. This week was my last at Google. I’ll do another post later about my new job/company, but I wanted to jot down some thoughts about Google, my role there, its future, and answer one or two common questions I’ve been receiving from friends, family, and coworkers.

First, let me say that Google is an awesome company filled with brilliant people. I am a much smarter, better person for having worked there, and I made several great friends in the process. If I decide the startup world isn’t for me, Google will probably be my first choice. Was it perfect? Of course not, that’s not true of any job. I did not choose to leave because my job was bad or I am pessimistic about Google’s future, rather, I was offered an incredible opportunity at a startup in SF that I simply couldn’t pass up (more on this later).

I think Google is facing two strategic threats right now:

  1. size
  2. social

Mainly due to its size, Google no longer has significant upside in terms of career trajectory or pecuniary compensation and was thus unable to match the startup opportunity. If Googlers feel that there isn’t upside, the company will bleed talent. At 25000ish employees, the company can no longer double in size every year or two and thus will continue to become more top heavy. Furthermore, Google has become a very safe place to work. Sure there are rapid growth areas within Google, but parts of the company just need warm bodies. Without fire under the feet of everyone, Google will not be able to regain its startup feel/mojo/velocity.

To begin our discussion of strategic threat 2, please answer the following question: “Is it harder to build a vibrant social network or a search engine?” If you answered the former you agree with me and 95% of the other people I asked. Just to be clear, I worked on the evaluation of Google’s social initiatives (yes I am using the word initiative intentionally to be as vague as possible) and nothing in this post should be construed in any way as my commentary on the quality of any Google social initiative past, present, or future. I am simply saying 1) FB has already climbed the social mountain and Google has not 2) the social mountain is higher than the search mountain.

Despite my previous comments, I think Google has made fantastic progress in this area. The relaunch of Social Search in February and the +1 button in March introduced two incredible tools that each have the potential to drastically improve the search experience; they both already drastically improve mine.

Over the next few years, Google will continue to grow and social will become much more important. It’s unclear if Google can “overcome” the threats I outlined. Rather, they need to work hard to address and ameliorate the negative consequences of its size and make social a seamless, enjoyable experience on Google properties, whatever that entails.

In the end, my decision to leave was tough and ultimately bittersweet. Im excited for the new adventures ahead, but will always look back fondly at the time I spent as a Googler.


Coachella 2011

Posted: April 22nd, 2011 | Author: | Filed under: Uncategorized | No Comments »

I went to Coachella for the first time this year and it blew my mind. I’d try to describe it, but no description I heard comes nearly close to doing it justice. I’ll just say that if you love music, you should go. I saw the following bands:

Rural Alberta Advantage, Moving Units, Warpaint, Lauryn Hill, Interpol, Cut Copy, Beardyman, Trampled by Turtles, Freelance Whales, Foals, Two Door Cinema Club, Broken Social Scene, One Day as a Lion, Fedde Le Grand, Animal Collective, Arcade Fire, Good Old War, Eliza Doolittle, Menomena, Jacks Mannequin, City and Colour, Jimmy Eat World, Best Coast, The National

My top 5:

  1. Arcade Fire
  2. Two Door Cinema Club
  3. Good Old War
  4. Jimmy Eat World
  5. Freelance Whales

Honorable mentions: City and Colour, Interpol, and Trampled By Turtles. Animal Collective was the only band that I hated. They were horrible.

I watched 36 hours of music in 3 days, the temperature was > 100 each day, and I walked > 20 miles between the houses and stages. Coachella was exhausting, but exhilarating. I’ve already started a mental countdown until next year’s festival.


My new laptop

Posted: April 20th, 2011 | Author: | Filed under: Uncategorized | No Comments »

I finally bought a new personal laptop after having the same first generation Intel MacBookPro since early 2006. Technically it was still working in the sense that it still turned on, but only operated while plugged in, even with a new battery. It was time. Though I went back and forth deciding between a MacBook Air and the new MacBook Pro, I ultimately ended up with the 15″ model of the latter with the high-resolution anti-glare display, because:

  1. I didn’t want to worry about an external monitor and 13.3″ just didn’t seem big enough
  2. quad core i7 >> core 2 duo
  3. anti-glare had made a huge difference
  4. I can’t really tell the difference between a 3lb and 5.5lb laptop when its in my laptop bag

This laptop is FAST. Unfortunately, upgrading laptops is a huge pain. I made a checklist of content/programs to transfer or install so I figured I would share that as well:

  1. quicksilver
  2. R
  3. adjust terminal settings – homebrew (because I’m so 1337)
  4. texshop
  5. chrome
  6. numpy/scipy
  7. music, pictures, some old documents, but hopefully I’ll be moving most of this to the cloud soon

Am I missing anything? Any ideas for cool laptop decorations?


Installing numpy and scipy on Snow Leopard

Posted: April 20th, 2011 | Author: | Filed under: Uncategorized | No Comments »

If you want to install numpy and scipy on Snow Leopard, don’t mess around with checking out and building the standard packages yourself. This is frustrating and involves building gFortran and a few other things yourself. I messed around with this for about half an hour before discovering Chris Fonnesbeck’s Scipy Superpack for Mac OSX. He should be given a medal.