Cmdstanpy - extracting indexed parameters like log_likelihood

Hello, all,

I have managed to run a regression model using cmdstanpy.

Here is my summary code & Result:

fit = LVR_model.sample(data=LVR_data, chains=4, iter_sampling=200,iter_warmup=200, adapt_delta=0.90, max_treedepth=10)
Fit_Summary =fit.summary(percentiles=(5,95), sig_figs=2)



Now as you can see in the result that it only gives me few last log_likelihood. What if I want to see the log_likelihood of the first 5 observation, that is something along the lines of Fit_Summary.loc[['log_likelihood[1:5]']]

But this gives me error saying KeyError: “None of [Index([‘log_likelihood[1:5]’], dtype=‘object’)] are in the [index]”

But if I change the code to Fit_Summary.loc[['log_likelihood[1]']]

I Get

But surely there must be an easy way to extract all the log_likelihood in one command, rather than typing each one like Fit_Summary.loc[['log_likelihood[1]', 'log_likelihood[2]','log_likelihood[.]']]

Can someone please help me.


You could first save the summary results a variable, then create a list of cols and use that

summ = fit.summary()
rows = [key for key in summ.index if str(key).startswith("log_lik")]