Skip to content

Commit

Permalink
updated the time_pls function
Browse files Browse the repository at this point in the history
  • Loading branch information
scworland committed Jun 8, 2017
1 parent d6207a2 commit 5e8e2de
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(combine_sites)
export(daily_pls)
export(is_valid_pH)
export(time_pls)
import(assertive)
import(dplyr)
import(ggplot2)
Expand Down
26 changes: 20 additions & 6 deletions R/time_pls.R
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)]
Expand Down
29 changes: 29 additions & 0 deletions man/time_pls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/testthat/test-time_pls.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
context("time series pls")

test_that("time_pls function exists", {
expect_true(is.function(time_pls))
})

0 comments on commit 5e8e2de

Please sign in to comment.