seananderson / glmmfields

R package for Bayesian spatial and spatiotemporal GLMMs with possible extremes
50 stars 10 forks source link

Matern covariance calculations error #3

Closed seananderson closed 6 years ago

seananderson commented 6 years ago

There seems to be an issue with the Matern covariance calculations. I realized that the unit tests before had matern_kappa = 0.5, which internally switched to the exponential code. Maybe a matrix needs to be transposed? Not sure. I haven't dug into this yet. Example:

  gp_sigma <- 0.2
  sigma <- 0.1
  df <- 10
  gp_theta <- 1.2
  n_draws <- 4
  nknots <- 9
  matern_kappa <- 1.5
  n_data_points <- 50
  set.seed(1)

  s <- sim_glmmfields(df = df, n_draws = n_draws, gp_theta = gp_theta,
    gp_sigma = gp_sigma, sd_obs = sigma, n_knots = nknots, n_data_points = n_data_points,
    covariance = "matern", matern_kappa = matern_kappa)

  m <- glmmfields(y ~ 1, data = s$dat, time = "time",
    lat = "lat", lon = "lon", nknots = nknots,
    iter = 1, chains = 1,
    estimate_df = FALSE, fixed_df_value = df,
    covariance = "matern", matern_kappa = matern_kappa)

# > Unrecoverable error evaluating the log probability at the initial value.
# > Exception: multiply: Columns of m1 (9) and Rows of m2 (50) must match 
# > in size  Found before start of program.

That example is pushed as a unit test here: https://github.com/seananderson/glmmfields/commit/d6f94d92653a3f56cc96f7e6926e938438997583

ericward-noaa commented 6 years ago

This is just a multiplication error. Fixed by replacing '' with '.'