diff --git a/R/RcppExports.R b/R/RcppExports.R index c4aa2645..176f97a5 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -101,10 +101,6 @@ R_milstein <- function(x0, L, t, theta, drift_pntr, diffusion_pntr, ddiffusion_p .Call('_bssm_R_milstein', PACKAGE = 'bssm', x0, L, t, theta, drift_pntr, diffusion_pntr, ddiffusion_pntr, positive, seed) } -R_milstein_joint <- function(x0, L_c, L_f, t, theta, drift_pntr, diffusion_pntr, ddiffusion_pntr, positive, seed) { - .Call('_bssm_R_milstein_joint', PACKAGE = 'bssm', x0, L_c, L_f, t, theta, drift_pntr, diffusion_pntr, ddiffusion_pntr, positive, seed) -} - suggest_n_nongaussian <- function(model_, theta, candidates, replications, seed, model_type) { .Call('_bssm_suggest_n_nongaussian', PACKAGE = 'bssm', model_, theta, candidates, replications, seed, model_type) } diff --git a/man/logLik.nongaussian.Rd b/man/logLik.nongaussian.Rd new file mode 100644 index 00000000..cae97503 --- /dev/null +++ b/man/logLik.nongaussian.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/loglik.R +\name{logLik.nongaussian} +\alias{logLik.nongaussian} +\title{Log-likelihood of a Non-Gaussian State Space Model} +\usage{ +\method{logLik}{nongaussian}( + object, + particles, + method = "psi", + max_iter = 100, + conv_tol = 1e-08, + seed = sample(.Machine$integer.max, size = 1), + ... +) +} +\arguments{ +\item{object}{Model model.} + +\item{particles}{Number of samples for particle filter or importance sampling. If 0, +approximate log-likelihood based on the Gaussian approximation is returned.} + +\item{method}{Sampling method, default is psi-auxiliary filter (\code{"psi"}), +other choices are \code{"bsf"} bootstrap particle filter, and \code{"spdk"}, +which uses the importance sampling approach by Shephard and Pitt (1997) and +Durbin and Koopman (1997).} + +\item{max_iter}{Maximum number of iterations for Gaussian approximation algorithm.} + +\item{conv_tol}{Tolerance parameter for the approximation algorithm.} + +\item{seed}{Seed for the random number generator.} + +\item{...}{Ignored.} +} +\description{ +Computes the log-likelihood of a non-Gaussian state space model of \code{bssm} package. +} +\examples{ +model <- ssm_ung(y = c(1,4,3), Z = 1, T = 1, R = 0.5, P1 = 2, + distribution = "poisson") + +model2 <- bsm_ng(y = c(1,4,3), sd_level = 0.5, P1 = 2, + distribution = "poisson") +logLik(model, particles = 0) +logLik(model2, particles = 0) +logLik(model, particles = 10, seed = 1) +logLik(model2, particles = 10, seed = 1) +} diff --git a/man/priors.Rd b/man/priors.Rd index f981d8ff..b4a42999 100644 --- a/man/priors.Rd +++ b/man/priors.Rd @@ -41,5 +41,13 @@ object of class \code{bssm_prior}. These simple objects of class \code{bssm_prior} are used to construct a prior distributions for the MCMC runs of \code{bssm} package. Currently supported priors are uniform (\code{uniform()}), half-normal (\code{halfnormal()}), normal (\code{normal()}), gamma (\code{gamma}), and -truncated normal distribution (\code{tnormal()}). +truncated normal distribution (\code{tnormal()}).All parameters are vectorized so +for regression coefficient vector beta you can define prior for example +as \code{normal(0, 0, c(10, 20))}. +} +\examples{ +# create uniform prior on [-1, 1] for one parameter with initial value 0.2: +uniform(0.2, -1, 1) +# two normal priors at once i.e. for coefficients beta: +normal(init = c(0.1, 2), mean = 0, sd = c(1, 2)) } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index b5ce1906..355b1de9 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -633,26 +633,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// R_milstein_joint -double R_milstein_joint(const double x0, const unsigned int L_c, const unsigned int L_f, const double t, const arma::vec& theta, SEXP drift_pntr, SEXP diffusion_pntr, SEXP ddiffusion_pntr, bool positive, const unsigned int seed); -RcppExport SEXP _bssm_R_milstein_joint(SEXP x0SEXP, SEXP L_cSEXP, SEXP L_fSEXP, SEXP tSEXP, SEXP thetaSEXP, SEXP drift_pntrSEXP, SEXP diffusion_pntrSEXP, SEXP ddiffusion_pntrSEXP, SEXP positiveSEXP, SEXP seedSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const double >::type x0(x0SEXP); - Rcpp::traits::input_parameter< const unsigned int >::type L_c(L_cSEXP); - Rcpp::traits::input_parameter< const unsigned int >::type L_f(L_fSEXP); - Rcpp::traits::input_parameter< const double >::type t(tSEXP); - Rcpp::traits::input_parameter< const arma::vec& >::type theta(thetaSEXP); - Rcpp::traits::input_parameter< SEXP >::type drift_pntr(drift_pntrSEXP); - Rcpp::traits::input_parameter< SEXP >::type diffusion_pntr(diffusion_pntrSEXP); - Rcpp::traits::input_parameter< SEXP >::type ddiffusion_pntr(ddiffusion_pntrSEXP); - Rcpp::traits::input_parameter< bool >::type positive(positiveSEXP); - Rcpp::traits::input_parameter< const unsigned int >::type seed(seedSEXP); - rcpp_result_gen = Rcpp::wrap(R_milstein_joint(x0, L_c, L_f, t, theta, drift_pntr, diffusion_pntr, ddiffusion_pntr, positive, seed)); - return rcpp_result_gen; -END_RCPP -} // suggest_n_nongaussian arma::vec suggest_n_nongaussian(const Rcpp::List model_, const arma::vec theta, const arma::vec candidates, const unsigned int replications, const unsigned int seed, const int model_type); RcppExport SEXP _bssm_suggest_n_nongaussian(SEXP model_SEXP, SEXP thetaSEXP, SEXP candidatesSEXP, SEXP replicationsSEXP, SEXP seedSEXP, SEXP model_typeSEXP) { @@ -1303,7 +1283,6 @@ static const R_CallMethodDef CallEntries[] = { {"_bssm_nonlinear_ekf_mcmc", (DL_FUNC) &_bssm_nonlinear_ekf_mcmc, 27}, {"_bssm_nonlinear_is_mcmc", (DL_FUNC) &_bssm_nonlinear_is_mcmc, 33}, {"_bssm_R_milstein", (DL_FUNC) &_bssm_R_milstein, 9}, - {"_bssm_R_milstein_joint", (DL_FUNC) &_bssm_R_milstein_joint, 10}, {"_bssm_suggest_n_nongaussian", (DL_FUNC) &_bssm_suggest_n_nongaussian, 6}, {"_bssm_suggest_n_nonlinear", (DL_FUNC) &_bssm_suggest_n_nonlinear, 20}, {"_bssm_postcorrection_nongaussian", (DL_FUNC) &_bssm_postcorrection_nongaussian, 10}, diff --git a/vignettes/sde_model.Rmd b/vignettes/sde_model.Rmd index 3f1dd887..c934d400 100644 --- a/vignettes/sde_model.Rmd +++ b/vignettes/sde_model.Rmd @@ -43,7 +43,7 @@ where $B_t$ is a Brownian motion and where $\mu$ and $\sigma$ are real valued fu ## Example -Discretely observed latent diffusion models can be constructed using the `ssm_sde` function, which takes pointers to `C++` functions defining the drift, diffusion, the derivative of the diffusion function, and the log-densities of the observations and the prior. As an example, let us consider an Ornstein–Uhlenbeck process +Discretely observed latent diffusion models can be constructed using the `ssm_sde` function, which takes pointers to `C++` functions defining the drift, diffusion, the derivative of the diffusion function, the log-densities of the observations, and the log-prior. As an example, let us consider an Ornstein–Uhlenbeck process $$ \textrm{d} \alpha_t = \rho (\nu - \alpha_t) \textrm{d} t + \sigma \textrm{d} B_t, $$