Saturday, February 21, 2015

Google Chrome

Never open more than 3 tabs at a time. If you must open another tab, first choose a tab to close.

Friday, February 6, 2015

Blogging platforms and moonlight

I'm contemplating moving the blog to wordpress. Since a big chunk of what I post nowadays tends to be code with all these greater than and less than signs, it totally throws the html on the blogger off. It is amazing to me that blogger won't add this small little feature that let's you insert code seamlessly with something like a code tag that wordpress provides. It is 2015 and it is very surprising to see that blogger would let so many users slip away but not pluck the low hanging fruit of adding code tags. I personally do not want to move the blog, but that is out of two entirely irrational reasons: one, that I'm lazy and do not have the time or enthusiasm to set up a blog from scratch, and two, that I've been on here for ten years now and it feels like home and so I don't want to leave.

I've been meaning to add tutorials for some great R libraries like dplyr, ggplot2, and shiny, and also some Python tutorials but before that I have fulfill the promise I made to myself of adding tutorials for the relatively uninspiring parts of R that form its basics. And, at any rate, to get started with any of that - it seems like moving to wordpress is the way. A couple of days ago, I tried to embed code snippets in earlier R posts but the results were clumsy and off-putting.

In any case, an interesting thing I learned today (let's assume I won't be adding anything else tonight): the earth's moon was once an asteroid that struck the earth and the hot molten ball that rebounded extremely slowly became the moon a couple hundred million years later. All that romantic poetry with moon as the evergreen metaphor seems a little incongruent now, doesn't it?

Monday, February 2, 2015

Some less talked about positives of the American Civil War

This is not a defense of wars, but the American Civil War had several positives coming out of it, and I thought I'd outline them briefly. Of course, it was at a great cost of 600,000 lives, about 2 percent of the entire US population at the time. Everybody knows about the biggest achievement of the war, which was also in large part the main engine behind the war: the abolition of slavery. Here I will mention some of the other, often overlooked positives:

1. For the first time, the recently discovered Bromine was used for healing and cleaning wounds. It improved standards of hygiene in wartime medical assistance in a big way, significantly reducing casualties where soldiers succumbed not to bullet wounds but to the ensuing gangrene.

2. Before the civil war, nursing was a primarily male occupation. With this war, the need for nursing outgrew the supply that men alone could furnish, bringing women in large numbers into the nursing profession. Alongside textile mills of the same period, this paved the way for women getting out of their houses for work in large numbers.

3. Working as a nurse at the time of the war inspired Carla Barton to start the American Red Cross post the war, an organization that has since saved millions of lives.

4. Embalming, the practice of using zinc chloride and arsenic for the preservation of the dead bodies of soldiers was an innovation of the civil war, which meant that the bodies could be received by their families, even weeks later, in recognizable and non-decomposed conditions for their last rites.

5. Telegram got a boost by Lincoln as a method of mapping and devising macro and micro level strategies. This would continue to remain a masterstroke of wartime planning for decades to come, including during the world wars.

6. In many ways, it was the first modern war. Before the civil war, the battle capacity of any regiment was limited by how much artillery they could carry with them. Once they were out of supplies, they could fight no longer. This was the first war to isolate supplies from actual offensives, by employing railroads to continually and strategically supply new arms to the fighting troops.

Sunday, February 1, 2015

R for Basic Statistics - 1

R for Simulation, Sampling and Inference


outcomes = c("heads", "tails")
sim_fair_coin = sample(outcomes, prob=c(0.4,0.6) , size=100, replace=TRUE)

Another use of sample() is to sample n elements randomly from a vector v.
sample(v, n)

To create a vector of size 15 all of whose value are identical:
vector2=rep(NA, 15). NA is often used as placeholder for missing data in R.

For loop in R
for (i in 1:50) {}

Compare to Python (later)

Divide a plot into multiple plots using (following example divides plotting area into three rows and 1 column):

par(mfrow = c(3, 1))

Set the scale of any graph using xlim and ylim arguments.

range() when applied on vector gives a vector of length 2 showing the smallest and largest element of that vector. It is useful to set the scale of graphs using xlim and ylim. For example:

# Define the limits for the x-axis:
xlimits = range(sample_means10)
# Draw the histogram:
hist(sample_means10, breaks=20, xlim=xlimits)

A complete confidence-interval example (comment code later):

# Initialize 'samp_mean', 'samp_sd' and 'n':
samp_mean = rep(NA, 50)
samp_sd = rep(NA, 50)
n = 60

for (i in 1:50) {
   samp = sample(population, n)
   samp_mean[i] = mean(samp)
   samp_sd[i] = sd(samp)

# Calculate the interval bounds here:
lower=samp_mean - 1.96*samp_sd/sqrt(n)
upper=samp_mean + 1.96*samp_sd/sqrt(n)

# Plotting the confidence intervals:
pop_mean = mean(population)
plot_ci(lower, upper, pop_mean)

Please note below in the output of the program above, a great use case for plot_ci chart.