<p>I can only give you a partial answer. You should be aware that this is pretty bleeding-edge; although the ArXiv paper (dated Feb 2020) says</p>
<blockquote>
<p>Hopefully by the time you are reading
this, the functionality will be available in the stable release on the Comprehensive R Archive Network (CRAN)</p>
</blockquote>
<p>but so far that's not even true; it's not even in the master GitHub branch, so I used <code>remotes::install_github(&quot;stan-dev/rstanarm@feature/survival&quot;)</code> to install it from source.</p>
<p>The proximal problem is that you should specify the new data frame as <code>newdata</code>, not <code>newdataEvent</code>.  There seem to be a lot of mismatches between the master and this branch, and between the docs and the code ... <code>newdataEvent</code> is used in the older method for <code>stanjm</code> models, but not for <code>stansurv</code> models. You can look at the code <a href="https://github.com/stan-dev/rstanarm/blob/feature/survival/R/posterior_survfit.R#L364-L377" rel="nofollow noreferrer">here</a>, or use <code>formals(rstanarm:::posterior_survfit.stansurv)</code>. Unfortunately, because this method has an (unused, unchecked) <code>...</code> argument, that means that any misnamed arguments will be silently ignored.</p>
<p>The next problem is that if you specify the new data in your example as <code>newdata</code> you'll get</p>
<blockquote>
<p>Error: The following variables are missing from the data: subplot_by_site, New.Species.name</p>
</blockquote>
<p>That is, there doesn't seem to be an obvious way to generate a population-level posterior prediction. (Setting the random effects grouping variables to <code>NA</code> isn't allowed.) If you want to do this, you could either:</p>
<ul>
<li>expand your <code>newdata</code> to include all combinations of the grouping variables in your data set, and average the results across levels yourself;</li>
<li>post an issue on GitHub or contact the maintainers ...</li>
</ul>
Posterior_survfit() is not using the nd
<p>I am having trouble generating posterior predictions using posterior_survfit(). I am trying to use a new data frame, but it is not using the new data frame and instead is using values from the dataset I used to fit the model. The fitted variables in the model are New.Treatment (6 treatments = categorical), Openness (a continuous light index min= 2.22, mean= 6.903221 and max=10.54), subplot_by_site(categorical-720 sites), New.Species.name(categorical- 165 species). My new data frame has 94 rows and the posterior_survfit() is giving me 3017800 rows. Help, please!</p>
<pre><code>head(nd)
      New.Treatment Openness
1          BE                  5
2          BE                  6
3          BE                  7
4          BE                  8
5          BE                  9
6          BE                 10


fit= stan_surv(formula = Surv(days, Status_surv) ~ New.Treatment*Openness + (1 |subplot_by_site)+(1|New.Species.name),
  data = dataset,
  basehaz = &quot;weibull&quot;,
  chains=4,
  iter = 2000,
  cores =4 )

Post=posterior_survfit(fit, type=&quot;surv&quot;,
                        newdata=nd5)

head(Post)
  id cond_time    time median  ci_lb  ci_ub
1  1        NA 62.0000 0.9626 0.9623 1.0000
2  1        NA 69.1313 0.9603 0.9600 0.9997
3  1        NA 76.2626 0.9581 0.9579 0.9696
4  1        NA 83.3939 0.9561 0.9557 0.9665
5  1        NA 90.5253 0.9541 0.9537 0.9545
6  1        NA 97.6566 0.9522 0.9517 0.9526

##Here some reproducible code to explain my problem:

library(rstanarm)

data_NHN&lt;- expand.grid(New.Treatment = c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;), Openness = c(seq(2, 11, by=0.15)))
data_NHN$subplot_by_site=c(rep(&quot;P1&quot;,63),rep(&quot;P2&quot;,60),rep(&quot;P3&quot;,60))
data_NHN$Status_surv=sample(0:1,183, replace=TRUE) 
data_NHN$New.Species.name=c(rep(&quot;sp1&quot;,10),rep(&quot;sp2&quot;,40),rep(&quot;sp1&quot;,80),rep(&quot;sp2&quot;,20),rep(&quot;sp1&quot;,33))
data_NHN$days=sample(10, size = nrow(data_NHN), replace = TRUE)

nd_t&lt;- expand.grid(New.Treatment = c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;), Openness = c(seq(2, 11, by=1)))


mod= stan_surv(formula = Surv(days, Status_surv) ~ New.Treatment+Openness + (1 |subplot_by_site)+(1|New.Species.name),
                  data =data_NHN,
                  basehaz = &quot;weibull&quot;,
                  chains=4,
                  iter = 30,
                  cores =4)

summary(mod)
pos=posterior_survfit(mod, type=&quot;surv&quot;,
                        newdataEvent=nd_t,
                      times = 0)
head(pos)

 #I am interested in predicting values for specific Openess values  
 #(nd_t=20 rows)but I am getting instead values for each point in time 
 #(pos=18300rows)
</code></pre>
<p>Operating System: Mac OS Catalina 10.15.6
R version: 4.0
rstan version: 2.21.2
rstanarm Version: rstanarm_2.21.2
Any suggestions on why is it not working. it’s not clear how to give some sort of plot of the effects of one variable in the interaction as the other changes and the associated uncertainty (i.e. a marginal effects plot). In my example, I am interested in getting the values at specific &quot;Openness&quot; values and not at each specific time as appears in the posterior results. TIA.</p>