Statistically Significant

December 20, 2009

Greetings from Fort Lauderdale!

Filed under: Life,Work — Hoxie @ 11:31 pm

Another week in the life of Hoxie.

Work flew by this week.  We had a big meeting with a few consultants on Friday afternoon, so I spent most of the week supplying slides, charts, and analyses for the event.  (It went very well!)  A few hours before the meeting, the department went out to lunch at Sandrine’s, in Harvard Square, which was very tasty and a lot of fun.

I also had my first really cold commutes this week.  I always check the weather on my iPod before heading out in the morning, and on Wednesday, I was greeted with a “17, feels like -2.”  Stupid wind chill.  After getting geared up, though, the only parts of me that were really cold were my hands (through ski gloves, mind you) and the parts of my face that were exposed to the wind.  (C’mon, Santa, bring me that wool balaclava and those glove liners!)

I get a break from the Boston cold this week, though, as I escaped the Great Blizzard of 2009 yesterday morning.  I’m only taking a week off, so I need to make the best of it with Christmas shopping, time at the beach, playing with Dante, seeing friends, and eating good food.  (Did anyone else who recently graduated get spoiled by the month-long vacations that accompany college semesters?  I did!)  Went to see Avatar in 3D with the family earlier this evening, and absolutely loved it.  Breathtaking, awesome, beautiful, powerful movie.  Seriously, stop reading this and go see Avatar now.

Hoping to finish grad school apps once and for all tomorrow morning, then enjoy a week of fun in the sun! :)

December 13, 2009

R Trick (Nerd Alert)

Filed under: Math — Hoxie @ 11:38 am

At work this past week, I finally figured out how to do something in R that I’ve been wanting to do for a while now. The problem has to do with creating and assigning variables using a loop. I figured out how to do mass variable creation using a loop this summer: to assign a random value between 0 and 1 to variables z1, z2, …, z10 using a loop, you can use:
for (index in 1:10){
assign(paste(“z”, index, sep=”") , runif(1))
}
(I can’t think of a place I’d choose to do this over just creating a 10-element vector of random numbers using “z <- runif(10)” and accessing the elements of the vector as I needed them, but there are places where it’s helpful to create a few variables using the loop index.)

But what if you have variables z1, z2, …, z10 created already and you want to work with each of them separately? I didn’t know how to create a “current variable” inside of the loop. Trying something similar fails:
for (index in 1:10){
assign(“current_value” , paste(“z”, index, sep=”"))
cat(current_value, “\n”)
# do complicated stuff
}
This will print “z1″, “z2″, … “z10″ instead of the values contained in our ten z variables.

The solution I discovered this past week:
for (index in 1:10){
eval(parse(text=paste(“current_value <- z”, index, sep=”")))
cat(current_value, “\n”)
}
For index==1, for example, this prepares the string “current_value <- z1″ and then submits it to R for evaluation, so now the variable current_value contains the value of z1. Nice.

Next Page »