Help me using pakcage gp_utility.R for plotting my draws from Rstan result

Hi friends,

I already run my model using the rstan and I got my results sucessfully. However I cannot plot my drawys using and receive this error:

Error in UseMethod(“extract”) : ***
*** no applicable method for ‘extract’ applied to an object of class "list"

While, I can sucessfully extract my result from simulation. Why this error happens?

here is the code:

model ← stan_model(‘GP_Sample.stan’)
simu_fit ← stan(file=‘GP_Sample.stan’, data=simu_data,
warmup=0, iter=4000, chains=1, seed=494838,
algorithm=“Fixed_param”, refresh=4000)



source(‘gp_utility.R’, local=util)
util$plot_gp_prior_realizations(Sim_result, x, “Realizations”)
util$plot_gp_prior_quantiles(Sim_result, x, “Prior Marginal Quantiles”)
util$plot_gp_prior_pred_quantiles(Sim_result, x, “Prior Predictive Marginal Quantiles”)

Could you kindly advice me that why I get this error and how i can resolve it?

Many thanks for your valuable coniderations, in advance.

Kindly Regards,

Based on these signatures gp_utility.R is from my Gaussian process case study, Robust Gaussian Process Modeling, which I should note come with no guarantees. That said these functions take the stanfit object as their first argument, not the extracted samples. Provided that you have the right variable names replacing Sim_result with simu_fit in the last three function calls should be better.

Dear Professor Michael Betancourt

Many thanks for your advice. Actually I tried that one as well but it did not respond again and I receieve the same error as: Error in UseMethod(“extract”) :
no applicable method for ‘extract’ applied to an object of class “stanfit”

having said that, only one time i get the result, but never again get respond.

Anyway, I do appreciate your case study [Robust Gaussian Process Modeling], i read it many times which is absoloutly a great lecture to understand the core idea behind GP.

kindly Regards

1 Like

Thanks for the kind words about the case study.

My guess is that you’re loading a tidyverse package in addition to rstan and calls to extract are being directed to the tidy extract function but not the rstan extract function. If that’s correct then replacing all instances of extract in the gp_utility.R code with rstan::extract should fix everything.

1 Like

Dear Prof. Michael,

many thanks for your advice. The Tidyverse Package was the issue as you kindly spot it. Now everything is going well.