Templates for Bayesian Regressions

At the Sustainable Development Research (SusDeveR) conference this weekend, I offered some simple tools for performing Bayesian Regressions: Jump to the Github Repository.

The point of these templates is to make it possible for anyone who is familiar with OLS to run a Bayesian regression. The templates have a chunk at the top to change for your application, and a chunk at the bottom that uses Gelman et al.’s Stan to estimate the posterior parameter distributions.

In general, the area at the top is just to create an output vector and a predictor matrix. Like this:
Constructing yy and XX

The template part has all of the Stan code, which (for a Bayesian regression) always has a simple form:
Simple Stan regression model

The last line does all of the work, and just says (in OLS speak) that the error distribution follows a normal distribution. Most of the templates also have a more efficient version, which does the same thing.

I say in the README what Bayesian regressions are and what they do. But why use them? The simple answer is that we shouldn’t expect the uncertainty on our parameters to be well-behaved. It’s nice if it is, and then OLS and Bayesian regressions will give the same answer. But if the true uncertainty on your parameter of interest is skewed or long-tailed or bimodal, the OLS assumption can do some real harm.

Plus, since Bayesian regressions are just a generalization of MLE, you can setup any functional form you like, laying out multiple, nonlinear expressions, estimating intermediate variables, and imposing additional probabilistic constraints, all in one model. Of course, the templates don’t show you how to do all that, but it’s a start.

Relationships with the gods

As I have been re-reading Sitting in the Fire by Arnold Mindell, in preparation for my first London salon, I have been reminded of the considerable role that spirituality has in my secular life. Mindell writes about the “spiritual power” that some people have, and it is a power that I feel. Since I have not been in the recent habit of doing anything to connect with this power, I got to wonder where it comes from and worry I risk losing it.

I realized that a big part of spiritual power or strength consists in being comfortable with one’s relationships with the gods. Whether those relationships are tight or distant, matters less than being at peace with that fact in the moment. But to explain, I need to share something of what I understand of the spiritual world, and my relationship to it.

My world is filled with gods, so these relationships are far from academic. Like Neil Gaiman’s American gods, I believe that there are gods for every aspect of life: a god of Science, of Money, of Blog Posts. And these gods are not just in our heads: the god of Climate Change existed before we bestowed its name.

I have a long history with several of these gods, and I know that some smile upon me, if not which. I maintain a close relationship with some of them, praying to them and sacrificing to them in my own ways. The gods of Truth, Community, and Personal Industry are very high on that list. Many gods, like the British god of Cricket, I have no relationship to at all. Still others I am firmly opposed to, like the god of the Undeserving Poor. That god, by the way, is not a god for any particular group of poor, since they would be deserving of it. Rather, it is a god who throughout the ages has promulgated the idea that there are some poor that are undeserving. A mere mortal like myself cannot fight such a god, but I can sacrifice to other gods who will fight Him.

There is another level of godhood, from which all of these gods draw their power and existence. I believe that there are two primordial gods, the parents of the gods, whom I call the Inner God and the Outer God. I know the Inner God as that spark of the divine that rests deep inside each of us, at the hidden core of our subjective self or the Indian atman. It is the spark behind the spark that lies in our most personal core, a core that is bizarrely shared with everyone else. At the other extreme is the Outer God, the god of the Other and Objectivity, resting at the limits of universe. Although all around us, it is forever distant from us, since our own subjectivity is like endless layers of fog in between.

Spiritual strength demands a kind of cantilevered relationship with these gods too. In some ways, I reach toward the Inner God, and in other ways and other times, toward the Outer God. I worry at times that I stray too far from one or the other, or fail to perform the rites that they deserve. But my recent realization was that this far matters less than the simple recognition of my life lived as forever between them.

Water-Energy-Food Flows

The water-energy-food nexus has become a popular buzz-word in the sustainability field. It aims to capture the idea that water, energy, and food challenges are intertwined, and that shocks to any one can precipitate problems to all three.

I’ve often wondered how closely these three are intertwined though. Water is certainly needed for energy (for thermoelectric cooling and hydropower), but the reverse link (mostly pumping) seems a lot weaker. Water is also needed for food production, but is food needed for water availability? Energy and food have some links, with a fair amount of energy needed to produce fertilizer, and a some “food” production actually going to biofuelds, but the sizes aren’t clear.

Below is my attempt to show these flows, for the United States:

Water-Energy-Food Flows

It seems to me, based on this, that this is less a nexus than water-centered system. Every drop of water is fought over for energy, food, and urban production. It’s less a interconnected nexus than a hub-with-spokes. A way to recognize that water is at the center of it all.

Sources:
– Hydrological flows: Total water (GW+SW) extractions from USGS. Food system only has irrigation and livestock; energy only has thermoelectric. The rest make up the difference.
– Energy system flows: Food system energy from Canning, P. 2010. Energy Use in the U.S. Food System. USDA Economic Research Report Number 94; “In 2010, the U.S. water system consumed over 600 billion kWh, or approximately 12.6 percent of the nation’s energy according to a study by researchers at the University of Texas at Austin.” from http://ift.tt/UJ5XlT “Energy consumption by public drinking water and wastewater utilities, which are primarily owned and operated by local governments, can represent 30%-40% of a municipality’s energy bill.” from https://fas.org/sgp/crs/misc/R43200.pdf; remainder to 100%.
– Biofuels: 18.38e6 m^3 ethanol + 1.7e6 m^3 biodiesel, at a density of 719.7 kg/m^3 is 14.45e6 MT.
– Remainder of food: http://ift.tt/2gMffOn reports 635 billion pounds consumption, 81% of which was domestically produced.

Water-Energy-Food Flows

The water-energy-food nexus has become a popular buzz-word in the sustainability field. It aims to capture the idea that water, energy, and food challenges are intertwined, and that shocks to any one can precipitate problems to all three.

I’ve often wondered how closely these three are intertwined though. Water is certainly needed for energy (for thermoelectric cooling and hydropower), but the reverse link (mostly pumping) seems a lot weaker. Water is also needed for food production, but is food needed for water availability? Energy and food have some links, with a fair amount of energy needed to produce fertilizer, and a some “food” production actually going to biofuelds, but the sizes aren’t clear.

Below is my attempt to show these flows, for the United States:

Water-Energy-Food Flows

It seems to me, based on this, that this is less a nexus than water-centered system. Every drop of water is fought over for energy, food, and urban production. It’s less a interconnected nexus than a hub-with-spokes. A way to recognize that water is at the center of it all.

Sources:
– Hydrological flows: Total water (GW+SW) extractions from USGS. Food system only has irrigation and livestock; energy only has thermoelectric. The rest make up the difference.
– Energy system flows: Food system energy from Canning, P. 2010. Energy Use in the U.S. Food System. USDA Economic Research Report Number 94; “In 2010, the U.S. water system consumed over 600 billion kWh, or approximately 12.6 percent of the nation’s energy according to a study by researchers at the University of Texas at Austin.” from http://ift.tt/UJ5XlT “Energy consumption by public drinking water and wastewater utilities, which are primarily owned and operated by local governments, can represent 30%-40% of a municipality’s energy bill.” from https://fas.org/sgp/crs/misc/R43200.pdf; remainder to 100%.
– Biofuels: 18.38e6 m^3 ethanol + 1.7e6 m^3 biodiesel, at a density of 719.7 kg/m^3 is 14.45e6 MT.
– Remainder of food: http://ift.tt/2gMffOn reports 635 billion pounds consumption, 81% of which was domestically produced.

Johnny Apple “seed”

I found a really fun recipe last year for apple cider, which basically involves putting apples in a pot and boiling them for three hours. The sheer chewiness of it makes it the best apple cider I know. But I wanted to take it a step further this time, and make hard cider. As a SCAdian I know used to say, “Cider wants to be hard.”

But brewing takes equipment. So I headed up to my local Wholefoods, thoroughly expecting a one-stop shop, based on the hipster WFs that I’m familiar with in NYC. Not so for the Royal Borough of Kensington and Chelsea.

Cheesecloth, to strain my apple-mush? Nope, but nylon mesh nut “mylk” bag that will do fine.

Champagne yeast, or similar? Nothing, unless I want my cider to taste like sourdough. So I got a bottle of kombucha, and I’m crossing my fingers.

Gas trap top, to let out the CO2 and keep out bacteria? Nope.

So be it. I once heard about a factory in Mexico that tops all their bottles with condoms: the condom expands as CO2 production heats up, and then deflates.

Does WF sell non-lubricated condoms? Not only do they not; they don’t sell any condoms in this country (at WF). And other nearby pharmacies don’t have non-lubricated ones.

But at this point, I was committed. I opened one up, washed it out as best I could, and now to hope for the best.

Extrapolating the 2017 Temperature

After NASA released the 2017 global average temperature, I started getting worried. 2017 wasn’t as hot as last year, but it was well above the trend.


NASA yearly average temperatures and loess smoothed.

Three years above the trend is pretty common, but it makes you wonder: Do we know where the trend is? The convincing curve above is increasing at about 0.25°C per decade, but in the past 10 years, the temperature has increased by almost 0.5°C.

Depending on how far back you look, the more certain you are of the average trend, and the less certain of the recent trend. Back to 1900, we’ve been increasing at about 0.1°C per decade; in the past 20 years, about 0.2°C per decade; and an average of 0.4°C per decade in the past 10 years.

A little difference in the trend can make a big difference down the road. Take a look at where each of these get you, uncertainty included:

A big chunk of the fluctuations in temperature from year to year are actually predictable. They’re driven by cycles like ENSO and NAO. I used a nice data technique called “singular spectrum analysis” (SSA), which identifies the natural patterns in data by comparing a time-series to itself at all possible offsets. Then you can take extract the signal from the noise, as I do below. Black is the total timeseries, red is the main signal (the first two components of the SSA in this case), and green is the noise.

Once the noise is gone, we can look at what’s happening with the trend, on a year-by-year basis. Suddenly, the craziness of the past 5 years becomes clear:

It’s not just that the trend is higher. The trend is actually increasing, and fast! In 2010, temperatures were increasing at about 0.25°C per decade, an then that rate began to jump by almost 0.05°C per decade every year. The average from 2010 to 2017 is more like a trend that increases by 0.02°C per decade per year, but let’s look at where that takes us.

If that quadratic trend continues, we’ll blow through the “safe operating zone” of the Earth, the 2°C over pre-industrial temperatures, by 2030. Worse, by 2080, we risk a 9°C increase, with truly catastrophic consequences.

This is despite all of our recent efforts, securing an international agreement, ramping up renewable energy, and increasing energy efficiency. And therein lies the most worrying part of it all: if we are in a period of rapidly increasing temperatures, it might be because we have finally let the demon out, and the natural world is set to warm all on its own.

Joining Earl’s Court

We recently moved to the storied streets of London, and then more recently were able to get off the streets and into a super-nice flat a stumble away from the Earl’s Court tube station. We have it all: international cuisine, hip commerce, super-size grocery stores, 400-year-old pub, easy transit, and lots of pretty neighborhoods to explore. I’ve been reading up on the history of my new home, first through London: The Biography, and then a search for old maps lead me to the fascinating Library Time Machine for our borough of Kensington and Chelsea.

One of the fascinating tidbits from those maps is the history of our area’s major roads. Old Brompton Lane and Earl’s Court Road date back to at least 1822 when our house was a pasture, and a single block of homes grew up between the pub and the Earl’s Court Manor. Here’s a mashup of old and new:

I’m surprised that this area is so recently urbanized, but the flip-side is that this was an independent community long before it was on the border of London’s Zone 1, and still retains some of the features of that tiny village.

1 Million Years of Stream Flow Data

The 9,322 gauges in the GAGES II database are picked for having over 20 years of reliable streamflow data from the USGS archives. Combined, these gauges represent over 400,000 years of data.
They offer a detailed sketch of water availability over the past century. But they miss the opportunity to describe a even fuller portrait.

In the AWASH model, we focus on not only gauged points within the river network and other water infrastructure like reservoirs and canals, but also on the interconnections between these nodes. When we connect gauge nodes into a network, we can infer something about the streamflows between them. In total, our US river network contains 22,619 nodes, most of which are ungauged.

We can use the models and the structure of the network to infer missing years, and flows for ungauged junctions. To do so, we create empirical models of the streamflows for any guages for which we have a complete set of gauged of upstream parents. The details of that, and the alternative models that we use for reservoirs, can be details for another post. For the other nodes, we look for structures like these:

Structures for which we can infer missing month values, where hollow nodes are ungauged and solid nodes are gauged.

If all upstream values are known, we can impute the downstream; if the downstream value is known and all but one upstream values are known, we can impute the remaining one; if upstream or downstream values can be imputed according to these rules, they may allow other values to be imputed using that new knowledge. Using these methods, we can impute an average of 44 years for ungauged flows, and an average 20 additional years for gauged flows. The result is 1,064,000 years of gauged or inferred streamflow data.

We have made this data available as a Zenodo dataset for wider use.

Sustainability, Engineering, and Philosophy