diff --git a/NAMESPACE b/NAMESPACE index 10d72cf..af0a818 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(combine_sites) export(daily_pls) export(is_valid_pH) +export(time_pls) import(assertive) import(dplyr) import(ggplot2) diff --git a/R/time_pls.R b/R/time_pls.R index 33d73a5..fe93108 100644 --- a/R/time_pls.R +++ b/R/time_pls.R @@ -1,10 +1,23 @@ -# data <- data -# dates <- data$date -# y <- data$cfs -# X <- cbind(data$p,data$tmin,data$tmax) - -time_pls <- function(y,X,dates,lag=365,ncomps=3) { +#' @title time_pls +#' @description Performs pls regression on time series data for a given number of lags. +#' @param y Vector of variable to predict using pls +#' @param X Matrix of covariates for pls +#' @param lag Number of lags to be used for creating pls components +#' @param ncomps Number of components for pls regression +#' @import plsdepot +#' @import assertive +#' @examples +#' \dontrun{ +#' data <- data +#' dates <- data$date +#' y <- data$cfs +#' X <- cbind(data$p,data$tmin,data$tmax) +#' plsm1 <- time_pls(y,X,dates,lag=30,ncomps=3) +#' } +#' @export + +time_pls <- function(y,X,dates,lag=30,ncomps=3) { mutate <- dplyr::mutate @@ -25,6 +38,7 @@ time_pls <- function(y,X,dates,lag=365,ncomps=3) { # run partial least squares regression pls_model <- plsreg1(X, y, comps = ncomps) + pls_model$dates <- dates return(pls_model) # month <- data$month[(lag+1):nrow(data)] diff --git a/man/time_pls.Rd b/man/time_pls.Rd new file mode 100644 index 0000000..b074828 --- /dev/null +++ b/man/time_pls.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/time_pls.R +\name{time_pls} +\alias{time_pls} +\title{time_pls} +\usage{ +time_pls(y, X, dates, lag = 30, ncomps = 3) +} +\arguments{ +\item{y}{Vector of variable to predict using pls} + +\item{X}{Matrix of covariates for pls} + +\item{lag}{Number of lags to be used for creating pls components} + +\item{ncomps}{Number of components for pls regression} +} +\description{ +Performs pls regression on time series data for a given number of lags. +} +\examples{ +\dontrun{ +data <- data +dates <- data$date +y <- data$cfs +X <- cbind(data$p,data$tmin,data$tmax) +plsm1 <- time_pls(y,X,dates,lag=30,ncomps=3) +} +} diff --git a/tests/testthat/test-time_pls.R b/tests/testthat/test-time_pls.R new file mode 100644 index 0000000..971b92f --- /dev/null +++ b/tests/testthat/test-time_pls.R @@ -0,0 +1,5 @@ +context("time series pls") + +test_that("time_pls function exists", { + expect_true(is.function(time_pls)) +})