Covariates specification in the function fit_dfa
Closed this issue · 2 comments
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
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