Run
devtools::install_github("daeyounglim/TSEnergy")
Click the "Clone or download" button and download ZIP. Run the following commands:
unzip("TSEnergy-master.zip")
file.rename("TSEnergy-master", "TSEnergy")
shell("R CMD build TSEnergy")
install.packages(list.files(pattern="(TSEnergy)(.*)(.tar.gz)"), repos = NULL, type = "source")
The package runs C++ behind the scenes, and therefore the computer on which this package will be used must have C++ compilers installed beforehand. Otherwise, the installation might fail.
- For Windows users - Download and install Rtools from the website.
- For Mac users - Please install the latest Xcode. It comes with all related compilers.
- For Linux - Install
r-base-dev
through the package manager of your system. For example, on Ubuntu 18.04, runapt install r-base-dev
.
After the compilers are ready, try installing the package again. The dependency installation is supposed to be automated but if R
complains, then run the following:
install.packages("Rcpp", "RcppArmadillo", "RcppProgress", "BH")
When the packages above are successfully installed, run devtools::install_github('daeyounglim/TSEnergy')
or following the complex version.
When using the devtools::install_github
, some Linux distros fire the following error message:
tar: This does not look like a tar archive
gzip: stdin: unexpected end of file
In that case, check if getOption("download.file.method")
is curl
. Then, run options("download.file.method" = "libcurl")
and then try installing again through devtools::install_github("daeyounglim/TSEnergy")
.
######################
# Univariate Box-Cox #
######################
x0 <- read_csv("data-0415_Pharmacy_Biology_Building-10415x_CW_CHWTON-2019-05-09.csv")
x <- x0 %>% filter(TimeStamp >= ymd_hms("2018-07-01 00:00:00"),
TimeStamp < ymd_hms("2018-08-01 00:00:00"))
y <- x$Reading %>% scale(center=FALSE) %>% drop
n <- length(y)
x1 <- x$TempRead %>% scale %>% drop
x2 <- x$HumidityRead %>% scale %>% drop
x3 <- 1*(hour(x$TimeStamp) %in% c(0:6, 19:23))
xobs <- cbind(1, x1, x2, x3)
zobs <- cbind(1, x1, x2)
uobs <- cbind(1, x1, x2, x3)
fit <- boxcoxar(y, integer(length(y)), mcmc=list(ndiscard=10000, nkeep = 20000),
xobs = xobs, zobs = zobs, uobs = uobs, verbose=TRUE)
## Get the estimates
## (will be made into 'fitted' function soon)
beta.est <- rowMeans(fit$mcmc.draws$beta)
alpha.est <- rowMeans(fit$mcmc.draws$alpha)
eta.est <- rowMeans(fit$mcmc.draws$eta)
yobs
- a vector of measured energy usage to be used as the response variablemiss
- a vector of binary values (0 or 1), each element of which indicates whether the response variable is missinga
- the shift parameter for the Box-Cox. By default, set to the minimum value minus one.xobs
- the covariate matrix for the main regression equationzobs
- the covariate matrix for the Box-Cox transformation parameter lambdauobs
- the covariate matrix for the time-dependent variances sigma2mcmc
- list of MCMC-related parameters: number of burn-ins (ndiscard), number of thinning(nskip), and posterior sample size (nkeep)prior
- list of hyperparameters; when not given, algorithm will run in default settingverbose
- logical variable for printing progress bar. Default to FALSE.
- When creating an R package, don't forget to register the native symbols by running the following:
tools::package_native_routine_registration_skeleton(".", "src/init.c", character_only=FALSE)
- When put datasets in the package, use
usethis::use_data_raw()
to createdata-raw/
folder and after preparing the dataset, saydf
, run the following:
devtools::use_data(df)
Then, the convention is to document the datasets in R/data.R
in the format of
#' Data from Experiment 1
#'
#' This is data from the first experiment ever to try XYZ using Mechanical
#' Turk workers.
#'
#' @format A data frame with NNNN rows and NN variables:
#' \describe{
#' \item{subject}{Anonymized Mechanical Turk Worker ID}
#' \item{trial}{Trial number, from 1..NNN}
#' ...
#' }
"df"
- Create
R/global.R
and include all global variables that will be used in the documentation. This includes all
- MCMC for univariate Box-Cox model
- MCMC for multivariate Box-Cox model
- MCMC for multivariate Box-Cox model with skewness accounted for
- MCMC for multivariate Box-Cox model with heavy-tail accounted for
- MCMC for multivariate Box-Cox model with both skewness and heavy-tail accounted for
- DIC and LPML for each model
- R functions such as
fitted
,print
,summary
,plot
for each class