Thursday, February 23, 2012

Political ecology in Australia (Labor's woes)

In the book Dune, by Frank Herbert, one of the main protagonists observes that the biggest threat to most creatures is one of their own kind. This is for the reason that they are in direct competition and that "they share the same basic requirements" -- they eat the same food, seek the same shelter, compete for the same mates, etc.
I thought of this quote recently, watching the antics of the Australian Labor party. Their ideological enemy, the Liberal party, are sitting on amusedly watching Labor tear itself apart. Why are members of Labor so busy fighting each other when their foe sits clearly across the chamber?
I think the reason is highlighted in the above quote. Labor has its niche, and the Liberal party has its niche -- members of each party tend not to change allegiance, and so remain in their party's "territory" in the political "landscape" as though they were fenced within it. Because of this, individuals within each party are effectively competing with others in the same party for positions of power and influence within that party's territory -- in exactly the same way as animals in an ecosystem compete for food and procreation. The fact that they are trashing their "ecosystem" to compete for the resources it contains has an unhappy similarity to humans fighting over resources and reminds me of Solomon's edict to "cut it in two."

This post was written by Angus Wallace and first appeared at guesstimatedapproximations.blogspot.com.au

Wednesday, February 1, 2012

Energy efficiency at home

I am running a half-day workshop this coming Saturday at Northey Street City Farm on how to save energy at home. It covers

  • how to estimate how much power devices are using
  • how to find the best places to invest in energy efficiency at your place
  • how to use the garden to reduce cooling costs
  • some technical understanding of electricity and its supply
  • how to examine behaviours seeking simple changes to save energy and money
  • how to cook to reduce energy use

Here is a link to the manual I have developed. I will refine this in the future and keep this site up-to-date. It is covered by a CC license (details in the pdf). Any comments or suggestions are welcome and will be considered for incorporation.

This post was written by Angus Wallace and first appeared at guesstimatedapproximations.blogspot.com.au

Tuesday, January 24, 2012

Winsorisation in R

I wrote a function to hard-winsorise each column of a data.frame to 3 standard deviations. I couldn't find anything that did this neatly.
It doesn't do any checking of the data, you need to do that yourself. This is licensed under GPL3 or later. Please link back here if cross-posting it elsewhere.

winsor_clip_data <- function (x, std = 3, na.rm = TRUE)
{
clip_vec <- function(dat, min, max){
# hard clip dat to the rangs max, min
dat[dat > max] <- max
dat[dat < min] <- min
return(dat)
}

sds<-as.matrix(apply(x, 2, sd, na.rm=TRUE))
means<-as.matrix(apply(x, 2, mean, na.rm=TRUE))
mins<-means-3*sds
maxs<- means+3*sds
output<- mapply(clip_vec, x, mins, maxs)

return(output)
}

Summary stats in R

I've been looking for an easy way of creating a data.frame of summary statistics in R, and haven't been able to find anything. The summary() function seems to output a list, and it isn't easily malleable into a data.frame. This makes it hard to add other stats to the list, or to query it from other functions. I've written a simple function that uses boxplot() plus a few other bits to make a nice data.frame.

It doesn't do any checking of the data, you need to do that yourself. This is licensed under GPL3 or later. Please link back here if cross-posting it elsewhere.

summary_stats <- function(these_data, output_dir) {

num_NAs=as.data.frame(t(colSums(is.na(these_data))))
rownames(num_NAs)<-"NA count"

means<-as.data.frame(t(colMeans(these_data, na.rm=TRUE)))
rownames(means)<-"means"

num_dat=as.data.frame(t(rep(nrow(these_data),ncol(these_data))))
rownames(num_dat)<-"num data"
names(num_dat)<-names(these_data)

stats<-boxplot(these_data,plot=FALSE)
stats<-as.data.frame(stats$stats[1:5,])
names(stats)<-names(these_data)
rownames(stats)<-c("minimum (excl outliers)","lower quartile","median", "upper quartile", "maximum (excl outliers)")

output<-as.data.frame(rbind(
num_NAs,
num_dat,
means,
stats
))
return(output)
}
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.