Skip to content

Commit cada0df

Browse files
authored
Merge pull request #7 from atsa-es/marxss2
fixed to pass RCMD check
2 parents bdc6d4f + 74c46ce commit cada0df

File tree

14 files changed

+122
-82
lines changed

14 files changed

+122
-82
lines changed

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ Description: Work on TMB files to fit MARSS models with TMB.
1313
URL: https://atsa-es.github.io/marssTMB, https://github.com/atsa-es/marssTMB
1414
BugReports: https://github.com/atsa-es/marssTMB/issues
1515
License: GPL (>= 2)
16+
Depends: R (>= 3.5.0)
1617
Imports:
1718
TMB (>= 1.9.3),
1819
stats,
19-
MARSS
20+
MARSS (>= 3.11.4)
2021
Suggests:
2122
ggplot2,
23+
dplyr,
2224
tidyr,
2325
knitr,
2426
rmarkdown,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export(create.varcov.maps)
77
export(dfaTMB)
88
export(uniTMB)
99
import(MARSS)
10+
importFrom(stats,coef)
1011
useDynLib(marssTMB, .registration=TRUE); useDynLib(marssTMB_TMBExports)

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# marssTMB 0.0.7
22

33
* updated `marxss.hpp` to be in MARSS format with X and Y as mxT and nxT
4-
* added Q estimation to `marxss.hpp` (note `MARSS_tmp()` will block this until this is tested)
5-
* added C estimation to `marxss.hpp` (note `MARSS_tmp()` will block this until this is tested)
4+
* added Q estimation to `marxss.hpp` (note `MARSS_tmb()` will block this until this is tested)
5+
* added C estimation to `marxss.hpp` (note `MARSS_tmb()` will block this until this is tested)
66

77
# marssTMB 0.0.6
88

R/MARSS-TMB.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
#' * tinitx = 1 (must be)
1818
#' * (if form="dfa") m the number of states (factors). default is 1
1919
#' @param inits list of initial conditions
20+
#' @param miss.value A parameter for backcompatibility. Not used.
2021
#' @param method must be "TMB" (case sensitive)
2122
#' @param form The equation form used in the marssTMB() call. The default is "dfa".
2223
#' @param fit Whether to fit the model.
2324
#' @param silent Show TMB output when fitting
2425
#' @param control list for the optimization function. [stats::nlminb()] or [stats::optim()], `control$fun.opt` allows you to choose optim or nlminb as the optimization function. `control$optim.method` allows you to choose method for `optim()`.
26+
#' @param ... Extra parameters. Not used.
2527
#'
2628
#' @return The output list from [MARSStmb()]
2729
#' @example inst/examples/MARSS_TMB_example.R

R/MARSStmb.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#' Internal function: Parameter estimation using TMB
22
#'
3-
#' Status 5/1/23 fits model. Now working on [to_marssMLE()] to format a [MARSS::marssMLE] object.
4-
#'
53
#' Minimal error checking is done in this function.
64
#' Normal calling function is [MARSS_tmb()] which in
75
#' turn calls this function. Note when MARSS is updated, the
@@ -13,20 +11,19 @@
1311
#' * Q is fixed (not estimated)
1412
#'
1513
#' @details
16-
#' This function returns a list which is passed to [to_marssMLE()] for further
17-
#' processing.
14+
#' This function returns [MARSS::marssMLE] object. For the `iter.record` element
15+
#' of the object, the following are returned as a list:
1816
#'
1917
#' * `obj.function` is the raw output from the [TMB::MakeADFun()] call.
2018
#' * `opt.output` is the raw output from the optimization call (optim or nlminb)
21-
#' * `MLEobj` is the unfitted (no par element) [MARSS::marssMLE] object. Has all the parameters and correct structure.
2219
#'
2320
#'
2421
#' @param MLEobj A properly formatted MARSS model as output by [MARSS_tmb()]
2522

2623
#' @return A [MARSS::marssMLE] object
27-
#' @example inst/examples/dfa_example.R
24+
#' @example inst/examples/MARSStmb_example.R
2825
#' @author Eli Holmes. This function is inspired by dfaTMB.R written by Tim Cline while a graduate student in the Fish 507 Time Series Analysis course.
29-
#' @seealso [MARSS::MARSSoptim()], [MARSS::MARSSkem()], [to_marssMLE()]
26+
#' @seealso [MARSS::MARSSoptim()], [MARSS::MARSSkem()]
3027
#' @export
3128
MARSStmb <- function(MLEobj) {
3229
pkg <- "MARSStmb"

R/dfaTMB.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#' Tim Cline's original code to Fit a DFA model with TMB.
22
#'
33
#' This can be called to fit a DFA with his syntax, but generally no work should be done here.
4+
#'
5+
#' @details
6+
#' The control defaults for [stats::nlminb()] are `iter.max = 2000` and `eval.max = 2000`.
7+
#' For [stats::optim()], the defaults are `reltol = 1e-12` and `maxit = 2000`.
8+
#'
49
#'
510
#' @param y Vector of observations n x T.
611
#' @param model list with
@@ -16,8 +21,8 @@
1621
#' @param silent Show TMB output when fitting, defaults to TRUE
1722
#' @param fun.opt function to use for optimization: `stats::nlminb()` or `stats::optim()`
1823
#' @param method to pass to optim call; ignored for `fun="nlminb"`
19-
#' @param form The equation form used in the marssTMB() call. The default is "dfa".
20-
24+
#' @param form The equation form used in the marssTMB() call. The default is "dfa".
25+
#' @param control a list with the control settings for the optimatization function. See details for the defaults.
2126
#' @return A list with Optimization, Estimates, Fits, and AIC
2227
#' @example inst/examples/dfa_example.R
2328
#' @author Tim Cline wrote most of this while a graduate student in the Fish 507 Time Series Analysis course. Eli Holmes later modified it to replicate the MARSS(x, form="dfa") model.
@@ -146,10 +151,9 @@ dfaTMB <- function(y,
146151
}
147152
pl1 <- obj1$env$parList() # This contains all of your parameter estimates RAW as they come out of the optimizer
148153
if (EstSE) {
149-
sdr <- sdreport(obj1)
154+
sdr <- TMB::sdreport(obj1)
150155
}
151156

152-
# ScaleFac<-as.vector(apply(pl1$u,2,FUN=sd))
153157
# pl1$u<-t(t(pl1$u)/ScaleFac)
154158
# pl1$Z<-t(t(pl1$Z)*ScaleFac)
155159

@@ -176,6 +180,8 @@ dfaTMB <- function(y,
176180

177181
# Standard Errors for parameters
178182
if (EstSE) {
183+
# ScaleFac<-as.vector(apply(pl1$u,2,FUN=sd))
184+
ScaleFac <- 1
179185
SES <- list(
180186
D = sdr$sd[which(names(sdr$value) == "D")],
181187
Z = sdr$sd[which(names(sdr$value) == "Z")] * ScaleFac,

R/marssTMB-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#' @rawNamespace useDynLib(marssTMB, .registration=TRUE); useDynLib(marssTMB_TMBExports)
22
#' @import MARSS
3+
#' @importFrom stats coef
34
#' @keywords internal
45
"_PACKAGE"
56

inst/examples/MARSS_TMB_example.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ dat <- as.data.frame(lakeWAplanktonTrans) |>
88
MARSS::zscore()
99

1010
#fit with MARSS
11-
fit <- MARSS_tmb(dat, model=list(m=3))
11+
fit <- MARSS_tmb(dat, model=list(m=3, tinitx=1), form="dfa")

inst/examples/MARSStmb_example.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library(MARSS)
2+
data(lakeWAplankton, package = "MARSS")
3+
phytoplankton <- c("Cryptomonas", "Diatoms", "Greens", "Unicells", "Other.algae")
4+
dat <- as.data.frame(lakeWAplanktonTrans) |>
5+
subset(Year >= 1980 & Year <= 1989) |>
6+
subset(select=phytoplankton) |>
7+
t() |>
8+
MARSS::zscore()
9+
10+
# set-up the model
11+
mod <- MARSS_tmb(dat, model=list(m=3, tinitx=1), form="dfa", fit=FALSE)
12+
# fit
13+
fit <- MARSStmb(mod)
14+

man/MARSS_tmb.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)