Sorry @jonah, but I think there is still some issue. Uncertain if it’s with loo, rstanarm, or something else, but this code…

```
df<-read.csv("reducedvilt.csv")
options(mc.cores = 1)
require(rstanarm)
require(rstan)
require(loo)
rstan_options(auto_write = TRUE)
moddef="Inno_art ~ Vall_ha + Spann_ha + Socker_ha + Olje_ha + Balj_ha + Potatis_ha + Gron_ha + Majs_ha + Annat_ha + Lan"
df$Inno_art<-ordered(df$Inno_art,levels=1:5,labels=LETTERS[1:5])
WL<-stan_polr(moddef , data = df, method = "logistic",
prior = R2(0.25,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
moddef="Inno_art ~ Vall_ha + Spann_ha + Socker_ha + Olje_ha + Balj_ha + Potatis_ha + Gron_ha + Majs_ha + Annat_ha"
WoL<-stan_polr(moddef , data = df, method = "logistic",
prior = R2(0.25,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
LOOWith<-loo(WL,k_threshold = 0.7)
LOOWithout<-loo(WoL,k_threshold = 0.7)
```

…gives the error message…

```
Error in stanmat[, colnames(x), drop = FALSE] : subscript out of bounds
```

Swapping the order of which model is fitted first, i.e…

```
moddef="Inno_art ~ Vall_ha + Spann_ha + Socker_ha + Olje_ha + Balj_ha + Potatis_ha + Gron_ha + Majs_ha + Annat_ha"
WoL<-stan_polr(moddef , data = df, method = "logistic",
prior = R2(0.25,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
moddef="Inno_art ~ Vall_ha + Spann_ha + Socker_ha + Olje_ha + Balj_ha + Potatis_ha + Gron_ha + Majs_ha + Annat_ha + Lan"
WL<-stan_polr(moddef , data = df, method = "logistic",
prior = R2(0.25,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
LOOWithout<-loo(WoL,k_threshold = 0.7)
LOOWith<-loo(WL,k_threshold = 0.7)
```

…instead yields:

```
Error in eval(predvars, data, env) : object 'Lan' not found
```

In both cases, the first loo calculation works, but the second fail after refitting for pareto-flagged observations. I get the same results when running in parallel, but wanted to run serially to make sure there isn’t some issue related to previous problems with parallel chains on Windows. However, the following, which moves the loo calculation to immediately after stan_polr, works:

```
moddef="Inno_art ~ Vall_ha + Spann_ha + Socker_ha + Olje_ha + Balj_ha + Potatis_ha + Gron_ha + Majs_ha + Annat_ha + Lan"
WL<-stan_polr(moddef , data = df, method = "logistic",
prior = R2(0.25,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
LOOWith<-loo(WL,k_threshold = 0.7)
moddef="Inno_art ~ Vall_ha + Spann_ha + Socker_ha + Olje_ha + Balj_ha + Potatis_ha + Gron_ha + Majs_ha + Annat_ha"
WoL<-stan_polr(moddef , data = df, method = "logistic",
prior = R2(0.25,what = "median"), init_r = 0.1, seed = 12346,
algorithm = "sampling")
LOOWithout<-loo(WoL,k_threshold = 0.7)
```

Not sure what to make of it. It seems the loo calculation “remembers” the lastly fitted object and expects that object structure.