Repository navigation
Spatial dynamic factor analysis with tinyVAST #114
Replies: 7 comments 5 replies
|
Yeah, thanks for asking here where the discussion is searchable :) I don't see any issues with that code, but of course I recommend:
both of those help you gain understanding of the model. And regarding the comparison with the 2016 paper ... that paper arose when I was still working out the feature set (eventually in VAST), and then the easier interface (eventually in tinyVAST). Now that there's an expressive interface, I wouldn't focus on matching that paper's specification, and instead focus on what type of inference you want. This model you have will extract a dominant and shared spatio-temporal pattern in log-densities. If you want to reduce it down to a single time-index and spatial response, then that would involve EOF analysis (https://aslopubs.onlinelibrary.wiley.com/doi/abs/10.1002/lno.11238). happy to keep discussing here |
|
You should be able to predict the value of the factor by supplying it as the "Var" in newdata = data.frame( "Var" = "f1", "Year" = 2001, [other columns here] )
predict(out_mod_base, what = "pepsilon1_g", newdata = newdata)have you tried that already? |
|
Hmm. I'll have to think more about the interface for intermediate quantities. It's hard, because ultimately you'll probably want to rotate output for DFA / SDFA / EOF prior to interpretation (see Ultimately, you'll likely want to do this manually. So using that vignette try: Or you can replace Is this enough to get you started exploring? |
|
I'm sorry, but I don't understand the question. Could you please re-iterate the question? |
|
Slight hijack of the thread so apologies. I have a model running roughly: fit = tinyVAST( space_term = sem, This model works and runs great! I can get the predictions that I need, check model fits and make maps of predicted single species data. Where I am getting hung up is how to make something like Figure 2 or 3 in the manuscript you wrote https://besjournals.onlinelibrary.wiley.com/doi/epdf/10.1111/2041-210X.12359. I suspect it is from this line of code in the vignette Lhat_cf[lower.tri(Lhat_cf,diag=TRUE)] = as.list(out$sdrep, what="Estimate")$theta_z But I am not seeing how to do it off the predictions? Or maybe I am mistaken and it isn’t from the predictions and I need to extract loadings from the model in relation to the spatial fields? |
|
These two topics are I think related. A few thoughts:
|
|
Thanks. That all makes sense and I am familiar with the rotations. I just need to wrap my head around doing it over a space to make the heat map/contour plots. Will have a read of your book this weekend and see if that helps me out.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am currently working on fitting a spatial dynamic factor analysis model in tinyVAST. I have been trying to adapt the current SFA vignette codes, but would appreciate any advice on best practices as I expand this out.
For my example I'm looking at a single factor model to attempt to model borealization across the Bering Sea based on multiple environmental variables (bottom temperature, sea ice coverage, bottom salinity, etc.). All factors considered are scaled for a normal distribution at the moment. Currently, I have the example coded up so that the entire SDFA is in the spacetime term for tinyVAST, and it does run, but from looking back at your joint dynamic species distribution paper in 2016, I'm not sure if that is the correct or optimal way to look at it.
Below are the rcodes for a truncated example. Thanks in advance for any advice.
Sem_Opt_mod1 = "
f1 -> f1, 1, NA, 1 # Fixes coefficient to 1- random walk
f1 <-> f1, 0, NA, 1 #Factor 1 Variance. The variance of Factor 1 is fixed to 1.
f1 -> BT_su , 0, l_BT_su #Bottom temperature (summer) loads onto Factor 1.
f1 -> SST_su , 0, l_SST_su #Sea surface temperature (summer) loads onto Factor 1.
f1 -> Storm , 0, l_Storm #storm index loads onto Factor 1.
f1 -> BS_su , 0, l_BS_su # Bottom salinity (summer) loads onto Factor 1.
f1 -> IR , 0, l_IR #Ice retreat loads onto Factor 1.
f1 -> SC_12 , 0, l_SC_12 #Sea ice concentration (Jan_Feb) loads onto Factor 1.
f1 -> SC_34 , 0, l_SC_34 #Sea ice concentration (Mar_Apr) loads onto Factor 1.
f1 -> Peak_CHL, 0, l_Peak_CHL # Peak boom timing loads onto Factor 1
BT_su <-> BT_su, 0, sd_resid #The same
SST_su <-> SST_su, 0, sd_resid #The same
Storm <-> Storm, 0, sd_resid #The same
BS_su <-> BS_su, 0, sd_resid#The same
IR <-> IR, 0, sd_resid #The same
SC_12 <-> SC_12, 0, sd_resid #The same
SC_34 <-> SC_34, 0, sd_resid#The same
Peak_CHL <-> Peak_CHL, 0, sd_resid #The same
"
my_control <- tinyVASTcontrol(
silent = getOption("tinyVAST.silent", T),
gmrf = "proj",
eval.max = 5000,
iter.max = 5000,
getJointPrecision = T
)
start_time <- Sys.time()
Out_mod_1 = tinyVAST(
spacetime_term = Sem_Opt_mod1,
data = Trunc_df_all2 %>% data.frame(),
formula = ST_val ~ 0 + factor(Var),
spatial_domain = Boundary_mesh_trunc,
family = gaussian(),
variables = c("f1", "BT_su", "SST_su", "Storm", "BS_su", "IR", "SC_12", "SC_34", "Peak_CHL"),
space_columns = c("X","Y"),
variable_column = "Var",
time_column = "Year",
control = my_control
)
end_time <- Sys.time()
time_taken <- end_time - start_time
print(time_taken)# "
All reactions