Three ways to do non-negative least squares in R

Since I find myself doing this all the time, perhaps this would be of interests to others.

# generate some fake data
x = matrix(rnorm(1000),ncol=10)
y = matrix(rnorm(100), ncol=1)

# method 1 (generally seems slowest)
mod1 = nnls(x,y)

# method 2
mod2 = glmnet(x,y, lambda=0, lower.limits=0, intercept=FALSE)

# method 3 - fastest with multiple y vectors, but occasionally throws a bug I can't figure out
mod3 = .fcnnls(x,y)

# compare results
data.frame(nnls=coef(mod1), glmnet=as.matrix(coef(mod2)[-1]), fcnnls=mod3$coef)

Things I would like to remember if I become a PI

I wrote this post two years ago, and thought perhaps I'd add some updates. It feels perhaps less likely I'll be a PI these days, but perhaps this could be good advice for others.

My original post included the following points:

  • I should offer my students the option to be corresponding authors on their papers. Similarly, I should seriously consider what my role was in the project and therefore whether I should be on the paper in the first place. I should strive to feel like I always deserve that spot and was doing more than contributing money and lab space.
  • If I have favorites, I should not treat them any differently than anyone else in the lab. I should celebrate all accomplishments as much as reasonably possible.
  • I should meet regularly with students and try to understand their goals and aspirations beyond their time in the lab.
  • I should give students an opportunity to provide honest feedback on how I am doing. This is not easy, but some PIs have had success with 6-month reviews.
  • I should encourage all my students to think about how to work on projects with the maximal possible impact, subject to the time constraints they have.
  • I should remind students that publications are not the only currency of value, and indeed are a very volatile and unreliable currency. However, unreported results are of no value to no one.

I think it's worth potentially adding the following points:

  • Students should be my top priority.
  • I should always keep meetings with students. Poor time management is inexcusable. A shared calendar so that students can see my schedule may be a good idea.
  • I should ask my students about the degree to which they would like me to be involved in their work. Some students may need a lot of interaction, others may prefer to be independent, and student needs may change over time.
  • I should be as encouraging as possible.

My new go-to for cheap PCBs: Seeed studio

Full disclosure: Seeed studio emailed me and said I'd get a $30 coupon if I wrote a review of my experience ordering PCBs from them. Edit: May 3, 2017 - they have since delivered on this promise, so I've got $30 to spend on new boards! Sweet. Definitely my new source for pcb manufacturing.

First off, I usually order 2-layer boards, and I'm not pushing the fab limits at all (usually my minimum clearance and trace widths are both >12 mil). My bottom line is price, since I pay for the stuff myself, and I'm a postdoc (hence I'm not rich).

In the past, I've ordered PCBs from Sunstone and Advanced Circuits (4PCB). Mostly, I care about price. At advanced circuits, for $33 I can get a seemingly arbitrarily large 2-layer board (only available to students, otherwise the minimum order quantity is 4), but if I tile a small PCB so that I can get 10 small PCBs for the price of one, then they slap on a $50 array fee. And then there's shipping (which for some reason is always really expensive, like >$20) so the minimum cost is about $50 for a single PCB. Sunstone used to be significantly more expensive, but I recently ordered some boards there for around $50 each.  So, similarly priced.

Recently, a friend of mine told me about Seeed studio. They are fantastically priced - I bought ten 2.2-square-inch boards (2-layer) for $15 there (plus an $18 shipping fee).

I received the board 9 days after ordering - comparable to sunstone and advanced circuits. Quality-wise they're clearly a little bit below sunstone and advanced circuits, as there are minor misalignments in the silkscreen and the soldermask. But so far as I can tell with my first batch, totally functional. Definitely will order again (and update this post if I find any further issues!)


New goal

For every dollar I spend on alcohol, I'm going to donate that same amount to a charity.

Are bacterial mutation rates higher in space?

Apparently Nanobiosym, a biotech company in the area, has decided to send MRSA up to the ISS on a spacex rocket. This is headline-grabbing stuff. From the NASA page:

Proof-of-Concept for Gene-RADAR® Predictive Pathogen Mutation Study (Nanobiosym Genes) evaluates the feasibility of one day using this device from Nanobiosym® to identify bacterial mutations in space. The X Prize-winning device can accurately detect any disease that has a genetic fingerprint, in real time and at the point-of-care. Microgravity may accelerate the rate of bacterial mutations and this pilot investigation analyzes this process in two strains aboard the International Space Station, which may provide insight into how deadly bacteria become drug-resistant.


Seriously, what????? $20 to anyone who can provide a reasonable and nontrivial explanation (e.g. not like, the cultures were less aerated in space because they weren't on a shaker) for why microgravity would accelerate the rate of bacterial mutations.

From a article, Anita Goel (founder of Nanobiosym) is quoted as saying “[Low Earth Orbit] acts as an incubator to accelerate the mutations that happen with some  bacteria and viruses”.

That makes no sense at all to me. Can anyone explain?

Correlations in time series are sensitive to timescale

... and it's something that perhaps we don't look at quite often enough!

What am I talking about? Well, let's imagine that we're interested in the relationship between two signals, , and . One of the most basic analyses we might do is ask "are they correlated?" But perhaps the correlation depends on the timescale that we focus on. Could a signal be positively correlated at once timescale and negatively correlated at another scale?

Since I've shown you an example, hopefully you believe that a signal could be positively correlated at one timescale and negatively correlated at another! Here, and are positively correlated on a long timescale but negatively correlated on a short timescale.

Can we characterize this sort of relationship? Yes, and I'll outline one way of characterizing this sort of time-scale dependent correlation below.

Continue reading "Correlations in time series are sensitive to timescale"

Paper #20 - Specific roles for DEG/ENaC and TRP channels in touch and thermosensation in C. elegans nociceptors

Title: Specific roles for DEG/ENaC and TRP channels in touch and thermosensation in C. elegans nociceptors

Year: 2010


Here they were interested in discovering which proteins mediate nociception - the sensation of pain. Neurons that detect pain are referred to as nociceptors, and are thought to be multimodal - that is, they respond to many kinds of sensory inputs that generate pain, like heat, cold, harsh touch, extreme pH, or noxious chemicals. This paper seeks to answer the question of how nociceptors obtain their multimodality. Do they have single receptors that respond to all these inputs? Or do they have many receptors? At which point do these sensory inputs converge onto the same signal transduction path?

Continue reading "Paper #20 - Specific roles for DEG/ENaC and TRP channels in touch and thermosensation in C. elegans nociceptors"