Skip to content
Snippets Groups Projects
Commit 32ec7e74 authored by Ben Anderson's avatar Ben Anderson
Browse files

removed

parent 77ce968f
No related branches found
No related tags found
No related merge requests found
# Header ###########################################
# ONS Time Use 2005 data
#
# Explorations using R
#
# Script for use as part of: The Social Science of Energy Storage (PSY6018)
#
# Sheffield/Southampton Centre for Doctoral Training in Energy Storage and its Applications
# http://www.southampton.ac.uk/engineering/postgraduate/research_degrees/energy_storage_cdt.page
#
# Copyright (C) 2014 University of Southampton
#
# Author: Ben Anderson (b.anderson@soton.ac.uk, @dataknut, https://github.com/dataknut)
# [Energy & Climate Change, Faculty of Engineering & Environment, University of Southampton]
#
# end header
# To do: -----------------------------------------------------------------
# Prelims -----------------------------------------------------------------
# clear out all old objects etc to avoid confusion
rm(list = ls())
# load required packages
x <- c("foreign","ggplot2","plyr")
lapply(x, require, character.only = T)
# if this breaks/fails because they haven't been installed use
# install.packages("x")
# path to data
# You will need to have downloaded the data from Dropbox/MOLE
# You will need to change this!!
dpath <- "/Users/ben/Documents/Dropbox/energy-storage-dtc/data/"
# Load data -----------------------------------------------------------------
# First: time use data in long form - this has data in 10 minute time slots
onstu2005_longcsv <- read.csv(paste0(dpath, "/UK-2005-TU-long.csv"))
# Now stop to check what's in it and make sure we understand the format!
head(onstu2005_longcsv, n = 4)
# check values of main acts (the things people reported doing)
table("Main acts"= onstu2005_longcsv$pact)
# check values of location variable (where they reported doing them)
table("Location"= onstu2005_longcsv$lact)
# NB: quite a lot of missing
# check values of months variable (so we see that seasons are represented)
table("Month"= onstu2005_longcsv$t_month)
# Second: survey data
onstu2005_surveycsv <- read.csv(paste0(dpath, "/UK-2005-TU-survey-reduced.csv"))
# check what's in it
head(onstu2005_surveycsv, n = 2)
# Test: Sleep -----------------------------------------------------------------
onstu2005_longcsv$sleep_p <- 0
onstu2005_longcsv$sleep_p[onstu2005_longcsv$pact == "sleeping"] <- 1
onstu2005_longcsv$sleep_s <- 0
onstu2005_longcsv$sleep_s[onstu2005_longcsv$sact == "sleeping"] <- 1
onstu2005_longcsv$sleep_all <- onstu2005_longcsv$sleep_p + onstu2005_longcsv$sleep_s
sleeping <- ddply(onstu2005_longcsv, c("s_dow", "s_halfhour"), summarise, propn=mean(sleep_all))
ggplot(sleeping, aes(x=s_halfhour, y=propn, colour=s_dow, group=s_dow)) + geom_line()
# Practice: Preparing food -----------------------------------------------------------------
# Might not require energy of course...
onstu2005_longcsv$cooking_p <- 0
onstu2005_longcsv$cooking_p[onstu2005_longcsv$pact == "preparing food" & onstu2005_longcsv$lact != "elsewhere"] <- 1
onstu2005_longcsv$cooking_s <- 0
onstu2005_longcsv$cooking_s[onstu2005_longcsv$sact == "preparing food" & onstu2005_longcsv$lact != "elsewhere"] <- 1
onstu2005_longcsv$cooking_all <- onstu2005_longcsv$cooking_p + onstu2005_longcsv$cooking_s
# Need to try to calculate the se somehow if we want error bars?
cooking_all <- ddply(onstu2005_longcsv, c("s_halfhour"), summarise,
propn=mean(cooking_all),
sd=sd(cooking_all),
n=obs(cooking_all))
ggplot(cooking_all, aes(x=s_halfhour, y=propn)) +
geom_line(aes(group=1)) +
geom_point(size=4) +
geom_errorbar(aes(ymin=propn-sd, ymax=propn+sd), width=.2)
cooking_dow <- ddply(onstu2005_longcsv, c("s_dow", "s_halfhour"), summarise, propn=mean(cooking_all))
ggplot(cooking_dow, aes(x=s_halfhour, y=propn, colour=s_dow, group=s_dow)) + geom_line()
# Practice: Car use -----------------------------------------------------------------
onstu2005_longcsv$car_enj_p <- 0
onstu2005_longcsv$car_enj_p[onstu2005_longcsv$pact == "travel - car/enjoyment"] <- 1
onstu2005_longcsv$car_enj_s <- 0
onstu2005_longcsv$car_enj_s[onstu2005_longcsv$sact == "travel - car/enjoyment"] <- 1
onstu2005_longcsv$car_enj_all <- onstu2005_longcsv$car_enj_p + onstu2005_longcsv$car_enj_s
onstu2005_longcsv$car_oth_p <- 0
onstu2005_longcsv$car_oth_p[onstu2005_longcsv$pact == "travel - car/other"] <- 1
onstu2005_longcsv$car_oth_s <- 0
onstu2005_longcsv$car_oth_s[onstu2005_longcsv$sact == "travel - car/other"] <- 1
onstu2005_longcsv$car_oth_all <- onstu2005_longcsv$car_oth_p + onstu2005_longcsv$car_oth_s
onstu2005_longcsv$car_shop_p <- 0
onstu2005_longcsv$car_shop_p[onstu2005_longcsv$pact == "travel - car/shopping"] <- 1
onstu2005_longcsv$car_shop_s <- 0
onstu2005_longcsv$car_shop_s[onstu2005_longcsv$sact == "travel - car/shopping"] <- 1
onstu2005_longcsv$car_shop_all <- onstu2005_longcsv$car_shop_p + onstu2005_longcsv$car_shop_s
car_use <- ddply(onstu2005_longcsv, c("s_halfhour"), summarise, shop=mean(car_shop_all), enj=mean(car_enj_all), other=mean(car_oth_all))
ggplot(car_use, aes(x=s_halfhour, y=shop)) +
aes(group=1) + geom_line()
ggplot(car_use, aes(x=s_halfhour, y=enj)) +
aes(group=1) + geom_line()
# needs to have home as location afterwards for relevance to EV?
# merge them
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment