Skip to content

Commit

Permalink
vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-ward committed Feb 2, 2021
1 parent 57da549 commit c8cd4da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions R/fit_stan.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param mcmc_list A list of MCMC control parameters. These include the number of 'iterations' (default = 1000), burn in or warmup (default = 500), chains (default = 3), and thinning (default = 1)
#' @param family A named distribution for the observation model, defaults to gaussian
#' @param marss A named list containing the following elements for specifying marss models: (states=NULL, obsVariances=NULL, proVariances=NULL, trends=NULL)
#'
#' @param ... Any other arguments passed to [rstan::sampling()].
#' @return an object of class 'rstan'
#' @importFrom rstan sampling
#' @export
Expand Down Expand Up @@ -49,13 +49,13 @@ fit_stan <- function(y, x=NA, model_name = NA,

data <- NA
if(model_name == "regression") {
if(class(x)!="matrix") x = matrix(x,ncol=1)
if(is.matrix(x)==FALSE) x = matrix(x,ncol=1)
object <- stanmodels$regression
data <- list("N"=length(y),"K"=dim(x)[2],"x"=x,"y"=y,"y_int"=round(y), "family"=family)
pars <- c("beta","sigma","pred","log_lik")
}
if(model_name == "regression_cor") {
if(class(x)!="matrix") x = matrix(x,ncol=1)
if(is.matrix(x)==FALSE) x = matrix(x,ncol=1)
object <- stanmodels$regression_cor
data <- list("N"=length(y),"K"=dim(x)[2],"x"=x,"y"=y,"y_int"=round(y), "family"=family)
pars <- c("beta","sigma","pred","phi","sigma_cor","log_lik")
Expand Down Expand Up @@ -126,21 +126,21 @@ fit_stan <- function(y, x=NA, model_name = NA,
if(is.na(x)) {
x <- matrix(0, nrow=length(y), ncol=1)
}
if(class(x)!="matrix") x <- matrix(x,ncol=1)
if(is.matrix(x)==FALSE) x <- matrix(x,ncol=1)
data <- list("N"=length(y),"K"=dim(x)[2],"x"=x,"y"=y,"y_int"=round(y), "family"=family,"n_pos"=n_pos,"pos_indx"=pos_indx)
pars <- c("beta","sigma_obs","sigma_process","pred","intercept","log_lik")
}
if(model_name == "dlm-slope") {
object = stanmodels$dlm_slope
# constant estimated intercept, and time varying slopes
if(class(x)!="matrix") x <- matrix(x,ncol=1)
if(is.matrix(x)==FALSE) x <- matrix(x,ncol=1)
data <- list("N"=length(y),"K"=dim(x)[2],"x"=x,"y"=y,"y_int"=round(y), "family"=family,"n_pos"=n_pos,"pos_indx"=pos_indx)
pars <- c("beta","sigma_obs","sigma_process","pred","log_lik")
}
if(model_name == "dlm") {
object = stanmodels$dlm
# this is just a time-varying model with time varying intercept and slopes
if(class(x)!="matrix") x <- matrix(x,ncol=1)
if(is.matrix(x)==FALSE) x <- matrix(x,ncol=1)
data <- list("N"=length(y),"K"=dim(x)[2],"x"=x,"y"=y,"y_int"=round(y), "family"=family,"n_pos"=n_pos,"pos_indx"=pos_indx)
pars <- c("beta","sigma_obs","sigma_process","pred","log_lik")
}
Expand Down
3 changes: 2 additions & 1 deletion vignettes/dlm.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ knitr::opts_chunk$set(echo = TRUE)
```{r install, eval=TRUE, warning=FALSE, message=FALSE, results='hide'}
library(rstan)
library(atsar)
library(MARSS)
# for optimizing stan on your machine,
#rstan_options(auto_write = TRUE)
#options(mc.cores = parallel::detectCores())
Expand All @@ -30,6 +30,7 @@ mcmc_list = list(n_mcmc = 1000, n_burn = 500, n_chain = 1, n_thin = 1)
We'll use the same data in the MARSS manual, from Mark's example in the Columbia River. The data are accessed with

```{r,eval=FALSE}
library(MARSS)
data(SalmonSurvCUI)
```

Expand Down

0 comments on commit c8cd4da

Please sign in to comment.