Skip to content

Commit

Permalink
new parameters to docs, test vignette output on package site
Browse files Browse the repository at this point in the history
  • Loading branch information
santikka committed May 30, 2024
1 parent 1386a91 commit 2a71175
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions R/as_data_frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' * `delta`\cr Time-varying regression coefficients.
#' * `nu`\cr Group-level random effects.
#' * `lambda`\cr Factor loadings.
#' * `kappa`\cr Contribution of the latent factor loadings in the total
#' variation.
#' * `psi`\cr Latent factors.
#' * `tau`\cr Standard deviations of the spline coefficients of `delta`.
#' * `tau_alpha`\cr Standard deviations of the spline coefficients of
Expand Down Expand Up @@ -42,6 +44,8 @@
#' in case of `nonzero_lambda = FALSE`, mean of these are used to flip the
#' sign of `psi` to avoid multimodality due to sign-switching, but
#' `omega_psi` variables are not modified.
#' * `zeta`\cr Total variation of latent factors, i.e., the sum
#' of `sigma_lambda` and `tau_psi`.
#'
#' @export
#' @family output
Expand Down
4 changes: 4 additions & 0 deletions R/as_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -639,21 +639,25 @@ as_data_table_lambda <- function(x, draws, n_draws, response, ...) {
as_data_table_sigma_lambda <- function(draws, response, ...) {
as_data_table_default("sigma_lambda", draws, response)
}

#' @describeIn as_data_table_default Data Table for a "tau_psi" Parameter
#' @noRd
as_data_table_tau_psi <- function(draws, response, ...) {
as_data_table_default("tau_psi", draws, response)
}

#' @describeIn as_data_table_default Data Table for a "kappa" Parameter
#' @noRd
as_data_table_kappa <- function(draws, response, ...) {
as_data_table_default("kappa", draws, response)
}

#' @describeIn as_data_table_default Data Table for a "zeta" Parameter
#' @noRd
as_data_table_zeta <- function(draws, response, ...) {
as_data_table_default("zeta", draws, response)
}

#' @describeIn as_data_table_default Data Table for a "psi" Parameter
#' @noRd
as_data_table_psi <- function(x, draws, n_draws, response,
Expand Down
2 changes: 1 addition & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ topological_order <- function(A) {
#'
#' @param message See [cli::cli_abort()].
#' @param ... See [cli::cli_abort()].
#' @param call See See [cli::cli_abort()].
#' @param call See [cli::cli_abort()].
#' @noRd
stop_ <- function(message, ..., call = rlang::caller_env()) {
cli::cli_abort(message, ..., .envir = parent.frame(), call = call)
Expand Down
4 changes: 4 additions & 0 deletions man/as.data.frame.dynamitefit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vignettes/dynamite.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ seatbelt_formula <-

Next, we fit the model

```{r seatbeltmodelfit, echo=TRUE, eval=TRUE, message=FALSE}
```{r seatbeltmodelfit, echo=TRUE, eval=TRUE, message=FALSE, error=FALSE, warning=FALSE}
fit <- dynamite(
dformula = seatbelt_formula,
data = seatbelt, time = "year", group = "state",
Expand Down Expand Up @@ -282,7 +282,7 @@ Here, the `aux()` function creates a deterministic transformation of \(p_t\) def

![(#fig:multichanneldag) A directed acyclic graph for the multichannel model with arrows corresponding to the assumed direct causal effects. A cross-section at times \(t\), \(t+1\), and \(t+2\) is shown. The vertices and edges corresponding to the deterministic tranformation \(\log(p_t)\) are omitted for clarity.](dag.png){width=80%}

```{r multichannelfit, echo=TRUE, eval=TRUE, message=FALSE}
```{r multichannelfit, echo=TRUE, eval=TRUE, message=FALSE, error=FALSE, warning=FALSE}
multichannel_fit <- dynamite(
dformula = multi_formula,
data = multichannel_example, time = "time", group = "id",
Expand Down
7 changes: 4 additions & 3 deletions vignettes/dynamite_custom.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ to_vector(nu_raw) ~ student_t(df, 0, 1);
```
and add `real<lower=2> df;` to the parameters block. Now we can call the `dynamite` with our new model code, using the `custom_stan_model` argument, which accepts either a `character` string containing the model code or a path to a `.stan` file.

```{r}
```{r customfit, message=FALSE, error=FALSE, warning=FALSE}
fit <- dynamite(
dformula = f, data = gaussian_example, time = "time", group = "id",
custom_stan_model = "custom_code.stan", chains = 1, refresh = 0
Expand Down Expand Up @@ -107,7 +107,7 @@ d <- get_data(fit)

Like `get_code()`, this method is available for both `dynamiteformula` and `dynamitefit` objects. With the custom code and the corresponding input data, we can call the variational algorithm of `rstan`:

```{r}
```{r vbfit, message=FALSE, error=FALSE, warning=FALSE}
model <- rstan::stan_model("custom_code.stan")
fit_vb <- rstan::vb(model, data = d, iter = 1e5, refresh = 0)
```
Expand All @@ -123,7 +123,8 @@ Now the methods for `dynamitefit` objects such as `summary()` and `predict()` wo

```{r}
summary(fit_vb_dynamite, types = "beta")
```
```{r}
pp2 <- predict(
fit_vb_dynamite, newdata = newdata, new_levels = "original", n_draws = 50
)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/dynamite_simulation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ init <- list(

We fit the model with these fixed values.

```{r gaussianfit}
```{r gaussianfit, message=FALSE, error=FALSE, warning=FALSE}
gaussian_simulation_fit <- dynamite(
dformula = f,
data = d,
Expand Down

0 comments on commit 2a71175

Please sign in to comment.