The following objects are masked from 'package:stats':
mad, sd, var
The following objects are masked from 'package:base':
%in%, match
Loading required package: parallel
rethinking (Version 2.42)
Attaching package: 'rethinking'
The following object is masked from 'package:stats':
rstudent
This chapter is an introduction to multilevel models, which can partially pool data from different clusters to balance between overfitting and underfitting. The trick to these models is using an adaptive prior, a prior whose parameters have their own priors, which allows the model to learn the prior from the data.
Exercises
13E1
The prior \(a_{\text{TANK}} \sim \text{Normal}(0, 1)\) will induce more shrinkage in the etimates than the prior \(a_{\text{TANK}} \sim \text{Normal}(0, 2)\). The smaller the variance of the prior is, the more shrinkage the prior will induce towards the prior mean.
13E2
We could rewrite this as a multilevel model in multiple ways, but we’ll do the easy way by converting the no-pooling structure for \(\alpha\) into a multilevel adaptive prior.
We’ll also write a mathematical model formula for a Poisson regression with varying intercepts. Again, nothing about the likelihood changes the way the multilevel part works.
Now we’ll modify that model to have two different kinds of varying intercepts. Recall that we can only identify the mean of a single varying intercept, so the new one needs to have a mean of zero. We’ll call the new group the “block” since it’s an example we used earlier in the chapter.
Now we want to fit a model to the Reed frog survival data, and include the effects of predation and size in the varying intercept model. We need to build five total models: one with just varying intercepts, one with predation only, one with size only, one with both predation and size, and one with predation, size, and their interaction. First we’ll format the data.
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342075fe2bc0.stan', line 19, column 4 to column 32)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Running MCMC with 4 parallel chains, with 1 thread(s) per chain...
Chain 1 Rejecting initial value:
Chain 1 Log probability evaluates to log(0), i.e. negative infinity.
Chain 1 Stan can't start sampling from this initial value.
Chain 1 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34205c5342e7.stan', line 23, column 4 to column 28)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 2 Rejecting initial value:
Chain 2 Log probability evaluates to log(0), i.e. negative infinity.
Chain 2 Stan can't start sampling from this initial value.
I got a lot of divergences on the interaction model specifically, so I removed the a_bar parameter from the multilevel model and made it a global intercept, along with turning up the control parameters and iterations. I tried either change by itself, but it seemed that both were necessary to fix the divergence transitions.
Now that we’ve fit the models let’s take a quick glance at the coefficients across all of them. We won’t look at the individual tank intercepts, only the population-level parameters.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Here’s some observations I notice from this plot: the intercept a_bar matters a lot, but them seems to matter less (be closer to zero) once we introduce size into the model. For all three models that have an effect of big tank, the intercept CI is much closer to zero. Predation has an impact wiht a wide CI in every model its in, and size has a small but consistent effect in all three models its in. THe effect of the interaction is very small and probably negligible. Let’s compare the models with PSIS to see how the different predictors affect the estimated out-of-sample error.
Some Pareto k values are very high (>1). Set pointwise=TRUE to inspect individual points.
Some Pareto k values are high (>0.5). Set pointwise=TRUE to inspect individual points.
Some Pareto k values are very high (>1). Set pointwise=TRUE to inspect individual points.
Some Pareto k values are very high (>1). Set pointwise=TRUE to inspect individual points.
Some Pareto k values are very high (>1). Set pointwise=TRUE to inspect individual points.
We see that some pareto \(k\) values are very high for all of the models, which I guess means there are probably some tanks with unusually high or low survival rates that affect the amount of pooling we need a lot.
But now we aren’t supposed to focus on the predictors we’re supposed to focus on the inferred variation across tanks. So let’s look at how the \(\bar{\alpha}\) and \(\sigma\) parameters change across models.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
We discussed the \(\bar{\alpha}\) parameter earlier, but we can also see that the expected variance, \(\sigma\) decreases as we add predictors to the model, with models 4 and 5 having similar levels of variance, much lower than the variance for the model with no predictors. This is because the predictors help to explain why some of the tanks are so different – the \(\alpha_i\) effects are the effects of each individual tank after we account for the effects of the predictors we include, so we expect the variance across \(\alpha_i\)’s to be smaller as we include influential predictors that help to explain our observations, particularly if they help to explain extreme observations.
13M2
OK, now we need to compare the models using WAIC. I Already did this with PSIS because I thought the first answer wouldn’t be finished without a comparison. But I guess I’ll do it again with WAIC.
Just like the PSIS values, the WAIC’s pretty much indicate that the models are all basically the same in terms of predictive accuracy. Model 2, which has varying intercepts for tanks and an effect of predation was still overall the best, but the WAIC values are so similar that this comparison doesn’t really mean anything.
13M3
In this question, we’ll use my least favorite prior, the Cauchy prior. I don’t like the Cauchy distribution. Nothing in science ever follows the Cauchy distribution, because everything in real life has a finite variance and a mean that exists. But I guess we better do this problem and hopefully it will show us that the Cauchy distribution is a bad choice.
Running MCMC with 4 parallel chains, with 1 thread(s) per chain...
Chain 1 Iteration: 1 / 1000 [ 0%] (Warmup)
Chain 1 Iteration: 100 / 1000 [ 10%] (Warmup)
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: cauchy_lpdf: Scale parameter is 0, but must be positive finite! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342039155ce3.stan', line 17, column 4 to column 32)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: cauchy_lpdf: Scale parameter is 0, but must be positive finite! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342039155ce3.stan', line 17, column 4 to column 32)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: cauchy_lpdf: Scale parameter is inf, but must be positive finite! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342039155ce3.stan', line 17, column 4 to column 32)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Despite Richard’s warning, I did not get any divergences from this model, although I expected them because of how much Cauchy priors suck. Let’s compare the coefficients in this model to the same model with normal priors.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
The Cauchy scale parameter is lower than the normal distribution SD (which makes sense, because it has fatter tails than a Normal at the same scale) but the means are pretty much the same, despite what Richard implies should happen in the question. I guess the cauchy location parameter has a slightly higher value. Let’s plot the individual tank estimate correlation.
alphas <- coeftab_cauchy_whatever@coefs[1:48, ] |>as.data.frame()plot(x = alphas$m_13m1_1, y = alphas$m_13m3,xlab ="Normal prior", ylab ="Cauchy prior")abline(a =0, b =1, lty =2)
The estimates with extreme values under the normal prior get made more extreme by the Cauchy prior. We lose some of the regularizing effect of the adaptive normal prior, because the Cauchy prior allows for extreme values to be extreme very easily.
13M4
Now we do the same thing but with a Student’s \(t\) prior with 2 degrees of freedom. I still don’t like this, because a Student’s \(t\) prior with 2 degrees of freedom still has an infinite variance, which doesn’t make sense in real life. My prior beliefs about real-world parameters never have infinite variance. I think a Student’s \(t\) prior with 3 degrees of freedom is sensible, but whatever, I’ll do what the problem says.
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: student_t_lpdf: Scale parameter is inf, but must be positive finite! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420459c59ba.stan', line 17, column 4 to column 39)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: student_t_lpdf: Scale parameter is inf, but must be positive finite! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420459c59ba.stan', line 17, column 4 to column 39)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
Warning: The ESS has been capped to avoid unstable estimates.
We can see that the new \(t\) distribution has a scale and location parameter in-between the values for the Cauchy and Normal priors. Let’s look at the correlations again.
alphas2 <- coeftab_nct@coefs[1:48, ] |>as.data.frame()plot(x = alphas$m_13m1_1, y = alphas$m_13m3,xlab ="Normal prior", ylab ="Cauchy or Student's t_2 prior",pch =16, cex =0.9)points(x = alphas2$m_13m1_1, y = alphas2$m_13m4, col = rethinking::rangi2)abline(a =0, b =1, lty =2)
The filled, black points show the Cauchy prior estimate on the \(Y\) axis and the empty, blue points show the Student’s \(t\) (df = 2) prior estimate on the \(Y\) axis. The Student’s \(t\) prior etimates are smaller than the Cauchy estimates, but still not the same as the Normal estimates for the extreme values. This is because a Student’s \(t\) prior with 1 degree of freedom is the same as a Cauchy prior, and increasing the degrees of freedom makes the prior more similar to a Normal prior with the same location and scale parameters.
13M5
In this problem, we’ll add a parameter for the mean of the adaptive prior for the \(\gamma\) effects in the chimps problem.
Warning: 366 of 2000 (18.0%) transitions ended with a divergence.
See https://mc-stan.org/misc/warnings for details.
Now we can compare the coefficients. We only need to look at the hyperprior coefficients here, but we should also note that this model sampled more slowly and had more divergent transitions.
The estimates are not as bad as I thought they would be, but there is more uncertainty in a_bar in the model with a g_bar parameter, and the uncertainty is also very large in g_bar. The sigma parameters don’t change.
We can look at the correlation between samples of a_bar and g_bar in the model of both to better understand what’s happening.
samples <- rethinking::extract.samples(m_13m5, pars =c("a_bar", "g_bar"))# The pars argument doesn't seem to actually do anything, so we need to# get only the things we want in a data frame.samples_df <-data.frame(a_bar = samples$a_bar[ , 1],g_bar = samples$g_bar[ , 1])plot(samples_df$a_bar, samples_df$g_bar, xlab ="a_bar", ylab ="g_bar")
The samples for the two parameters have a very strong negative correlation. Whenever one increases, the other has to decrease – this is the same as the two feet example we saw before, basically these parameters cannot be reliably distinguished by the model.
13M6
Fitting a model to one data point is nearly always an exercise in futility, but let us fit four models to the same one data point.
m_13m6_nn <- rethinking::ulam(alist( y ~dnorm(mu, 1), mu ~dnorm(10, 1) ),data =list(y =0),chains =4, cores =4)
In file included from stan/src/stan/model/model_header.hpp:5:
stan/src/stan/model/model_base_crtp.hpp:205:8: warning: 'void stan::model::model_base_crtp<M>::write_array(stan::rng_t&, std::vector<double>&, std::vector<int>&, std::vector<double>&, bool, bool, std::ostream*) const [with M = ulam_cmdstanr_151e8eede558bd2e1c0e665ff85db334_model_namespace::ulam_cmdstanr_151e8eede558bd2e1c0e665ff85db334_model; stan::rng_t = boost::random::mixmax_engine<17, 36, 0>; std::ostream = std::basic_ostream<char>]' was hidden [-Woverloaded-virtual=]
205 | void write_array(stan::rng_t& rng, std::vector<double>& theta,
| ^~~~~~~~~~~
OK, now that we fitted all of these models let’s look at the posterior distributions I guess. Unfortunately coeftab() doesn’t seem to work on these models for whatever reason.
I stared at this for a while and had no idea what was going on. But I think what is happening here is a consequence of the fact that the normal distribution prior is “stronger” than the \(t\) prior. We don’t “know” what should be true here, but based on our one data point we would guess that the mean of \(y\) should be zero instead of 10, which we know a priori is the mean of \(\mu\).
So if we set a \(t\) prior on \(\mu\), but not on \(y\) (treating the likelihood as the prior on the data; this is the nt model), all of the posterior mass for \(\mu\) is at zero, because the prior for \(\mu\) “loses” to the prior for \(y\) – the \(t\) prior has very thick tails so it accomodotes the stronger normal prior’s desire to be centered at \(0\). Similarly but opposite, in the tn model where the likelihood is the t distribution but the prior on \(\mu\) is normal, the posterior distribution is pulled to a mean of \(10\), the mean that we specified in the prior that was Normal.
For the tt model and the nn model, neither model “wins” because they’re equally strong, but they “tie” in different ways. For the nn model, both normal priors try to pull the mean towards what we observed, but they are both forceful so we get a compromise at \(5\) – we get a compromise that makes neither prior happy, but they’re both “halfway right” in a specific sense. For the tt model, neither prior is forceful so we get a posterior that says the mean could be \(0\) or the mean could be \(10\) but we can’t be sure because neither prior is “aggressive”, so instead of a bad compromise we get no agreement at all.
13H1
For this problem, we want to used a fixed-effects and a varying-effects model to estiamte use of contraception by province from the 1988 Bangladesh Fertility Survey. First we need to set up the data.
It might be better to fit this particular model using the aggregated binomial form, but since we have each observation and they arise from a natural process, I think it makes more sense to treat each row as an independent Bernoulli trial for each woman, instead of as a set of Binomial trials with varying \(n\) and fixed success probabilities.
So we’ll fit bernoulli models with fixed effects per district, and with varying (adaptively clustered) effects.
We fit both of the models, let’s get the predicted probabilities from both models.
all_districts <-data.frame(d =unique(dat_bng$d))post_fe <- rethinking::link(m_13h1_fe, all_districts)post_ve <- rethinking::link(m_13h1_ve, all_districts)mean_pi <-function(x, na.rm =FALSE, trim =0, prob =0.89) { m <-mean(x, trim = trim, na.rm = na.rm) pi <- rethinking::PI(x, prob = prob)return(c("est"= m, "lwr"= pi[[1]], "upr"= pi[[2]]))}post_fe_summary <-apply(post_fe, 2, mean_pi)post_ve_summary <-apply(post_ve, 2, mean_pi)fe <- post_fe_summary |>t() |>as.data.frame() |> dplyr::mutate(district = dplyr::row_number(), model ="Fixed")ve <- post_ve_summary |>t() |>as.data.frame() |> dplyr::mutate(district = dplyr::row_number(), model ="Varying")both <- dplyr::bind_rows(fe, ve) |> dplyr::left_join(district_counts, by ="district")library(ggplot2)ggplot2::ggplot(both) + ggplot2::aes(x = district, y = est, ymin = lwr, ymax = upr,col = model, fill = model, shape = model ) + ggplot2::geom_hline(yintercept = overall_prev, lty =2, col ="darkgray") + ggplot2::geom_pointrange(#position = ggplot2::position_dodge(width = 0.9),alpha =0.7 ) + ggplot2::scale_x_continuous(limits =c(0, 61),breaks =c(1, seq(5, 60, 5)),expand =c(0, 0) ) + ggplot2::labs(x ="district", y ="probability of contraception") + ggplot2::theme_minimal(base_size =24) + ggplot2::theme(legend.position ="bottom")
In this plot, the dashed gray line shows the overall proportion of contraception usage in the dataset. The more extreme observations get pulled towards the mean more strongly in the varying effects model.
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
From this plot, we can see that the estimates with the most extreme differences between models (the red points, which are those furthest from the dashed gray line of equality) are points with relatively small sample sizes that also have extreme estimates. The error bars are a bit noisy, but we can still see that for most points, the line of equality falls within the error bars in at least one direction. The only exception are the most extreme points.
So there’s nothing unusual going on here, just the normal effect that we expect to see from applying regularization to our estimates. Districts with fewer estimates are also more likely to have extreme probability estimates, so there is a compounding effect in the shrinkage.
13H2
Now we’ll go back to the Trolley data, so we need to clean up the data again.
For this problem we want to fit a model that ignores individuals and a model that has varying intercepts for each individual, so let’s do that now. First the model that ignores id.
m_13h2_1 <- rethinking::ulam(alist( R ~dordlogit(phi, cutpoints), phi <- bA * A + bC * C + bI * I,c(bA, bI, bC) ~dnorm(0, 0.5), cutpoints ~dnorm(0, 1.5) ),data = dat_trolley,chains =4, cores =4,iter =2500, warmup =500,log_lik =TRUE)
In file included from stan/src/stan/model/model_header.hpp:5:
stan/src/stan/model/model_base_crtp.hpp:205:8: warning: 'void stan::model::model_base_crtp<M>::write_array(stan::rng_t&, std::vector<double>&, std::vector<int>&, std::vector<double>&, bool, bool, std::ostream*) const [with M = ulam_cmdstanr_56ffa6e4d69fb853769d1c0d2f94df0c_model_namespace::ulam_cmdstanr_56ffa6e4d69fb853769d1c0d2f94df0c_model; stan::rng_t = boost::random::mixmax_engine<17, 36, 0>; std::ostream = std::basic_ostream<char>]' was hidden [-Woverloaded-virtual=]
205 | void write_array(stan::rng_t& rng, std::vector<double>& theta,
| ^~~~~~~~~~~
Running MCMC with 4 parallel chains, with 1 thread(s) per chain...
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is 8.4231e+96, but should be greater than the previous element, 8.4231e+96 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is 8.41505e+96, but should be greater than the previous element, 8.41505e+96 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is 6.0972e+23, but should be greater than the previous element, 6.0972e+23 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is 284707, but should be greater than the previous element, 284707 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -188.76, but should be greater than the previous element, -188.76 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -187.355, but should be greater than the previous element, -187.355 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -47.4516, but should be greater than the previous element, -47.4516 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -12.7996, but should be greater than the previous element, -12.7996 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 4 is -3.59436, but should be greater than the previous element, -3.59436 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3686.56, but should be greater than the previous element, -3686.56 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3683.89, but should be greater than the previous element, -3683.89 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -923.455, but should be greater than the previous element, -923.455 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -232.176, but should be greater than the previous element, -232.176 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -59.7153, but should be greater than the previous element, -59.7153 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -16.4365, but should be greater than the previous element, -16.4365 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3166.49, but should be greater than the previous element, -3166.49 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3167.2, but should be greater than the previous element, -3167.2 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -791.476, but should be greater than the previous element, -791.476 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -196.571, but should be greater than the previous element, -196.571 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 1 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is inf, but should be greater than the previous element, inf (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is 9.90209e+241, but should be greater than the previous element, 9.90209e+241 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 2 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -45947.8, but should be greater than the previous element, -45947.8 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -549.284, but should be greater than the previous element, -549.284 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 3 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -264514, but should be greater than the previous element, -264514 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3171.46, but should be greater than the previous element, -3171.46 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 4 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -197670, but should be greater than the previous element, -197670 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2367.59, but should be greater than the previous element, -2367.59 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-34204e6d19af.stan', line 24, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
6 vector or matrix parameters hidden. Use depth=2 to show them.
mean sd 5.5% 94.5% rhat ess_bulk
bC -0.9478110 0.04957521 -1.0272033 -0.8692619 1.000611 6121.160
bI -0.7130898 0.03663150 -0.7711662 -0.6546722 1.000504 7080.426
bA -0.6983976 0.03975742 -0.7620553 -0.6350968 1.000633 5606.926
And now the model with random intercepts per person.
m_13h2_2 <- rethinking::ulam(alist( R ~dordlogit(phi, cutpoints), phi <- a[id] + bA * A + bC * C + bI * I,c(bA, bI, bC) ~dnorm(0, 0.5),# We already have intercepts by default in this type of model# so we can't identify a random intercept mean a[id] ~dnorm(0, sigma), sigma ~dexp(1), cutpoints ~dnorm(0, 1.5) ),data = dat_trolley,chains =4, cores =4,iter =2500, warmup =500,log_lik =TRUE)
In file included from stan/src/stan/model/model_header.hpp:5:
stan/src/stan/model/model_base_crtp.hpp:205:8: warning: 'void stan::model::model_base_crtp<M>::write_array(stan::rng_t&, std::vector<double>&, std::vector<int>&, std::vector<double>&, bool, bool, std::ostream*) const [with M = ulam_cmdstanr_482ce47ca44d3178675bfde49440ce01_model_namespace::ulam_cmdstanr_482ce47ca44d3178675bfde49440ce01_model; stan::rng_t = boost::random::mixmax_engine<17, 36, 0>; std::ostream = std::basic_ostream<char>]' was hidden [-Woverloaded-virtual=]
205 | void write_array(stan::rng_t& rng, std::vector<double>& theta,
| ^~~~~~~~~~~
Running MCMC with 4 parallel chains, with 1 thread(s) per chain...
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2506.14, but should be greater than the previous element, -2506.14 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2505.52, but should be greater than the previous element, -2505.52 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -626.482, but should be greater than the previous element, -626.482 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -156.326, but should be greater than the previous element, -156.326 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -39.038, but should be greater than the previous element, -39.038 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 5 is inf, but should be greater than the previous element, inf (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 5 is inf, but should be greater than the previous element, inf (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 5 is 1.9949e+83, but should be greater than the previous element, 1.9949e+83 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 5 is 2.3758e+20, but should be greater than the previous element, 2.3758e+20 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2284.75, but should be greater than the previous element, -2284.75 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2285.05, but should be greater than the previous element, -2285.05 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -572.184, but should be greater than the previous element, -572.184 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -143.185, but should be greater than the previous element, -143.185 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -36.1439, but should be greater than the previous element, -36.1439 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -4063.66, but should be greater than the previous element, -4063.66 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -4064.36, but should be greater than the previous element, -4064.36 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -1016.25, but should be greater than the previous element, -1016.25 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -253.717, but should be greater than the previous element, -253.717 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -63.1941, but should be greater than the previous element, -63.1941 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -15.5311, but should be greater than the previous element, -15.5311 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 1 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 21, column 4 to column 28)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -864.566, but should be greater than the previous element, -864.566 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 2 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -9640.17, but should be greater than the previous element, -9640.17 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 5 is 1.62442e+42, but should be greater than the previous element, 1.62442e+42 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 3 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is inf, but should be greater than the previous element, inf (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is inf, but should be greater than the previous element, inf (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 4 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 21, column 4 to column 28)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 6 is 1.51264e+111, but should be greater than the previous element, 1.51264e+111 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-3420c5b5798.stan', line 28, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
337 vector or matrix parameters hidden. Use depth=2 to show them.
mean sd 5.5% 94.5% rhat ess_bulk
bC -1.2545195 0.05214927 -1.338813 -1.1723489 0.9997024 9652.708
bI -0.9462145 0.03828754 -1.007491 -0.8853769 0.9998575 10363.328
bA -0.9415201 0.04281814 -1.010358 -0.8729049 1.0000257 8514.766
sigma 1.8829550 0.08068005 1.759069 2.0170261 1.0004416 8189.220
We can see that not only do we get higher ESS for our main parameters in the varying intercepts model, we can actually see that the effects of interest are more negative than they were before. We have to look at the WAIC and posterior predictions, even though I think I can explain this already, so we’ll look at the WAIC first.
rethinking::compare(m_13h2_1, m_13h2_2)
WAIC SE dWAIC dSE pWAIC weight
m_13h2_2 31338.86 177.31618 0.000 NA 353.573092 1
m_13h2_1 37089.94 75.76839 5751.078 172.1097 8.980726 0
Despite having many more parameters, the varying intercepts model is clearly better than the model that ignores individual variations. Let’s look at some posterior predictions. I don’t know that we really talked about a great way to visualize these predictions, so I’ll try to do something like the histograms of the posterior predictive distribution in Chapter 12.
# Get the ppd simulationsm_13h2_1_ppd <- rethinking::sim(m_13h2_1)m_13h2_2_ppd <- rethinking::sim(m_13h2_2)# Get the data that shows which columns are which individuals and stories# Cause we're going to summarize over thosetrolley_preds <- Trolley_clean |> dplyr::mutate(fe_pred =colMeans(m_13h2_1_ppd),ve_pred =colMeans(m_13h2_2_ppd) )tidy_mean_pi <-function(x, ...) tibble::enframe(mean_pi(x, ...))trolley_preds_by_person <- trolley_preds |> tidyr::pivot_longer(c(fe_pred, ve_pred),names_to ="model", values_to ="preds" ) |> dplyr::reframe(tidy_mean_pi(preds),.by =c(id, model) ) |> tidyr::pivot_wider(names_from = name, values_from = value) |> dplyr::mutate(model =factor( model,levels =c("fe_pred", "ve_pred"),labels =c("No individual effects", "Individual varying intercepts") ) )library(ggplot2)ggplot(trolley_preds_by_person) +aes(x = est, xmin = lwr, xmax = upr, y = id, color = model, shape = model) +geom_pointrange(alpha =0.7) +theme_minimal(base_size =24) +theme(legend.position ="bottom") +labs(x ="Average response", y ="Individual id", color =NULL, shape =NULL)
This plot kind of looks bad but you can see the major difference here that makes the varying effects model work so much better. Each individual has a different average across all studies – some individuals tend to rate all strories highly, or all stories lowly, and very few individuals are actually close to the study sample average response that is enforced by the model that ignores individual effects. So by allowing individuals to have different baseline ratings (usually called their “anchor point”), we can actually get better estimates of how the different features of stories change ratings on average, not only how they change the average rating.
13H3
Now we’ll fit a model that also has varying intercepts for the story variable.
m_13h3 <- rethinking::ulam(alist( R ~dordlogit(phi, cutpoints), phi <- a_id[id] + a_st[story] + bA * A + bC * C + bI * I,c(bA, bI, bC) ~dnorm(0, 0.5),# We already have intercepts by default in this type of model# so we can't identify a random intercept mean a_id[id] ~dnorm(0, sigma_id), a_st[story] ~dnorm(0, sigma_st), sigma_id ~dexp(1), sigma_st ~dexp(1), cutpoints ~dnorm(0, 1.5) ),data = dat_trolley,chains =4, cores =4,iter =2500, warmup =500,log_lik =TRUE)
In file included from stan/src/stan/model/model_header.hpp:5:
stan/src/stan/model/model_base_crtp.hpp:205:8: warning: 'void stan::model::model_base_crtp<M>::write_array(stan::rng_t&, std::vector<double>&, std::vector<int>&, std::vector<double>&, bool, bool, std::ostream*) const [with M = ulam_cmdstanr_eaa20d013812fd39b95fb3343b83886b_model_namespace::ulam_cmdstanr_eaa20d013812fd39b95fb3343b83886b_model; stan::rng_t = boost::random::mixmax_engine<17, 36, 0>; std::ostream = std::basic_ostream<char>]' was hidden [-Woverloaded-virtual=]
205 | void write_array(stan::rng_t& rng, std::vector<double>& theta,
| ^~~~~~~~~~~
Running MCMC with 4 parallel chains, with 1 thread(s) per chain...
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -1739.91, but should be greater than the previous element, -1739.91 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -1739.66, but should be greater than the previous element, -1739.66 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is -435.796, but should be greater than the previous element, -435.796 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is -109.351, but should be greater than the previous element, -109.351 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3243.25, but should be greater than the previous element, -3243.25 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3243.94, but should be greater than the previous element, -3243.94 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -811.251, but should be greater than the previous element, -811.251 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -202.195, but should be greater than the previous element, -202.195 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is -50.5311, but should be greater than the previous element, -50.5311 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is -12.5393, but should be greater than the previous element, -12.5393 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2158.42, but should be greater than the previous element, -2158.42 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -2158.3, but should be greater than the previous element, -2158.3 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -540.597, but should be greater than the previous element, -540.597 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -135.111, but should be greater than the previous element, -135.111 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -4193.31, but should be greater than the previous element, -4193.31 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -4194.1, but should be greater than the previous element, -4194.1 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -1047.37, but should be greater than the previous element, -1047.37 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -260.317, but should be greater than the previous element, -260.317 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -63.4646, but should be greater than the previous element, -63.4646 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 1 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 25, column 4 to column 34)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is 2.43139e+134, but should be greater than the previous element, 2.43139e+134 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -19358.3, but should be greater than the previous element, -19358.3 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 3 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 6 is 1.14599e+15, but should be greater than the previous element, 1.14599e+15 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 3
Chain 4 Iteration: 1 / 2500 [ 0%] (Warmup)
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 25, column 4 to column 34)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 4 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -4734.57, but should be greater than the previous element, -4734.57 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 4
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -278987, but should be greater than the previous element, -278987 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 2
Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 2 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -3342.03, but should be greater than the previous element, -3342.03 (in 'C:/Users/Zane/AppData/Local/Temp/RtmpKe5Y1B/model-342072c729d.stan', line 32, column 24 to column 70)
Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Let’s compare the coefficients for the effects of interest across all three of our models. Even running this coeftab takes a long time makes the models have so many parameters. But I think it’s as fast as we can do with rethinking and I was too lazy to write any code that would access the underlying stan model to avoid dealing with any parameters I don’t care about right now.
The effects of contact (C) and action (A) are much stronger after we control for differences between stories and between individuals – adding the effect of stories on top of the effect of individuals makes the effects of C and A even stronger. However, the effect of intention (I) gets stronger as we add individual effects, but doesn’t change as much after we add effects for individual stories. These changes in coefficients from the model that accounts for individuals imply that, in addition to individuals having different baseline rating levels, different stories also have different baseline approval ratings. After we account for differences in individuals and differences in stories, we can see that stories that involved contact and action (and intention to a lesser extent) had much lower ratings.
Let’s check if this model fits better with WAIC, but I bet that it does.
Yes, the model that controls for individuals and stories is the best, and the differences in WAIC are noticeable beyond the estimated error. However, the difference between the model that controls for individuals and stories is not as stark as the difference between the model that controls for individuals and the model with fixed effects only. I think the last thing that’s worth noting is that the variance parameter for the story effects is much smaller than the variance parameter for the individual effects, and samples much more poorly.
13H4
For this problem, we’ll go back to the reedfrogs data. We’ve already cleaned that dataset once in this one. So we want to fit a model with varying intercepts and effects of size and predation, and both models and…wait, I already did this for the previous problem on reedfrogs. See solution to 13M1.