atsa-es / atsar

Applied time series analysis in R with Stan. Allows fast Bayesian fitting of multivariate time-series models.
https://atsa-es.github.io/atsar/
49 stars 16 forks source link

Covariates specification in the function fit_dfa #3

Closed Giapass closed 4 years ago

Giapass commented 4 years ago

Dear Dr.Holmes and Dr. Ward, I hope you can help me with this issue. I like to specify a group of covariates in a DFA model using the function fit_dfa in atsar. There are no information how to proceed, and the example in github doesn't work, `library(MARSS) data(lakeWAplankton) dat = lakeWAplanktonTrans

use only the 10 years from 1980-1989

plankdat = dat[dat[,"Year"]>=1980 & dat[,"Year"]<1990,]

create vector of phytoplankton group names

phytoplankton = c("Cryptomonas", "Diatoms", "Greens", "Unicells", "Other.algae")

get only the phytoplankton

dat.spp.1980 = plankdat[,phytoplankton] y = t(dat.spp.1980) covar = matrix(runif(10*ncol(y)), nrow=10) covar_index = matrix(1, nrow(y), nrow(covar))

let's make species 1, 3 have the same effects, 2/4 have the same effects and 5 be different

covar_index[1,] = 1:10 covar_index[3,] = 1:10 covar_index[2,] = 11:20 covar_index[4,] = 11:20 covar_index[5,] = 21:30 fit_dfa(y = y, covar=covar, covar_index = covar_index, num_trends=1, iter=500)` Please let me know if there is a change in the code. I am using atsar 0.1.1. Thank you Giannina Passuni

ericward-noaa commented 4 years ago

Hi Giannina -- thanks for flagging this. I have some changes I need to make to this function, and will dig into the issues you noted in the next couple of days.

Thanks for your patience!

Eric

On Mon, Jun 8, 2020 at 10:11 AM Giapass notifications@github.com wrote:

Dear Dr.Holmes and Dr. Ward, I hope you can help me with this issue. I like to specify a group of covariates in a DFA model using the function fit_dfa in atsar. There are no information how to proceed, and the example in github doesn't work, library(MARSS) data(lakeWAplankton) dat = lakeWAplanktonTrans use only the 10 years from 1980-1989

plankdat = dat[dat[,"Year"]>=1980 & dat[,"Year"]<1990,] create vector of phytoplankton group names

phytoplankton = c("Cryptomonas", "Diatoms", "Greens", "Unicells", "Other.algae") get only the phytoplankton

dat.spp.1980 = plankdat[,phytoplankton] y = t(dat.spp.1980) covar = matrix(runif(10*ncol(y)), nrow=10) covar_index = matrix(1, nrow(y), nrow(covar)) let's make species 1, 3 have the same effects, 2/4 have the same effects and 5 be different

covar_index[1,] = 1:10 covar_index[3,] = 1:10 covar_index[2,] = 11:20 covar_index[4,] = 11:20 covar_index[5,] = 21:30 fit_dfa(y = y, covar=covar, covar_index = covar_index, num_trends=1, iter=500) Please let me know if there is a change in the code. I am using atsar 0.1.1. Thank you Giannina Passuni

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nwfsc-timeseries/atsar/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGQEZFH4UG43QVHBKBDUTLRVULSRANCNFSM4NYTILFQ .

--

Eric Ward

Northwest Fisheries Science Center

NOAA Fisheries | U.S. Department of Commerce

Office: 206-302-1745

Mobile: 206-650-7401 https://faculty.washington.edu/warde/

ericward-noaa commented 4 years ago

Ok Giannina, thanks for your patience. There were a couple issues in the code calling the model, and I think those are fixed now. The example runs fine.

The covariate matrix in the example represents a matrix of 10 time series of covariates, so if it's not clear, the covar_index matrix is then a 10 x P matrix of indexing, representing the unique elements being estimated. In this example, there's 30 total coefficients being estimated -- in reality you may only want some covariates to map onto a subset of observed time series. It's also possible to let elements of covar_index be 0, so that there's no effect of covariates on a time series