rm(list = ls()) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", fig.asp = 9/16, fig.width = 7, warning = FALSE )
library(tidyverse) library(broom) library(magrittr) library(forecast) library(ggfortify)
Read the data about heat load in Soenderborg. The model for house 3 is to be modeled, so only the heat load from house 3 is selected. Also, filter the data in winter and store them in ti_winter
.
ti <- read_csv("~/GitHub/tidynamics/data/soenderborg_2day.csv") %>% mutate( "is_win" = as.POSIXlt("2010-11-01") <= as.POSIXlt(.$t) & as.POSIXlt(.$t) < as.POSIXlt("2011-02-01") ) %>% select(t, P3, Te, G, Ws, is_win) %>% drop_na()
li_mod <- list( "entire" = lm(P3 ~ Te, ti), "winter" = lm(P3 ~ Te, filter(ti, is_win)) )
li_mod %>% map_df(tidy, .id = "period")
li_mod %>% map_df(glance, .id = "period")
The P-values of coefficients for intercept and Te
are too small, so neither of them is a qualified model.
autoplot(li_mod$entire, data = ti, colour = "is_win")
According to the two figures in left panel, the variability of the residuals suggests that the variance of heat load is related to its mean, which violates the costant variance assumption. There are many large residuals when the heat load is smaller than 0 during spring, summer and fall. Furthermore, the lower right panel shows there are some observations with large leverages affecting the fitted model.
autoplot(li_mod$winter)
However, the two figures in left panel shows that the model for heat load in winter period fits quite well. The qqplot behaves much better as well. There is no observations with large leverages and large residuals.
forecast::ggtsdisplay(li_mod$entire$residuals, lag.max = 30)
forecast::ggtsdisplay(li_mod$winter$residuals, lag.max = 30)
The residuals from the model fitted with data from entire period show correlation in both ACF and PACF, while those in winter period show insignificant correlation.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.