Urban heat island effect in DTX

 

Overview

Local Sense Lab released extended sensor data that span across ten days, which is helpful as increasing sample size would enable more robust analysis. In this post, I test the difference between the temperature levels between two sensor locations to further my previous analysis on the urban heat island effect (UHI) in Downtown Crossing (DTX).

I used the t test to determine whether the temperature level between city1 and city2 are significantly different. I used ANOVA to support the findings in t test.

 

T Test

ttest

The mean temperature of city1 is 26.65 degrees Celsius and city2, 25.74. The t value is 26.114, which is fairly large. And the p value is almost 0, which confirms that the difference is significant.

 

ANOVA Test

anova1

anova2

The F value came out to be 692, which means that the variance between the two locations is 692 times greater than the variance within each location. With a significant p value, the test confirms that the two locations have significantly different temperature levels.

 

Visualization

You can tell the city 1 has higher temperature level most of the times. The difference become greater during the hottest times of the day.

 

## Plot line graph

baseTemp  <- ggplot(temp, aes(x=timestamp, y=value))

baseTemp+geom_line(aes(color=factor(id_wasp), group=id_wasp))+scale_color_discrete(name=”Sensor”)+labs(title=”Temperature (Celsius)”)

heatExtend.png

 

R Code

##—– Reading two CSV files from Local Sense Lab —–##

city <- read.csv(“C:/Users/Jun Kim/Documents/RData/Data_assignment/Module10/sensor.data.city_extended.csv”)

envi <- read.csv(“C:/Users/Jun Kim/Documents/RData/Data_assignment/Module10/sensor.data.environment_extended.csv”)

#remove columns that were used in the data transmission and do not provide analytical value for the city dataset

city2<-city[c(1:2,6:8)]

#remove columns that were used in the data transmission and do not provide analytical value for the environment dataset

envi2<-envi[c(1:2,6:8)]

# Mark all duplicates in the city dataset

city2$un_flg <- as.numeric(duplicated(city2[2:5]))

# Mark all duplicates in the environment dataset

envi2$un_flg <- as.numeric(duplicated(envi2[2:5]))

# Order the city data by id_wasp, sensor, and timestamp

city3 <- city2[order(city2$id_wasp, city2$sensor, city2$timestamp),]

# Order the environment data by id_wasp, sensor, and timestamp

envi3 <- envi2[order(envi2$id_wasp, envi2$sensor, envi2$timestamp),]

## Convert timestamp to POSIxct

city4 <- city3

# Changing the data type

newTimeEnv <- as.POSIXct(city4$timestamp, format=”%Y-%m-%d %H:%M:%S”)

# Assigning the new data to a new data frame

city4$timestamp <- newTimeEnv

# Verifying that the data type of timestamp column (should return POSIXct)

class(city4$timestamp[1])

# Repeat for envi

envi4 <- envi3

# Changing the data type

newTimeEnv <- as.POSIXct(envi4$timestamp, format=”%Y-%m-%d %H:%M:%S”)

# Assigning the new data to a new data frame

envi4$timestamp <- newTimeEnv

# Verifying that the data type of timestamp column (should return POSIXct)

class(envi4$timestamp[1])

# Remove Aug. 10 and Aug. 19 data for city (to compare each date)

city5 <- city4[!(city4$timestamp < “2016-08-11 00:00:00 EDT”),]

city5 <- city5[!(city5$timestamp > “2016-08-18 23:59:59 EDT”),]

# Remove duplicates

city6 <- city4[!(city4$un_flg==1),]

envi6 <- envi4[!(envi4$un_flg==1),]

# Subset by sensor and id_wasp

co      <- envi6[which(envi6$sensor == “CO”), ]

coEnvi1 <- co[which(co$id_wasp == “environ1”), ]

coEnvi2 <- co[which(co$id_wasp == “environ2”), ]

no2      <- envi6[which(envi6$sensor == “NO2”), ]

no2Envi1 <- no2[which(no2$id_wasp == “environ1”), ]

no2Envi2 <- no2[which(no2$id_wasp == “environ2”), ]

o2      <- envi6[which(envi6$sensor == “O2”), ]

o2Envi1 <- o2[which(o2$id_wasp == “environ1”), ]

o2Envi2 <- o2[which(o2$id_wasp == “environ2”), ]

co2      <- envi6[which(envi6$sensor == “CO2”), ]

co2Envi1 <- co2[which(co2$id_wasp == “environ1”), ]

co2Envi2 <- co2[which(co2$id_wasp == “environ2”), ]

temp   <- city6[which(city6$sensor == “GP_TC”), ]

tempCity1 <- temp[which(temp$id_wasp == “city1”), ]

tempCity2 <- temp[which(temp$id_wasp == “city2”), ]

humid   <- city6[which(city6$sensor == “GP_HUM”), ]

humidCity1 <- humid[which(humid$id_wasp == “city1”), ]

humidCity2 <- humid[which(humid$id_wasp == “city2”), ]

decib   <- city6[which(city6$sensor == “MCP”), ]

decibCity1 <- decib[which(decib$id_wasp == “city1”), ]

decibCity2 <- decib[which(decib$id_wasp == “city2”), ]

lumino   <- city6[which(city6$sensor == “LUM”), ]

luminoCity1 <- lumino[which(lumino$id_wasp == “city1”), ]

luminoCity2 <- lumino[which(lumino$id_wasp == “city2”), ]

# Create new data frame for environ1

envi6_1 <- data.frame(coEnvi1$timestamp, coEnvi1$value, no2Envi1$value, o2Envi1$value, co2Envi1$value)

names(envi6_1)[1] <- “Time”

names(envi6_1)[2] <- “COenv1”

names(envi6_1)[3] <- “NO2env1”

names(envi6_1)[4] <- “O2env1”

names(envi6_1)[5] <- “CO2env1”

# Create ew data frame for environ2

envi6_2 <- data.frame(coEnvi2$timestamp, coEnvi2$value, no2Envi2$value, o2Envi2$value, co2Envi2$value)

names(envi6_2)[1] <- “Time”

names(envi6_2)[2] <- “COenv2”

names(envi6_2)[3] <- “NO2env2”

names(envi6_2)[4] <- “O2env2”

names(envi6_2)[5] <- “CO2env2”

# List names for both data frames

names(envi6_1)

names(envi6_2)

## T test

t.test(tempCity1$value, tempCity2$value)

## ANOVA test

anova <- aov(value~id_wasp, data=temp)

summary(anova)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s