R/init-vars.R

Defines functions init.vars

Documented in init.vars

init.vars <- function(model, debug = FALSE)
{
  if (is.null(model@sgfc)) {
    xreg <- stsm.sgf(model, gradient = FALSE, hessian = FALSE,
      deriv.transPars = FALSE)$constants
  } else
    xreg <- model@sgfc

  if (is.null(model@ssd)) {
    pg <- Mod(fft(model@diffy))^2 / (2 * pi * length(model@diffy))
  } else pg <- model@ssd

  y <- 2 * pi * pg

  fit <- lm.fit(x = xreg, y = y)
  vars <- coef(fit)

  if (debug)
  {
    stopifnot(all.equal(coef(lm(y ~ 0 + xreg)), vars, 
      check.attributes = FALSE))
  }

  if (!is.null(model@transPars))
  {
    msg <- paste("variance parameters are not reparameterized ", 
    "according to 'model@transPars' = '", model@transPars, "'.", sep = "")
    warning(msg)
  }

  return(list(vars = vars, fit = fit))
}

Try the stsm package in your browser

Any scripts or data that you put into this service are public.

stsm documentation built on May 2, 2019, 7:39 a.m.