Sunday, January 29, 2017

Statistics while Driving To Work

Interesting science and data is all around us in our everyday lives. It sometimes just takes a paper and pen (or notepad app on your phone) in order to capture and analyze it. Having recently moved to a new city and new house, I decided that I wanted to statistically solve the age-old problem: which route is fastest for my drive to/from work? I narrowed the test down to 3 separate routes. When determining which one is the best, though, it's not as simple as driving them each a single time. I wanted to determine which one was statistically better over many trips to account for the changing road conditions, stop lights, time of day, etc. After all, saving 2 minutes from your daily commute can add up to over 8 hours per year (2 minutes per day * 5 days/week * 50 weeks of work/yr= 500 minutes!)!!

Results Summary

Data Source Stats

We have two different cars (Passat and Explorer); I also collected data in both the morning and evening. I've included the statistics for how much each car and route were driven. I recorded data for a total of 35 trips (over a period of a few months):

Here we can see that route 2 had more overall trips, but overall the trips were mostly evenly spread. Regarding car, trips were recorded nearly evenly between the two. It did seem that I preferred to record data after my evening drive more than my morning. This may have been as a result of my haste to get into the office, I forgot to write down the drive time on several occasions.

Data Representation

I have been listening to an NPR podast called "Note to Self" that analyzes our relationship to data, social media, and technology. One interesting episode described two data scientists who recorded small details about their lives every week, drew sketches compiling this data in interesting ways, and sent it to each other on a postcard - NPR Note To Self - Facing our Weirdest Selves (see pictures of examples and audio of the episode). This episode inspired me to make a drawing that represented the data that I collected during this process as shown below:

I've represented the different routes by the three different colors (Route 1 - Grey, Route 2 - Orange, Route 3 - Blue). Morning and evening were drawn as circle or square respectively. Which vehicle was used (Explorer or Passat) was also represented, with trips in the explorer having a smaller shape inside, and Passat ones using the open symbol. The size of the shape represents the time that each trip took. The fastest trips are smallest, and the slowest trips use the largest symbols.

Dataset Statistics

On with the statistics: Tables that represented the statistic for trips along the three different routes are represented below:

I've included the average, standard deviation, max/min, and quartile 1/quartile 3 for the dataset along the different routes.

I also generated a Box Plot (using Excel's Stock Chart - which was tricky to learn), shown below.

From the table and Box Plot, we can see the differences more clearly. The average trip length for Route 1 was a bit higher than Route 2 and 3. However, Route 2 had the largest standard deviation and both the longest and shortest trip lengths. This may have been partially related to the fact that Route 2 also had the largest number of trips (40% of the total as shown in the Pie chart above). While one could with some certainty say that Route 1 seems longer than Route 2 and 3, a simple hypothesis test can show this.

Hypothesis Testing

Hypothesis testing can be used to determine whether two data distributions have the same mean values or not, known as T-testing in this case. This article from NIST.gov illustrates how to perform this test.

First, the T-statistic needs to be computed for the three cases (Route 1 vs Route 2, Route 2 vs. Route 3, and Route 1 vs. Route 3). The T statistic can be computed using:

Where YBar1 is the average for route 1, s1 is the standard deviation, and N1 is the number of times driven.

Then the hypothesis should be rejected if the t-test gives a significance of less than 5%.
This was computed using the excel function =T.dist(-1*T, DOF, True); Where DOF (degrees of freedom) was computed using v- given in the reference [or just N1+N2 -2 if equal variances are assumed]. Of course, this process can be skipped if the number of replicates is equal for the different cases.

The results are summarized in the following table:

Alpha is related to whether the two means are statistically different. Conventionally, if Alpha is greater than 5%, then the two cannot be said to be statistically different. On the other hand, if alpha is less than 5%, then the two can be said to be different. In this case, it is clear that Route 1 is different from 2 and 3. Route 2 and 3 are very nearly equal, and therefore can be presumed to be the same within error (although the hypothesis testing can never fully prove this since they may be similar, but not exactly the same).

Conclusions

Over the course of several months of data collection, I have determined that Route 1 is statistically slower than the others. Having been the one to collect this data, I believe that this may be for two primary reasons: 1. This route goes right by a high school, causing the morning commute to be delayed somewhat, and 2. This route was undergoing some construction, causing detours (that I, for the most part, left out of the dataset). Recently, I have been driving Route 2 almost exclusively, as it does seem to consistently take the least amount of time. Future studies might look at the number of miles for each route (gas mileage?), the number of stop lights, or possibly whether we can resolve a difference in time of day/the car that was used.

Saturday, March 19, 2016

Arduino Powered Sous Vide

Hi all,
I have been playing around a lot w/ electronics, in particular the Arduino. For those that don't know, Arduino is basically an open-source microcontroller (coded in C) that can be used for reading sensors and controlling electronic devices as a result. In this particular post, I decided to do a food-related project called "Sous Vide" that consists of a constant temperature water bath that you can cook various meats in to a perfect, uniform temperature that makes them taste amazing. While there are many commercial products on the market (Amazon affiliate link: Anova Culinary PCB-120US-K1 Bluetooth Precision Cooker, 800 Watts, Black), I wanted to make my own as a fun project.
I started by putting together a power box. This consisted of a solid state relay, a wall outlet (GFCI is probably best), a fused/switched  power input line, a project enclosure box, and an external power source (wall voltage, 120V). The relay was triggered on/off by a 5V signal from the Arduino. I used an Arduino with a buttoned LCD display, and a thermistor temperature sensor. Using these, I was able to build a setup that I could set the temperature I wanted to run at, plug in my crock pot, and control using my power box. (Feel free to purchase components through my Amazon affiliate links)
Unfortunately, the crock pot heated very slowly, taking 1.5 hours to get to temperature. I decided to augment the system using a standard coffee pot heater. Here is a picture of the setup:
Here, I used a wall powered GFCI outlet (for safety), with the powerbox/arduino setup, a slow cooker pot, water pump, and a coffee machine water heater.
The coffee pot heater that I salvaged from an old hot water heater, I used in conjunction with some food safe, high temperature compatible tubing (I had to buy the 1/2" to 1/4" adapter hose barbed pieces on E-bay). The heater  took 120V AC power directly, which I hooked up directly through the solid state relay in the power box.
I purchased a 9V submersible pump that could handle up to 180°F from E-bay, and pumped water through the coffee pot heater at a rate of ~400 mL/min. After hooking up the thermistor and Arudino to complete the control loop. I was able to maintain reasonable control of the temperature. In order to implement my chemical engineering controls knowledge, I built a PID temperature controller that viewed each of the integral, derivative, and proportional controls in Python (wxpython, matplotlib; used Arduino serial communication to send data to laptop):
The first graph: Black is the set point, and red is the temperature (see that it overshoots by ~1.5 degreesF at first, then dampens out). The second graph shows the controller parameters: black is the p (proportional), red is the integral (builds up over time the longer that the system is away from the setpoint), blue is the derivative (accounts for how quickly the temperature is changing), and green is the overall %on (the sum of the others, except for the derivative which is subtracted).
The finished product after I had set the crock pot at 135°F (medium rare temp) for about an hour w/ a nice Ribeye:
After a quick sear (a minute or so) on each side (cast-iron pan with a little bit of oil, quite hot), the steak looked amazing (and tasted the same). The texture was uniform all the way through, and was extremely juicy!

Overall a fun project, let me know if you've got any questions!
Zach

Frost On My Car

So, with the brunt of winter upon us I thought that I would share some of my experiences. Living in Oklahoma, our winter hovers on the edge of freezing quite often. One thing that I noticed right away was that on many nights that were near freezing (35°F or so), I would have to scrape ice off of one side of my car, but not the other. A few questions came to mind, First: Why is my car frosting when the low temperature was not below freezing (32°F)?, Second: Why was the ice only forming on one side of my car and not the other?

So this is approximately the setup of my car sitting in the drive way (garage door in front of it):

First, the initial question: Why would ice form when the temperature wasn't freezing yet? The answer is simple, but probably not something that most people think about. It boils down to radiation. If we think about what temperature the car is in absolute terms (i.e., with the vacuum of space defining a temperature of absolute zero--Zero degrees Kelvin), your car sits at let's say 35°F=1.7°C=275 °K. This is significantly higher temperature than the vacuum of space, which is readily accepting the radiated heat from your vehicle. Of course if the sky is cloudy, the clouds will be significantly hotter than outer space and the chance of frosting over will be much lower.

Question 1: Temperature at Which the Window Should Frost

Now, to do a quick thought experiment to determine lowest approximate ambient temperature (T∞) that might lead to the window frosting over.

The amount of heat radiated from your car window to space can be described using the Stephan Boltzmann Law (assuming your car window is a black body):

q = σ (Twindow - Tspace)^4

Where q is the heat flux (per unit area), σ is the Stefan Boltzmann constant (5.67E-8 W/m^2/K^4), Twindow is the temperature of your car in Kelvin, and Tspace is the temperature of outer space.

However, the story is not so simple because the car window is actually receiving radiation from all around (the adjacent buildings, walls, etc). Here is a schematic (and actually picture) from the car of the adjacent building that shows the "view factor" of the window to space.

And the actual picture from the car:

In this case, the "view factor", accounts for what percentage of the window surface can radiate to another object (in this case, we'll consider outer space and the adjacent house). From this picture, I'll estimate the view factor of the window to space as ~0.1 (i.e., 10% of the radiation from the window is radiated to space while 90% is radiated to the adjacent house/ground/etc.). Also, the window is at a slightly lower temperature (let's say the freezing temperature of water, Twindow=32°F=0°C=273.15°K) than the adjacent house (which is warmer--possibly around or slightly higher than the ambient temperature, T∞).

The net  heat loss from the window due to radiation can be computed by:

Where we've assumed that space is approximately 0°K and that the adjacent house temperature is slightly higher than the ambient temperature (Thouse = T∞+ΔT). With this, we've developed a function for the amount of radiative heat transfer out of the window given the ambient temperature (T∞) and an assumption for the house temperature relative to ambient (say ΔT = 4°C or so--as in the house hasn't quite cooled down to ambient yet--which is reasonable).

Natural Convection

Now that we've considered the radiative component of heat transfer, let's consider the counteracting force of convective heat transfer. In this case, because the window is at the frosting temperature (Twindow=0°C=273.15K) and the ambient air is possibly a higher temperature, the ambient air will actually act to warm the window. This will be what is known as natural convection (i.e., cooling by air that moves over a surface due to the fact that  it's being heated or cooling, as opposed to force convection which might happen if it is windy).

The relevant equations that allow us to compute the convective heat transfer coefficient, h is that for the Nusselt number (Nu):

Where kair is the thermal conductivity of air at 0°C (http://www.engineeringtoolbox.com/air-properties-d_156.html) and Lwindow is the characteristic dimension of the window (assumed to be ~1 meter). The remaining parameter is the Rayleigh number (Ra), which is given by:

The Rayleigh number is a dimensionless number that is the product of two other dimensionless numbers: the Grashof number (Gr) and the Prandtl number.

The Grashoff number takes the ratio of the fluid buoyancy to the viscous driving forces. Here, we use the thermal expansivity (β = 1/T for an ideal gas) and the kinematic viscosity of air (νair).

We can compute the Ra number for a given ambient temperature (T∞).

Which can be used to compute the convective heat transfer coefficient (h) as a function of T∞.

By balancing the convective (qconv = h*(T∞-Twindow)) and radiative heat fluxes, we can come up with a final answer to the question of what temperature might the window on that side of the car freeze:

The ambient temperature (T∞) which gives a net heat flux of zero (i.e., which can sustain the window at Twindow = 273.15K), for the given assumptions is about 275°K (~35.3°F). This seems like a reasonable estimate, and explains why your car window will frost at above 32°F.

Question 2: Why doesn't the other side of the car frost over?

So to answer question two: why didn't the window on the side of my house ice over? The answer is simple: those windows didn't radiate directly out to space. Their view factor to the adjacent house was too high, and therefore we had significantly less radiative heat loss (the house was actually radiating its heat to the car as well since they are close). The neighbors house, on the other hand, was too far away to provide the same effect (as it had a lower view factor).

In the case of the smaller view factor to space (in the limit of zero), the window will not freeze until the ambient temperature reaches freezing (in reality, it will have to be below freezing to cool the window). This is why it's much more difficult for a car to frost when sitting in a garage or under a car port.

Interestingly, previous questions have been asked before:

First Post

Hey all, this is my first post. The purpose for this blog is to serve as an outlet for my scientific interests, and to document some of my thoughts on a variety of subjects. An engineer by training, I plan on focusing on quantitative calculations and analyses of things of little importance. I'll apply my skills in statistics, programming, data analysis, electronics and instrumentation, etc. to anything and everything!

I thought that I would share a bit about myself and my scientific background.

I'm a PhD, chemical engineering, currently working in R&D for the oil and gas industry.

Quickly, I'll detail a bit about my research from my PhD. I studied thermoelectric materials with Jeff Snyder (who recently transferred to a professor position at Northwestern University). My PhD focused on improving thermoelectric materials, which convert waste heat into electricity. These solid-state devices perform these conversions with no moving parts, and provide reliable transformation for decades at a time. As a result, these materials are often used in conjunction with nuclear power sources for space missions, basically creating a nuclear battery (known as a radioisotope thermoelectric generator, RTG).

Looking forward to it!
Zach