Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.Rhistory
.RData
.Ruserdata

# local testing files
tempfiles/
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.1.0
Date: 2024-02-20 15:36:22 UTC
SHA: 40df86c9c02e76044b2499df231d4ddc43ce4940
Date: 2024-02-27 07:01:18 UTC
SHA: 15721ee1ca7a92c51b130bafde6eb79d19e235da
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tsnet
Type: Package
Title: Fitting, Comparing, and Visualizing Networks Based on Time Series Data
Version: 0.1.0
Version: 0.2.0
Authors@R:
c(person("Björn S.", "Siepe",
email = "bjoernsiepe@gmail.com",
Expand All @@ -22,13 +22,14 @@ Encoding: UTF-8
LazyData: true
URL: https://github.com/bsiepe/tsnet
BugReports: https://github.com/bsiepe/tsnet/issues
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
cowplot,
dplyr,
ggdist,
ggokabeito,
ggplot2,
loo,
methods,
posterior,
Rcpp (>= 0.12.0),
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ importFrom(ggdist,stat_slab)
importFrom(ggdist,theme_ggdist)
importFrom(ggokabeito,palette_okabe_ito)
importFrom(ggokabeito,scale_fill_okabe_ito)
importFrom(loo,loo)
importFrom(loo,loo_model_weights)
importFrom(loo,pareto_k_values)
importFrom(loo,psis)
importFrom(loo,relative_eff)
importFrom(loo,weights.importance_sampling)
importFrom(posterior,as_draws_matrix)
importFrom(rlang,.data)
importFrom(rstan,extract)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# tsnet 0.2.0
* Fixed documentation issues (e.g., wrong display of LaTex equations)

# tsnet 0.1.0

* Initial CRAN submission.
21 changes: 11 additions & 10 deletions R/centrality.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
#' a network, while density describes the networks' overall connectedness.
#' Specifically, it computes the in-strength, out-strength, contemporaneous
#' strength, temporal network density, and contemporaneous network density. The
#' result can then be visualized using [plot_centrality()].
#' result can then be visualized using \code{\link{plot_centrality}}.
#'
#' @param fitobj Fitted model object for a Bayesian GVAR model. This can be
#' `tsnet_fit` object (obtained from [stan_gvar()]), a BGGM object (obtained
#' from [BGGM::var_estimate()]), or extracted posterior samples (obtained from
#' [stan_fit_convert()).
#' `tsnet_fit` object (obtained from \code{\link{stan_gvar}},
#' a BGGM object (obtained from \code{\link[BGGM]{var_estimate}} in \code{BGGM}),
#' or extracted posterior samples (obtained from \code{\link{stan_fit_convert}}).
#' @param burnin An integer specifying the number of initial samples to discard
#' as burn-in. Default is 0.
#' as burn-in. Default is \code{0}.
#' @param remove_ar A logical value specifying whether to remove the
#' autoregressive effects for centrality calculation. Default is TRUE. This is
#' only relevant for the calculation of temporal centrality/density measures.
#' autoregressive effects for centrality calculation. Default is \code{TRUE}.
#' This is only relevant for the calculation of temporal centrality/density
#' measures.
#'
#' @return A list containing the following centrality measures:
#' \itemize{
Expand Down Expand Up @@ -106,11 +107,11 @@ get_centrality <- function(fitobj,
#' centrality measures.
#'
#' @param obj An object containing the centrality measures obtained from
#' [get_centrality()].
#' \code{\link{get_centrality}}.
#' @param plot_type A character string specifying the type of plot. Accepts
#' "tiefighter" or "density". Default is "tiefighter".
#' "tiefighter" or "density". Default is \code{"tiefighter"}.
#' @param cis A numeric value specifying the credible interval. Must be between
#' 0 and 1 (exclusive). Default is 0.95.
#' 0 and 1 (exclusive). Default is \code{0.95}.
#'
#' @return A ggplot object visualizing the centrality measures. For a
#' "tiefighter" plot, each point represents the mean centrality measure for a
Expand Down
10 changes: 5 additions & 5 deletions R/check_eigen.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#'
#' This function checks the eigenvalues of the Beta matrix (containing the
#' temporal coefficients) to assure that the model is stationary. It uses the
#' same check as the `graphicalVAR` package. The function calculates the
#' same check as the \code{graphicalVAR} package. The function calculates the
#' eigenvalues of the Beta matrix and checks if the sum of the squares of the
#' real and imaginary parts of the eigenvalues is less than 1. If it is, the VAR
#' model is considered stable.
#'
#' @param fitobj A fitted Bayesian GVAR object. This can be a tsnet_fit object
#' (obtained from [stan_gvar()]), a BGGM object (obtained from
#' [BGGM::var_estimate()]), or extracted posterior samples (obtained from
#' [stan_fit_convert()).
#' (obtained from \code{\link{stan_gvar}}, a \code{BGGM} object (obtained from
#' \code{\link[BGGM]{var_estimate}}), or extracted posterior samples
#' (obtained from \code{\link{stan_fit_convert}}.
#' @param verbose Logical. If TRUE, a verbal summary of the results is printed.
#' Default is TRUE.
#' Default is \code{TRUE}.
#' @examples
#' data(fit_data)
#' fitobj <- fit_data[[1]]
Expand Down
30 changes: 15 additions & 15 deletions R/compare_gvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@
#' <doi:10.31234/osf.io/uwfjc>.
#'
#' @param fit_a Fitted model object for Model A. This can be a tsnet_fit object
#' (obtained from [stan_gvar()]), a BGGM object (obtained from
#' [BGGM::var_estimate()]), or extracted posterior samples (obtained from
#' [stan_fit_convert()).
#' (obtained from \code{\link{stan_gvar}}, a \code{BGGM} object (obtained from
#' \code{\link[BGGM]{var_estimate}}, or extracted posterior samples (obtained from
#' \code{\link{stan_fit_convert}}).
#' @param fit_b Fitted model object for Model B. This can be a tsnet_fit object
#' (obtained from [stan_gvar()]), a BGGM object (obtained from
#' [BGGM::var_estimate()]), or extracted posterior samples (obtained from
#' [stan_fit_convert()).
#' @param cutoff The percentage level of the test (default: 5\%) as integer.
#' @param dec_rule The decision rule to be used. Currently supports default "or"
#' (obtained from \code{\link{stan_gvar}}, a \code{BGGM} object (obtained from
#' \code{\link[BGGM]{var_estimate}}, or extracted posterior samples (obtained from
#' \code{\link{stan_fit_convert}}).
#' @param cutoff The percentage level of the test (default: \code{5}) as integer.
#' @param dec_rule The decision rule to be used. Currently supports default \code{"or"}
#' (comparing against two reference distributions) and "comb" (combining the
#' reference distributions). The use of "or" is recommended, as "comb" is less
#' stable.
#' @param n_draws The number of draws to use for reference distributions
#' (default: 1000).
#' (default: \code{1000}).
#' @param comp The distance metric to use. Should be one of "frob" (Frobenius
#' norm), "maxdiff" (maximum difference), or "l1" (L1 norm) (default:
#' "frob"). The use of the Frobenius norm is recommended.
#' \code{"frob"}). The use of the Frobenius norm is recommended.
#' @param return_all Logical indicating whether to return all distributions
#' (default: FALSE). Has to be set to TRUE for plotting the results.
#' (default: \code{FALSE}). Has to be set to TRUE for plotting the results.
#' @param sampling_method Draw sequential pairs of samples from the posterior,
#' with certain distance between them ("sequential") or randomly from two
#' halves of the posterior ("random"). The "random" method is preferred to
#' account for potential autocorrelation between subsequent samples. Default:
#' "random".
#' \code{"random"}.
#' @param indices A list of "beta" and "pcor" indices specifying which elements
#' of the matrices to consider when calculating distances. If NULL (default),
#' of the matrices to consider when calculating distances. If \code{NULL} (default),
#' all elements of both matrices are considered. If provided, only the
#' elements at these indices are considered. If only one of the matrices
#' should have indices, the other one should be NULL. This can be useful if
#' you want to calculate distances based on a subset of the elements in the
#' matrices.
#' @param burnin The number of burn-in iterations to discard (default: 0).
#' @return A list (of class "compare_gvar") containing the results of the
#' @param burnin The number of burn-in iterations to discard (default: \code{0}).
#' @return A list (of class \code{compare_gvar}) containing the results of the
#' comparison. The list includes:
#'
#' \item{sig_beta}{Binary decision on whether there is a significant difference between the temporal networks of A and B}
Expand Down
12 changes: 6 additions & 6 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#' Simulated Time Series Dataset
#'
#' This dataset contains a simulated time series dataset for two individuals
#' generated using the `graphicalVAR` package. The dataset is useful for testing
#' generated using the \code{graphicalVAR} package. The dataset is useful for testing
#' and demonstrating the functionality of the package.
#'
#' @format ## `ts_data` A data frame with 500 rows and 7 columns.
#' \describe{
#' \item{id}{A character string identifier for the individual. There are two unique ids, representing two individuals.}
#' \item{V1-V6}{These columns represent six different variables in the time series data.}
#' }
#' @source Simulated using the [graphicalVAR::graphicalVARsim()] function.
#' @source Simulated using the \code{\link[graphicalVAR]{graphicalVARsim}} function in the \code{graphicalVAR} package.
#'
#' @usage data(ts_data)
#'
Expand All @@ -28,19 +28,19 @@
#' Example Posterior Samples
#'
#' This dataset contains posterior samples of beta coefficients and partial correlations for two individuals.
#' It was generated by fitting a GVAR model using [stan_gvar()] with three variables from the [ts_data] dataset.
#' It was generated by fitting a GVAR model using \code{\link{stan_gvar}} with three variables from the \code{\link{ts_data}} dataset.
#'
#' @format ## `fit_data`
#' A list with two elements, each containing posterior samples for one individual.
#'
#' @usage data(fit_data)
#'
#' @source The data is generated using the [stan_gvar()] function on subsets
#' of the [ts_data] time series data.
#' @source The data is generated using the \code{\link{stan_gvar}} function on subsets
#' of the \code{\link{ts_data}} time series data.
#'
#' @details
#' The list contains two elements, each containing posterior samples for one individual.
#' The samples were extracted using the [stan_fit_convert()] function.
#' The samples were extracted using the \code{\link{stan_fit_convert}} function.
#' For each individual, the list elements contain the posterior means of the beta coefficients
#' ("beta_mu") and the posterior means of the partial correlations ("pcor_mu").
#' The "fit" element contains all 1000 posterior samples of the beta coefficients and partial correlations.
Expand Down
Loading
Loading