-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Dynamic Factor Analysis options and vignette (#16)
* developing DFA vignette * adding test for gmrf_parameterization options * fix bug when Gamma is rank-deficient * Update dynamic_factor_analysis.Rmd * update DFA vignette * fix bug in simulate.dsem from last commit * add error-check for duplicate colnames in tsdata * fix vignette.Rmd error in wolf-moose example * add error check * update DFA vignette and helper function * Update dynamic_factor_analysis.Rmd * add convergence warnings * fix variance-check for missing data * add test for Bering Sea run * update summary_mcmc to matching indexing * small fixes to DFA vignette * update Imports ... ... after R-CMD-check * remove junk --------- Co-authored-by: Jim Thorson <[email protected]>
- Loading branch information
1 parent
09566c3
commit 0769a36
Showing
17 changed files
with
953 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
#' @title Make text for dynamic factor analysis | ||
#' | ||
#' @description | ||
#' Make the text string for a dynamic factor analysis expressed using | ||
#' arrow-and-lag notation for DSEM. | ||
#' | ||
#' @param variables Character string of variables (i.e., column names of \code{tsdata}). | ||
#' @param n_factors Number of factors. | ||
#' @param factor_names Optional character-vector of factor names, | ||
#' which must match NA columns in \code{tsdata}. | ||
#' | ||
#' @return | ||
#' A text string to be passed to \code{\link{dsem}} | ||
#' | ||
#' @export | ||
make_dfa <- | ||
function( variables, | ||
n_factors, | ||
factor_names = paste0("F",seq_len(n_factors)) ){ | ||
|
||
# pre-processing | ||
n_variables = length( variables ) | ||
text_matrix = NULL | ||
|
||
# Factor SDs | ||
for( f in 1:n_factors ){ | ||
SD = c( paste(factor_names[f], "<->", factor_names[f]), 0, NA, 1 ) | ||
text_matrix = rbind( text_matrix, SD ) | ||
} | ||
|
||
# Factor RWs | ||
for( f in 1:n_factors ){ | ||
AR = c( paste(factor_names[f], "->", factor_names[f]), 1, NA, 1 ) | ||
text_matrix = rbind( text_matrix, AR ) | ||
} | ||
|
||
# Factor loadings | ||
for( f in 1:n_factors ){ | ||
for( v in f:n_variables ){ | ||
Load = c( paste(factor_names[f], "->", variables[v]), 0, paste0("L",f,v), 0.1 ) | ||
text_matrix = rbind( text_matrix, Load ) | ||
}} | ||
|
||
# Fix SD = 0 for additional process errors | ||
for( v in 1:n_variables ){ | ||
extraSD = c( paste(variables[v], "<->", variables[v]), 0, NA, 0 ) | ||
text_matrix = rbind( text_matrix, extraSD ) | ||
} | ||
|
||
# Output | ||
text_vec = apply( text_matrix, paste, MARGIN=1, collapse=", " ) | ||
text = paste0( text_vec, collapse="\n" ) | ||
return( text ) | ||
} |
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.