diff --git a/NAMESPACE b/NAMESPACE index 901ba0d..3bf7b68 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(cAIC) export(classify_variables) export(convert_equations) export(dsem) +export(dsemRTMB) export(dsem_control) export(list_parameters) export(loo_residuals) @@ -59,3 +60,6 @@ importFrom(stats,simulate) importFrom(stats,time) importFrom(stats,vcov) useDynLib(dsem, .registration = TRUE) + +# Edited by hand +import("RTMB") \ No newline at end of file diff --git a/R/compute_nll.R b/R/compute_nll.R index 1ab4131..d2eafab 100644 --- a/R/compute_nll.R +++ b/R/compute_nll.R @@ -72,9 +72,6 @@ function( parlist, # Hadamard squared LU-decomposition # See: https://eigen.tuxfamily.org/dox/group__QuickRefPage.html squared_invIminusRho_kk = invIminusRho_kk - #print(class(squared_invIminusRho_kk)) - #print(invIminusRho_kk) - #REPORT( invIminusRho_kk ) squared_invIminusRho_kk@x = squared_invIminusRho_kk@x^2 if( options[2] == 1 ){ diff --git a/R/dsemRTMB.R b/R/dsemRTMB.R index c2931d8..a1dea78 100644 --- a/R/dsemRTMB.R +++ b/R/dsemRTMB.R @@ -1,5 +1,23 @@ - - +#' @title Fit dynamic structural equation model +#' +#' @description Fits a dynamic structural equation model +#' +#' @inheritParams dsem +#' +#' @param log_prior A user-provided function that takes as input the list of +#' parameters \code{out$obj$env$parList()} where \code{out} is the output from +#' \code{dsemRTMB()}, and returns the log-prior probability. For example +#' \code{log_prior = function(p) dnorm( p$beta_z[1], mean=0, sd=0.1, log=TRUE)} +#' specifies a normal prior probability for the first path coefficient +#' with mean of zero and sd of 0.1 +#' +#' @details +#' See \code{\link{dsem}} for details +#' +#' @return +#' An object (list) of class `dsem`, fitted using RTMB +#' +#' @export dsemRTMB <- function( sem, tsdata, diff --git a/R/read_model.R b/R/read_model.R index c0a44b2..f992401 100644 --- a/R/read_model.R +++ b/R/read_model.R @@ -10,10 +10,7 @@ #' @param quiet Boolean indicating whether to print messages to terminal #' #' @details -#' \strong{RAM specification using arrow-and-lag notation} -#' -#' -#' @export +#' See \code{\link{make_dsem_ram.R}} for details read_model <- function( sem, times, diff --git a/man/dsemRTMB.Rd b/man/dsemRTMB.Rd new file mode 100644 index 0000000..929b193 --- /dev/null +++ b/man/dsemRTMB.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dsemRTMB.R +\name{dsemRTMB} +\alias{dsemRTMB} +\title{Fit dynamic structural equation model} +\usage{ +dsemRTMB( + sem, + tsdata, + family = rep("fixed", ncol(tsdata)), + estimate_delta0 = FALSE, + log_prior = function(p) 0, + control = dsem_control(), + covs = colnames(tsdata) +) +} +\arguments{ +\item{sem}{Specification for time-series structural equation model structure +including lagged or simultaneous effects. See Details section in +\code{\link[dsem]{make_dsem_ram}} for more description} + +\item{tsdata}{time-series data, as outputted using \code{\link[stats]{ts}}} + +\item{family}{Character-vector listing the distribution used for each column of \code{tsdata}, where +each element must be \code{fixed} or \code{normal}. +\code{family="fixed"} is default behavior and assumes that a given variable is measured exactly. +Other options correspond to different specifications of measurement error.} + +\item{estimate_delta0}{Boolean indicating whether to estimate deviations from equilibrium in initial year +as fixed effects, or alternatively to assume that dynamics start at some stochastic draw away from +the stationary distribution} + +\item{log_prior}{A user-provided function that takes as input the list of +parameters \code{out$obj$env$parList()} where \code{out} is the output from +\code{dsemRTMB()}, and returns the log-prior probability. For example +\code{log_prior = function(p) dnorm( p$beta_z[1], mean=0, sd=0.1, log=TRUE)} +specifies a normal prior probability for the first path coefficient +with mean of zero and sd of 0.1} + +\item{control}{Output from \code{\link{dsem_control}}, used to define user +settings, and see documentation for that function for details.} + +\item{covs}{optional: a character vector of one or more elements, with each element giving a string of variable +names, separated by commas. Variances and covariances among all variables in each such string are +added to the model. Warning: covs="x1, x2" and covs=c("x1", "x2") are not equivalent: +covs="x1, x2" specifies the variance of x1, the variance of x2, and their covariance, +while covs=c("x1", "x2") specifies the variance of x1 and the variance of x2 but not their covariance. +These same covariances can be added manually via argument `sem`, but using argument `covs` might +save time for models with many variables.} +} +\value{ +An object (list) of class `dsem`, fitted using RTMB +} +\description{ +Fits a dynamic structural equation model +} +\details{ +See \code{\link{dsem}} for details +} diff --git a/man/read_model.Rd b/man/read_model.Rd new file mode 100644 index 0000000..66e27dd --- /dev/null +++ b/man/read_model.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read_model.R +\name{read_model} +\alias{read_model} +\title{Make a RAM (Reticular Action Model)} +\usage{ +read_model(sem, times, variables, covs = NULL, quiet = FALSE) +} +\arguments{ +\item{sem}{Specification for time-series structural equation model structure +including lagged or simultaneous effects. See Details section in +\code{\link[dsem]{make_dsem_ram}} for more description} + +\item{times}{A character vector listing the set of times in order} + +\item{variables}{A character vector listing the set of variables} + +\item{covs}{A character vector listing variables for which to estimate a standard deviation} + +\item{quiet}{Boolean indicating whether to print messages to terminal} +} +\description{ +\code{read_model} converts SEM arrow notation to \code{model} describing SEM parameters +} +\details{ +\strong{RAM specification using arrow-and-lag notation} +}