library(readxl)
datos <- read_excel("G:/My Drive/2_Investigacion/Arquitectura/El Cerro.xlsx", skip=1)
# Modificando los nombres
colnames(datos) <- c('fecha', 'hora',
'text', 'thab', 'tcom', 'test',
'hext', 'hcom', 'hest')
# Explorando las 6 primeras observaciones
head(datos)
## # A tibble: 6 x 9
## fecha hora text thab tcom test hext
## <dttm> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2016-12-12 00:00:00 1899-12-31 00:00:00 12.9 16 15.6 17.1 72.1
## 2 2016-12-12 00:00:00 1899-12-31 00:15:00 12.6 16 15.6 16.8 72.8
## 3 2016-12-12 00:00:00 1899-12-31 00:30:00 12.6 15.6 15.6 16.8 73.6
## 4 2016-12-12 00:00:00 1899-12-31 00:45:00 12.9 15.6 15.6 16.8 74.4
## 5 2016-12-12 00:00:00 1899-12-31 01:00:00 12.6 15.6 15.6 16.8 74.4
## 6 2016-12-12 00:00:00 1899-12-31 01:15:00 12.6 15.6 15.6 16.8 73.6
## # ... with 2 more variables: hcom <dbl>, hest <dbl>
La base de datos tiene 28032 observaciones y 9 variables.
kde2dEsta función pertenece al paquete MASS y sirve para estimar densidades cuando se tienen dos variables \(X\) y \(Y\).
Para estimar la densidad de la temperatura exterior y la temperatura de la habitación se usa el siguiente código.
require(MASS)
f <- kde2d(x=datos$thab, y=datos$text, n=50)
El objeto f es una lista con 3 elementos, f$x y f$y son vectores mientras que f$z es una matriz.
Para construir un diagrama de calor se usa lo siguiente.
image(f, las=1, col=hcl.colors(20, "greens", rev=TRUE),
xlab='Temperatura habitación (°C)',
ylab='Temperatura exterior (°C)',
main='El Cerro')
filled.contour(x=f$x, y=f$y, z=f$z, nlevels=10,
col=hcl.colors(10, "greens", rev=TRUE),
xlab='Temperatura habitación (°C)',
ylab='Temperatura exterior (°C)',
main='El Cerro')
Para obtener una superficie que se puede mover con el mouse.
require(plotly)
plot_ly(x=f$x, y=f$y, z=f$z, type = "surface") %>%
layout(title = "Superficie del Rendimiento",
scene = list(
xaxis = list(title = "Temperatura habitacion"),
yaxis = list(title = "Temperatura exterior"),
zaxis = list(title = "Densidad")))
Las temperaturas mínima y máxima registradas en la base de datos son:
library(dplyr)
datos %>% select(text, thab, tcom) %>% summarise_all(list(minimo=min, maximo=max))
## # A tibble: 1 x 6
## text_minimo thab_minimo tcom_minimo text_maximo thab_maximo tcom_maximo
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 9.42 12.6 12.6 22.9 21.7 22.5
Con la información anterior podemos crear dos diagramas de calor.
f1 <- kde2d(x=datos$thab, y=datos$text, n=50, lims=c(9, 23, 9, 23))
f2 <- kde2d(x=datos$tcom, y=datos$text, n=50, lims=c(9, 23, 9, 23))
par(mfrow=c(1, 2))
image(f1, las=1, col=hcl.colors(20, "greens", rev=TRUE),
xlab='Temperatura habitación (°C)',
ylab='Temperatura exterior (°C)',
main='El Cerro')
image(f2, las=1, col=hcl.colors(20, "greens", rev=TRUE),
xlab='Temperatura comedor (°C)',
ylab='Temperatura exterior (°C)',
main='El Cerro')
d <- f1$z - f2$z
sum(d^2)
## [1] 0.03852746
En el enlace de abajo hay una sugerencia para comparar
The Pearson correlation coefficient is a measure of the linear correlation between two variables X and Y. It has a value between +1 and −1, where 1 is total positive linear correlation, 0 is no linear correlation, and −1 is total negative linear correlation.
alt text
plot(x=as.vector(f1$z), y=as.vector(f2$z),
xlab="Densidad f1", ylab="Densidad f2")
cor.test(f1$z, f2$z)
##
## Pearson's product-moment correlation
##
## data: f1$z and f2$z
## t = 227.62, df = 2498, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9748564 0.9784680
## sample estimates:
## cor
## 0.9767314
f1 <- kde2d(x=datos$thab, y=datos$text, n=50, lims=c(9, 23, 9, 23))
f2 <- kde2d(x=datos$test, y=datos$text, n=50, lims=c(9, 23, 9, 23))
par(mfrow=c(1, 2))
image(f1, las=1, col=hcl.colors(20, "greens", rev=TRUE),
xlab='Temperatura habitacion (°C)', ylab='Temperatura exterior(°C)')
image(f2, las=1, col=hcl.colors(20, "greens", rev=TRUE),
xlab='Temperatura estudio (°C)', ylab='Temperatura exterior(°C)')
plot(x=as.vector(f1$z), y=as.vector(f2$z),
xlab="Densidad f1", ylab="Densidad f2")
cor.test(f1$z, f2$z)
##
## Pearson's product-moment correlation
##
## data: f1$z and f2$z
## t = 13.837, df = 2498, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2300211 0.3028527
## sample estimates:
## cor
## 0.2668178