#' Test of cross-validation approach using missing data in Stan

loo_test_sets <- create_folds(mw, type = "LOO")
sloo_test_sets <- create_folds(mw, type = "SLOO")

#' What do the test sets look like?
cowplot::plot_grid(
  plotlist = lapply(loo_test_sets, function(x) {
    x$data %>%
      ggplot(aes(fill = y)) +
        geom_sf() +
        theme_void() +
        theme(
          legend.position = "none"
        )
  }),
  ncol = 7
)

cowplot::plot_grid(
  plotlist = lapply(sloo_test_sets, function(x) {
    x$data %>%
      ggplot(aes(fill = y)) +
      geom_sf() +
      theme_void() +
      theme(
        legend.position = "none"
      )
  }),
  ncol = 7
)

#' Try fitting one of them in Stan
sf <- loo_test_sets[[1]]$data

#' Index of observations which are not missing
ii_obs <- which(!is.na(sf$y))

#' Index of missing observations
ii_mis <- which(is.na(sf$y))

#' Number of not missing observations
n_obs <- length(ii_obs)

#' Number of missing observations
n_mis <- length(ii_mis)

dat <- list(
  n_obs = n_obs,
  n_mis = n_mis,
  ii_obs = array(ii_obs),
  ii_mis = array(ii_mis),
  n = nrow(sf),
  y_obs = sf$y[ii_obs],
  m = sf$n_obs
)

temp <- rstan::stan(file = "constant.stan", data = dat, warmup = 100, iter = 900)
## 
## SAMPLING FOR MODEL 'constant' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 5.7e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.57 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1: 
## Chain 1: 
## Chain 1: WARNING: There aren't enough warmup iterations to fit the
## Chain 1:          three stages of adaptation as currently configured.
## Chain 1:          Reducing each adaptation stage to 15%/75%/10% of
## Chain 1:          the given number of warmup iterations:
## Chain 1:            init_buffer = 15
## Chain 1:            adapt_window = 75
## Chain 1:            term_buffer = 10
## Chain 1: 
## Chain 1: Iteration:   1 / 900 [  0%]  (Warmup)
## Chain 1: Iteration:  90 / 900 [ 10%]  (Warmup)
## Chain 1: Iteration: 101 / 900 [ 11%]  (Sampling)
## Chain 1: Iteration: 190 / 900 [ 21%]  (Sampling)
## Chain 1: Iteration: 280 / 900 [ 31%]  (Sampling)
## Chain 1: Iteration: 370 / 900 [ 41%]  (Sampling)
## Chain 1: Iteration: 460 / 900 [ 51%]  (Sampling)
## Chain 1: Iteration: 550 / 900 [ 61%]  (Sampling)
## Chain 1: Iteration: 640 / 900 [ 71%]  (Sampling)
## Chain 1: Iteration: 730 / 900 [ 81%]  (Sampling)
## Chain 1: Iteration: 820 / 900 [ 91%]  (Sampling)
## Chain 1: Iteration: 900 / 900 [100%]  (Sampling)
## Chain 1: 
## Chain 1:  Elapsed Time: 0.025817 seconds (Warm-up)
## Chain 1:                0.190944 seconds (Sampling)
## Chain 1:                0.216761 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'constant' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 4.5e-05 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.45 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2: 
## Chain 2: 
## Chain 2: WARNING: There aren't enough warmup iterations to fit the
## Chain 2:          three stages of adaptation as currently configured.
## Chain 2:          Reducing each adaptation stage to 15%/75%/10% of
## Chain 2:          the given number of warmup iterations:
## Chain 2:            init_buffer = 15
## Chain 2:            adapt_window = 75
## Chain 2:            term_buffer = 10
## Chain 2: 
## Chain 2: Iteration:   1 / 900 [  0%]  (Warmup)
## Chain 2: Iteration:  90 / 900 [ 10%]  (Warmup)
## Chain 2: Iteration: 101 / 900 [ 11%]  (Sampling)
## Chain 2: Iteration: 190 / 900 [ 21%]  (Sampling)
## Chain 2: Iteration: 280 / 900 [ 31%]  (Sampling)
## Chain 2: Iteration: 370 / 900 [ 41%]  (Sampling)
## Chain 2: Iteration: 460 / 900 [ 51%]  (Sampling)
## Chain 2: Iteration: 550 / 900 [ 61%]  (Sampling)
## Chain 2: Iteration: 640 / 900 [ 71%]  (Sampling)
## Chain 2: Iteration: 730 / 900 [ 81%]  (Sampling)
## Chain 2: Iteration: 820 / 900 [ 91%]  (Sampling)
## Chain 2: Iteration: 900 / 900 [100%]  (Sampling)
## Chain 2: 
## Chain 2:  Elapsed Time: 0.026944 seconds (Warm-up)
## Chain 2:                0.173533 seconds (Sampling)
## Chain 2:                0.200477 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'constant' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 2.9e-05 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.29 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3: 
## Chain 3: 
## Chain 3: WARNING: There aren't enough warmup iterations to fit the
## Chain 3:          three stages of adaptation as currently configured.
## Chain 3:          Reducing each adaptation stage to 15%/75%/10% of
## Chain 3:          the given number of warmup iterations:
## Chain 3:            init_buffer = 15
## Chain 3:            adapt_window = 75
## Chain 3:            term_buffer = 10
## Chain 3: 
## Chain 3: Iteration:   1 / 900 [  0%]  (Warmup)
## Chain 3: Iteration:  90 / 900 [ 10%]  (Warmup)
## Chain 3: Iteration: 101 / 900 [ 11%]  (Sampling)
## Chain 3: Iteration: 190 / 900 [ 21%]  (Sampling)
## Chain 3: Iteration: 280 / 900 [ 31%]  (Sampling)
## Chain 3: Iteration: 370 / 900 [ 41%]  (Sampling)
## Chain 3: Iteration: 460 / 900 [ 51%]  (Sampling)
## Chain 3: Iteration: 550 / 900 [ 61%]  (Sampling)
## Chain 3: Iteration: 640 / 900 [ 71%]  (Sampling)
## Chain 3: Iteration: 730 / 900 [ 81%]  (Sampling)
## Chain 3: Iteration: 820 / 900 [ 91%]  (Sampling)
## Chain 3: Iteration: 900 / 900 [100%]  (Sampling)
## Chain 3: 
## Chain 3:  Elapsed Time: 0.028453 seconds (Warm-up)
## Chain 3:                0.182464 seconds (Sampling)
## Chain 3:                0.210917 seconds (Total)
## Chain 3: 
## 
## SAMPLING FOR MODEL 'constant' NOW (CHAIN 4).
## Chain 4: 
## Chain 4: Gradient evaluation took 2.7e-05 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.27 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4: 
## Chain 4: 
## Chain 4: WARNING: There aren't enough warmup iterations to fit the
## Chain 4:          three stages of adaptation as currently configured.
## Chain 4:          Reducing each adaptation stage to 15%/75%/10% of
## Chain 4:          the given number of warmup iterations:
## Chain 4:            init_buffer = 15
## Chain 4:            adapt_window = 75
## Chain 4:            term_buffer = 10
## Chain 4: 
## Chain 4: Iteration:   1 / 900 [  0%]  (Warmup)
## Chain 4: Iteration:  90 / 900 [ 10%]  (Warmup)
## Chain 4: Iteration: 101 / 900 [ 11%]  (Sampling)
## Chain 4: Iteration: 190 / 900 [ 21%]  (Sampling)
## Chain 4: Iteration: 280 / 900 [ 31%]  (Sampling)
## Chain 4: Iteration: 370 / 900 [ 41%]  (Sampling)
## Chain 4: Iteration: 460 / 900 [ 51%]  (Sampling)
## Chain 4: Iteration: 550 / 900 [ 61%]  (Sampling)
## Chain 4: Iteration: 640 / 900 [ 71%]  (Sampling)
## Chain 4: Iteration: 730 / 900 [ 81%]  (Sampling)
## Chain 4: Iteration: 820 / 900 [ 91%]  (Sampling)
## Chain 4: Iteration: 900 / 900 [100%]  (Sampling)
## Chain 4: 
## Chain 4:  Elapsed Time: 0.029904 seconds (Warm-up)
## Chain 4:                0.181266 seconds (Sampling)
## Chain 4:                0.21117 seconds (Total)
## Chain 4:
rstan::summary(temp)$summary
##                      mean      se_mean          sd          2.5%           25%           50%          75%
## y_mis[1]      39.32631322 2.382316e-01 5.897314232   28.54019813   35.11108349   39.03756346   43.2358606
## beta_0        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[1]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[2]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[3]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[4]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[5]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[6]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[7]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[8]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[9]        -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[10]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[11]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[12]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[13]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[14]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[15]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[16]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[17]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[18]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[19]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[20]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[21]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[22]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[23]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[24]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[25]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[26]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[27]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## eta[28]       -2.35479527 5.528449e-04 0.031133175   -2.41588845   -2.37650492   -2.35539917   -2.3332747
## y[1]          39.32631322 2.382316e-01 5.897314232   28.54019813   35.11108349   39.03756346   43.2358606
## y[2]          29.54181354 0.000000e+00 0.000000000   29.54181354   29.54181354   29.54181354   29.5418135
## y[3]          49.56848581 0.000000e+00 0.000000000   49.56848581   49.56848581   49.56848581   49.5684858
## y[4]          25.41303769 0.000000e+00 0.000000000   25.41303769   25.41303769   25.41303769   25.4130377
## y[5]          46.93140798          NaN 0.000000000   46.93140798   46.93140798   46.93140798   46.9314080
## y[6]          28.46503770 0.000000e+00 0.000000000   28.46503770   28.46503770   28.46503770   28.4650377
## y[7]          89.86246516 0.000000e+00 0.000000000   89.86246516   89.86246516   89.86246516   89.8624652
## y[8]          26.83167324 0.000000e+00 0.000000000   26.83167324   26.83167324   26.83167324   26.8316732
## y[9]          21.08982854 0.000000e+00 0.000000000   21.08982854   21.08982854   21.08982854   21.0898285
## y[10]         36.46588664 0.000000e+00 0.000000000   36.46588664   36.46588664   36.46588664   36.4658866
## y[11]         25.13650708 0.000000e+00 0.000000000   25.13650708   25.13650708   25.13650708   25.1365071
## y[12]         93.79745832 0.000000e+00 0.000000000   93.79745832   93.79745832   93.79745832   93.7974583
## y[13]         32.68935853 0.000000e+00 0.000000000   32.68935853   32.68935853   32.68935853   32.6893585
## y[14]         38.28128687 0.000000e+00 0.000000000   38.28128687   38.28128687   38.28128687   38.2812869
## y[15]         36.02050396 0.000000e+00 0.000000000   36.02050396   36.02050396   36.02050396   36.0205040
## y[16]         18.16454375 0.000000e+00 0.000000000   18.16454375   18.16454375   18.16454375   18.1645438
## y[17]         70.63350982 0.000000e+00 0.000000000   70.63350982   70.63350982   70.63350982   70.6335098
## y[18]         25.83200246 0.000000e+00 0.000000000   25.83200246   25.83200246   25.83200246   25.8320025
## y[19]         13.51610181 0.000000e+00 0.000000000   13.51610181   13.51610181   13.51610181   13.5161018
## y[20]         58.71062406 0.000000e+00 0.000000000   58.71062406   58.71062406   58.71062406   58.7106241
## y[21]         70.58567052 0.000000e+00 0.000000000   70.58567052   70.58567052   70.58567052   70.5856705
## y[22]         34.57662815 0.000000e+00 0.000000000   34.57662815   34.57662815   34.57662815   34.5766281
## y[23]         35.97166622 0.000000e+00 0.000000000   35.97166622   35.97166622   35.97166622   35.9716662
## y[24]         11.12088361 0.000000e+00 0.000000000   11.12088361   11.12088361   11.12088361   11.1208836
## y[25]         15.22465643 0.000000e+00 0.000000000   15.22465643   15.22465643   15.22465643   15.2246564
## y[26]         19.47180929 0.000000e+00 0.000000000   19.47180929   19.47180929   19.47180929   19.4718093
## y[27]         41.00921639 0.000000e+00 0.000000000   41.00921639   41.00921639   41.00921639   41.0092164
## y[28]         22.20170783 0.000000e+00 0.000000000   22.20170783   22.20170783   22.20170783   22.2017078
## log_lik[1]    -5.71010969 2.142435e-02 0.643429796   -7.57833227   -5.87267843   -5.45943424   -5.2934677
## log_lik[2]    -5.27796568 1.268113e-03 0.070489729   -5.45275287   -5.31676291   -5.26220246   -5.2237735
## log_lik[3]    -6.28627413 4.875740e-03 0.274902410   -6.89906216   -6.46036307   -6.25477626   -6.0833544
## log_lik[4]    -6.52186682 4.643663e-03 0.262086354   -7.08121876   -6.69407756   -6.50142040   -6.3321250
## log_lik[5]    -6.22570588 5.005546e-03 0.279842629   -6.82186354   -6.41156896   -6.21388807   -6.0236790
## log_lik[6]    -9.70496859 9.764405e-03 0.550961631  -10.84976365  -10.07399112   -9.67346549   -9.3110084
## log_lik[7]   -35.86469432 2.957595e-02 1.664159660  -39.17712263  -37.01683395  -35.88043647  -34.7055216
## log_lik[8]    -5.27375045 1.392521e-03 0.077876212   -5.46134650   -5.31872451   -5.25891326   -5.2144550
## log_lik[9]   -16.80332850 1.582082e-02 0.892301878  -18.62602609  -17.40759491  -16.76361077  -16.1704020
## log_lik[10]   -6.01794724 4.260194e-03 0.238401710   -6.52191626   -6.17714725   -6.00937361   -5.8465236
## log_lik[11]   -6.23760530 4.067554e-03 0.229562454   -6.73105156   -6.38761498   -6.21837538   -6.0708685
## log_lik[12]  -28.68020925 2.760638e-02 1.552926898  -31.78365042  -29.75307780  -28.69047280  -27.5961903
## log_lik[13]   -5.63830665 2.644377e-03 0.148909742   -5.97711008   -5.73069773   -5.61848163   -5.5274256
## log_lik[14]   -6.80685223 5.743657e-03 0.322118111   -7.47442630   -7.02477691   -6.80029601   -6.5776173
## log_lik[15]   -5.29575614 9.369281e-04 0.050098494   -5.43152119   -5.31700658   -5.27878651   -5.2584173
## log_lik[16]   -9.38215350 7.951511e-03 0.448605103  -10.30840351   -9.68387832   -9.35863089   -9.0623320
## log_lik[17]  -18.50038456 1.877916e-02 1.056067179  -20.61973323  -19.22835556  -18.50419409  -17.7615455
## log_lik[18]   -6.42553709 4.477652e-03 0.252714288   -6.96648465   -6.59121383   -6.40522169   -6.2423330
## log_lik[19]  -15.63019914 1.276867e-02 0.720092993  -17.09703566  -16.11868625  -15.59960735  -15.1200984
## log_lik[20]   -8.88927856 9.935893e-03 0.557690014  -10.03512545   -9.26858200   -8.88160380   -8.4942007
## log_lik[21]  -11.81602127 1.409051e-02 0.791562396  -13.42646422  -12.35751365  -11.81095774  -11.2581781
## log_lik[22]   -5.47119029 1.966523e-03 0.110226725   -5.73297879   -5.53614888   -5.45185715   -5.3876977
## log_lik[23]   -5.35470885 2.155052e-03 0.119037901   -5.62654711   -5.42917060   -5.34230706   -5.2657454
## log_lik[24]  -12.52775978 9.536441e-03 0.537836411  -13.62491945  -12.89228580  -12.50434656  -12.1465052
## log_lik[25]  -15.42721074 1.308762e-02 0.738107802  -16.93240784  -15.92757743  -15.39525999  -14.9040739
## log_lik[26]  -15.32940145 1.410149e-02 0.795345939  -16.95501297  -15.86781017  -15.29365428  -14.7650888
## log_lik[27]   -5.85655394 3.947006e-03 0.220355124   -6.33087746   -6.00179653   -5.84535421   -5.6966235
## log_lik[28]  -12.81016049 1.230070e-02 0.693874253  -14.23494524  -13.27851168  -12.77661765  -12.3167656
## rho[1]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[2]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[3]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[4]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[5]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[6]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[7]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[8]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[9]         0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[10]        0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[11]        0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[12]        0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[13]        0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
## rho[14]        0.08671708 4.375198e-05 0.002466054    0.08196912    0.08498195    0.08663757    0.0884044
##                     97.5%       n_eff      Rhat
## y_mis[1]      52.03921313  612.787445 1.0018539
## beta_0        -2.29342473 3171.321210 1.0006016
## eta[1]        -2.29342473 3171.321210 1.0006016
## eta[2]        -2.29342473 3171.321210 1.0006016
## eta[3]        -2.29342473 3171.321210 1.0006016
## eta[4]        -2.29342473 3171.321210 1.0006016
## eta[5]        -2.29342473 3171.321210 1.0006016
## eta[6]        -2.29342473 3171.321210 1.0006016
## eta[7]        -2.29342473 3171.321210 1.0006016
## eta[8]        -2.29342473 3171.321210 1.0006016
## eta[9]        -2.29342473 3171.321210 1.0006016
## eta[10]       -2.29342473 3171.321210 1.0006016
## eta[11]       -2.29342473 3171.321210 1.0006016
## eta[12]       -2.29342473 3171.321210 1.0006016
## eta[13]       -2.29342473 3171.321210 1.0006016
## eta[14]       -2.29342473 3171.321210 1.0006016
## eta[15]       -2.29342473 3171.321210 1.0006016
## eta[16]       -2.29342473 3171.321210 1.0006016
## eta[17]       -2.29342473 3171.321210 1.0006016
## eta[18]       -2.29342473 3171.321210 1.0006016
## eta[19]       -2.29342473 3171.321210 1.0006016
## eta[20]       -2.29342473 3171.321210 1.0006016
## eta[21]       -2.29342473 3171.321210 1.0006016
## eta[22]       -2.29342473 3171.321210 1.0006016
## eta[23]       -2.29342473 3171.321210 1.0006016
## eta[24]       -2.29342473 3171.321210 1.0006016
## eta[25]       -2.29342473 3171.321210 1.0006016
## eta[26]       -2.29342473 3171.321210 1.0006016
## eta[27]       -2.29342473 3171.321210 1.0006016
## eta[28]       -2.29342473 3171.321210 1.0006016
## y[1]          52.03921313  612.787445 1.0018539
## y[2]          29.54181354    2.003757 0.9987492
## y[3]          49.56848581    2.003757 0.9987492
## y[4]          25.41303769    2.003757 0.9987492
## y[5]          46.93140798         NaN 0.9987492
## y[6]          28.46503770    2.003757 0.9987492
## y[7]          89.86246516    2.003757 0.9987492
## y[8]          26.83167324    2.003757 0.9987492
## y[9]          21.08982854    2.003757 0.9987492
## y[10]         36.46588664    2.003757 0.9987492
## y[11]         25.13650708    2.003757 0.9987492
## y[12]         93.79745832    2.003757 0.9987492
## y[13]         32.68935853    2.003757 0.9987492
## y[14]         38.28128687    2.003757 0.9987492
## y[15]         36.02050396    2.003757 0.9987492
## y[16]         18.16454375    2.003757 0.9987492
## y[17]         70.63350982    2.003757 0.9987492
## y[18]         25.83200246    2.003757 0.9987492
## y[19]         13.51610181    2.003757 0.9987492
## y[20]         58.71062406    2.003757 0.9987492
## y[21]         70.58567052    2.003757 0.9987492
## y[22]         34.57662815    2.003757 0.9987492
## y[23]         35.97166622    2.003757 0.9987492
## y[24]         11.12088361    2.003757 0.9987492
## y[25]         15.22465643    2.003757 0.9987492
## y[26]         19.47180929    2.003757 0.9987492
## y[27]         41.00921639    2.003757 0.9987492
## y[28]         22.20170783    2.003757 0.9987492
## log_lik[1]    -5.23850822  901.959097 1.0017617
## log_lik[2]    -5.18769056 3089.837475 1.0003802
## log_lik[3]    -5.82651483 3178.894082 1.0004991
## log_lik[4]    -6.05320150 3185.425727 1.0005389
## log_lik[5]    -5.72602439 3125.538653 1.0006646
## log_lik[6]    -8.68475089 3183.839326 1.0005614
## log_lik[7]   -32.63243493 3166.012742 1.0006120
## log_lik[8]    -5.16364972 3127.565422 1.0004160
## log_lik[9]   -15.11738097 3181.013428 1.0005750
## log_lik[10]   -5.58760182 3131.554740 1.0006584
## log_lik[11]   -5.83119681 3185.187162 1.0005327
## log_lik[12]  -25.67699779 3164.338726 1.0006150
## log_lik[13]   -5.39833119 3171.023395 1.0004787
## log_lik[14]   -6.20991786 3145.236886 1.0006427
## log_lik[15]   -5.25082671 2859.149463 1.0002475
## log_lik[16]   -8.54509666 3182.944889 1.0005665
## log_lik[17]  -16.46740057 3162.503322 1.0006181
## log_lik[18]   -5.97548844 3185.362886 1.0005364
## log_lik[19]  -14.26532200 3180.431391 1.0005772
## log_lik[20]   -7.84463965 3150.444914 1.0006360
## log_lik[21]  -10.31577233 3155.855224 1.0006284
## log_lik[22]   -5.30945082 3141.779762 1.0004325
## log_lik[23]   -5.16613622 3051.089016 1.0007235
## log_lik[24]  -11.50999784 3180.736872 1.0005761
## log_lik[25]  -14.02993711 3180.666427 1.0005763
## log_lik[26]  -13.82766538 3181.133307 1.0005745
## log_lik[27]   -5.46905399 3116.812230 1.0006731
## log_lik[28]  -11.50699747 3182.015151 1.0005709
## rho[1]         0.09166899 3176.945243 1.0005881
## rho[2]         0.09166899 3176.945243 1.0005881
## rho[3]         0.09166899 3176.945243 1.0005881
## rho[4]         0.09166899 3176.945243 1.0005881
## rho[5]         0.09166899 3176.945243 1.0005881
## rho[6]         0.09166899 3176.945243 1.0005881
## rho[7]         0.09166899 3176.945243 1.0005881
## rho[8]         0.09166899 3176.945243 1.0005881
## rho[9]         0.09166899 3176.945243 1.0005881
## rho[10]        0.09166899 3176.945243 1.0005881
## rho[11]        0.09166899 3176.945243 1.0005881
## rho[12]        0.09166899 3176.945243 1.0005881
## rho[13]        0.09166899 3176.945243 1.0005881
## rho[14]        0.09166899 3176.945243 1.0005881
##  [ reached getOption("max.print") -- omitted 15 rows ]
out <- rstan::extract(temp)

#' Could add truth to this plot and remake in ggplot2
plot(out$y_mis)