r/BayesianProgramming • • Jun 27 '17

Bayesian estimation of correlations and differences of correlations with a multivariate normal

Thumbnail
doingbayesiandataanalysis.blogspot.com
2 Upvotes

r/BayesianProgramming • • Jun 25 '17

You’ll never guess what’s been happening with PyStan and PyMC

Thumbnail andrewgelman.com
2 Upvotes

r/BayesianProgramming • • Jun 20 '17

Austin Rochford | Variational Inference in Python

Thumbnail
youtube.com
2 Upvotes

r/BayesianProgramming • • Jun 17 '17

Hello, world! Stan, PyMC3, and Edward

Thumbnail andrewgelman.com
2 Upvotes

r/BayesianProgramming • • Jun 16 '17

Andrew Rowan - Bayesian Deep Learning with Edward (and a trick using Dropout)

Thumbnail
youtube.com
2 Upvotes

r/BayesianProgramming • • Jun 16 '17

PyMC3 Discourse Community

Thumbnail
discourse.pymc.io
2 Upvotes

r/BayesianProgramming • • May 29 '17

Numbers of parameters in a Bayesian Network?

2 Upvotes

I'm going through the book, "Bayesian Networks With Examples in R" and the book didn't explain how they got 21 parameters in this.

I'm posting the R code below. Thanks.

library(bnlearn)
# first step, create node for each variable
dag <- empty.graph(nodes = c("A", "S", "E", "O", "R", "T"))
dag <- set.arc(dag, from = "A", to = "E")
dag <- set.arc(dag, from = "S", to = "E")
dag <- set.arc(dag, from = "E", to = "O")
dag <- set.arc(dag, from = "E", to = "R")
dag <- set.arc(dag, from = "O", to = "T")
dag <- set.arc(dag, from = "R", to = "T")
modelstring(dag)
A.lv <- c("young", "adult", "old")
S.lv <- c("M", "F")
E.lv <- c("high", "uni")
O.lv <- c("emp", "self")
R.lv <- c("small", "big")
T.lv <- c("car", "train", "other")

A.prob <- array(c(0.30, 0.50, 0.20), dim = 3, dimnames = list(A = A.lv))
S.prob <- array(c(0.60, 0.40), dim = 2, dimnames = list(S = S.lv))
O.prob <- array(c(0.96, 0.04, 0.92, 0.08), dim = c(2, 2),
                dimnames = list(O = O.lv, E = E.lv))
R.prob <- array(c(0.25, 0.75, 0.20, 0.80), dim = c(2, 2),
                dimnames = list(R = R.lv, E = E.lv))
E.prob <- array(c(0.75, 0.25, 0.72, 0.28, 0.88, 0.12, 0.64,
                  0.36, 0.70, 0.30, 0.90, 0.10), dim = c(2, 3, 2),
                dimnames = list(E = E.lv, A = A.lv, S = S.lv))
T.prob <- array(c(0.48, 0.42, 0.10, 0.56, 0.36, 0.08, 0.58,
                  0.24, 0.18, 0.70, 0.21, 0.09), dim = c(3, 2, 2),
                dimnames = list(T = T.lv, O = O.lv, R = R.lv))
cpt <- list(A = A.prob, S = S.prob, E = E.prob, O = O.prob, R = R.prob,
            T = T.prob)
bn <- custom.fit(dag, cpt)
nparams(bn)

r/BayesianProgramming • • May 14 '26

Request for expert review — Verifiable Risk Protocol draft

Thumbnail reddit.com
1 Upvotes

r/BayesianProgramming • • Jan 16 '26

Looking for expert feedback on Bayesian fusion report for UAP case triage

1 Upvotes

Hi all,

I’ve written a report that develops a Bayesian fusion framework for UAP case triage. It combines Bayesian inference, risk/decision analysis, and multi‑source evidence fusion to prioritize cases based on the quality and combination of available evidence.

I’m looking for one or two people with experience in at least one of the following:

  • Bayesian statistics / probabilistic modeling

  • Data fusion / decision-support systems

I’d be very grateful for feedback on:

  • Whether the modeling assumptions and priors are reasonable

  • Whether the fusion steps and math are sound

  • I can share a PDF or link via DM

If you’re interested and have some time to offer a critical but constructive read, please comment here or send me a message. Thank you.


r/BayesianProgramming • • Sep 02 '25

Why is Naive Bayes considered sensitive to class imbalance? Is it primarily due to the fact that the prior probabilities are estimated from the observed class proportions in the training data?

1 Upvotes

r/BayesianProgramming • • May 05 '25

Stubborn error in rstanarm

1 Upvotes

Hi netizens. I'm running a Bayesian regression on two variables in a dataset with N=400. I have made many attempts to correct the error, but no matter what I revise in the code I receive the following error message:

Error in make_eta(prior$location, prior$what, K = K) :
location <= 1 is not TRUE

Here's my code:

#run Bayesian Regression
#specify prior assumptions
fitted.model <- stan_lm(
#Specify formula for dependent/outcome ~ independent/predictor
formula = Y ~ X,
#Specify data location
data = data
#Specify priors for intercept/Y mean and SD
prior_intercept = normal(76, 12, autoscale = FALSE),
#Specify priors for slope and SD
prior = normal(8.5, 4.25, autoscale = FALSE),
#Specify relationship between variables and standard error
prior_aux = linear(24, autoscale = FALSE)
)

In case it helps: β0 ~ N(76, 12^2); β1 ~ N(8.5, 4.25^2); σε ~ 24^2

I tried the following 'corrections' but still get the same error message. Suggestions greatly appreciated!

#converted the data to a data frame
my_data <- as.data.frame(data)



#changed from linear to exponential analysis
prior_aux = exponential(1, autoscale = FALSE)



#removed prior_aux entirely
fitted.model <- stan_lm( formula = Y ~ X, data = my_data,
prior_intercept = normal(76, 12, autoscale = FALSE), prior = normal(8.5, 4.25, autoscale = FALSE) #Removed prior_aux temporarily
)



#reduced standard deviations to prevent instability
prior_intercept = normal(76, 5, autoscale = FALSE) prior = normal(8.5, 2, autoscale = FALSE) prior_aux = exponential(1, autoscale = FALSE)



#define location of the variables in the same line as defining the formula
formula = data$Y ~ data$X

r/BayesianProgramming • • Apr 20 '25

Combination of kinetic yeast fermentation model with a black-box model to investigate effect of temperature and pH

Thumbnail reddit.com
1 Upvotes

r/BayesianProgramming • • Dec 13 '24

Does PC algorithm always find an acyclic skeleton ?

1 Upvotes

Can PC algorithm suggest a skeleton which has a cycle ?


r/BayesianProgramming • • Nov 21 '24

Math for programmers 2024 book bundle. Manning

Thumbnail reddit.com
1 Upvotes

r/BayesianProgramming • • Oct 16 '24

Continuous Bayesian network in RDS and RDA to python

1 Upvotes

Hi, I got a continuous bayesian model stored in rds and rda format. How can I transform this into python supported file such that I could work with the continuous bayesian model ?


r/BayesianProgramming • • Jul 15 '24

GPy

1 Upvotes

I'm trying to run a sequential price experiment using a Gaussian process.

When I sample the distribution, the wide credible intervals mean my preferred price is essentially random, even though the mean prediction for each price looks very intuitive.

I'm not surprised the intervals are wide as their is a lot of noise in the data since sales vary a lot


r/BayesianProgramming • • Mar 16 '24

Likelihood Function from Real Data and Model that is also Probabilistic

1 Upvotes

Disclaimer: I’m really new to all of this. While I’ve been interested in Bayesian inference for some time, I’m still at a very basic level. Also, my background is in biochemistry in microbiology, not computer science.

1.) I have data that describe the growth of a microorganism. The data is just a set of scalar values, each value corresponding to an independent experiment (mu_exp). I don’t have a lot of data (n~10). mu_exp has a mono modal distribution but probably a bit skewed. mu_exp is a “macroscopic” property of a culture of microorganisms.

2.) I have a differential equation with about a dozen parameters that describes the growth of the organism (growth equation). The parameters describe “microscopic” properties of the cell.

3.) I have a function (let’s call it “probe()” that samples the numerical solution of the growth equation in a manner that simulates the experimental process of determining mu. This function also simulates the statistical error of the measurement, and therefore gives probabilistic results. Repeated calls of “probe()” creates a vector of values mu_sim that correspond to my experimental data mu_exp.

3.) I have various pre-existing experimental data that gives me fairly good estimates for all parameters.

4.) I think that Bayesian parameter estimation would be a good approach to fit my model to my data. I have the additional data (3) which allows me to construct fairly informative priors on all my parameters. On the other hand, I don’t have sufficiently extensive data to determine the parameters without additional (prior) information.

5.) My idea so far is, to sample my parameter space to get mu_exp(parameters), fit my data to a (skewed) normal distribution to get p(mu_exp) and then use that distribution (mu_sim=mu_exp) to calculate the likelihood over my parameter space.

Here’s my problem now: When I sample the parameter space, I get a distribution of mu_sim for each set of parameters. So rather then mu_sim(parameters), what I get is really p(mu_sim)(parameters). My intuition is that the likelihood function should simply be the element-wise product of p(mu_sim)(parameters) x p(mu_exp). But I don’t know that.

There must be a “standard solution” to this problem. I think what need are the keywords to look for material on it.

So far, I have everything set up in R and am planning to use the package “brms”, in case that’s relevant.


r/BayesianProgramming • • Dec 16 '23

What does “?” Mean?

Post image
1 Upvotes

Hi I am new here, learning BayesiaLab in my grad program and had a question what the “?” Means on the node? I imported this data from an online database and almost all the nodes come out like this.

Also, are there any resources out there for how to properly upload data and run unsupervised model? I am scouring the internet and haven’t been able to find much?

TIA!


r/BayesianProgramming • • Sep 25 '23

from BMFH with yfinance

1 Upvotes

import datetime as dt

import collections

import pandas as pd

import pandas_datareader as pdr

import pandas_datareader.data as web

import pandas_datareader as pdr

import yfinance as yf

yf.pdr_override() # <== that's all it takes :-)

n_observations = 100 # we will truncate the the most recent 100 days.

tickers = ["AAPL", "TSLA", "GOOG", "AMZN"]

enddate = "2023-04-27"

startdate = "2020-09-01"

stock_closes = pd.DataFrame()

for ticker in tickers:

data = yf.download(ticker, startdate, enddate)["Close"]

stock_closes[stock] = data

picked_stock_closes = stock_closes[::-1]

picked_stock_returns = stock_closes.pct_change()[1:][-n_observations:]

dates = picked_stock_returns.index.to_list()


r/BayesianProgramming • • Apr 27 '23

VARIMA in Stan?

1 Upvotes

Does anyone have Stan code for VARIMA models? I don’t want to recreate the wheel if it exists out there somewhere.

Thank you!


r/BayesianProgramming • • Apr 18 '23

Does Anyone Use Conditional Density Estimation Models?

1 Upvotes

Hi, I'm a Data Analytics graduate student and for my last semester, I'm experimenting with a novel method of generating a continuous probability distribution P(Y|X) for Y given a vector of explanatory variables X. Since it is just a proof-of-concept both Y and X are 1-D. I'm looking for a model/architecture that I can implement in a Jupyter notebook or Google Colab environment to compare its output distributions with my experimental model's. I'm using Python, but R and Julia are not out of the question.

The two issues I am having are 1. that I don't know what is most recent or capable or advanced in this area of machine learning (HuggingFace doesn't have any), and 2. that the two models I have found - MONDE (Chilinski and Silva, 2020) and Roundtrip (Liu, et al., 2021) - are overk!ll for what I need. Are there any Bayesians out there who could point me to something practical that they have used in their jobs? And if conditional density estimators are not used in your industry, could you explain why that is the case?


r/BayesianProgramming • • Dec 20 '22

Combining plots of posterior distributions of model Parameters for two different models in R

1 Upvotes

Hi, I am stuck.

I have two separate plots showing the posterior distributions for the parameters in my models. These were created in R. What I would like to do is combine them into one plot with the posteriors for each model shown in different colours. They have the same parameters in each model. The estimates are not identical however.

This is what I have so far:

And this is the code used to create the first plot:

spread_draws(SP1, `b_.*`, regex = TRUE) %>%
  # extract all parameters that start with b_ (fixed effects)
  rename_at(vars(starts_with("b_")), function(x) str_remove(x, fixed("b_"))) %>%
  # turn to long format
  pivot_longer(cols = !c(.chain, .iteration, .draw), names_to = "par") %>%
  # get rid of parameters you don't want
  filter(par != "Intercept") %>%
  mutate(par = factor(par, levels = unique(par))) %>%
  ggplot(aes(x = value, y = fct_rev(par))) +
  stat_halfeye() +
  geom_vline(xintercept = 0, linetype = "dashed") +
  labs(x = "Posterior slope", y = NULL, title = "Figure 4a: Posterior distribution of Model parameters (ITT)") +
theme(panel.background = element_rect(fill = "white", colour = "grey50"), plot.title = element_text(hjust = 0.5))

The second plot code is identical except for the model name SP2.

The package (tidybayes) was used.


r/BayesianProgramming • • Sep 20 '22

How can I reduce the Rhat?

1 Upvotes

Hello i'm trying a model in stan, and when i run the code the Rhat have large values, so how can i reduce his values?

the R code:

library(openxlsx)
library(rstan)

options(mc.cores = parallel::detectCores())

setwd('C:/Users/osses/Desktop/A-ORIGEN-/Archivo_memoria/003_datos_FAS')

# DATA

A1<- read.xlsx(xlsxFile='uf.xlsx',sheet= 1 ,
               startRow = 1,colNames = TRUE,rowNames = FALSE)


setwd('C:/Users/osses/Desktop/A-ORIGEN-/Archivo_memoria/004_Excel_finales')


excel<- read.xlsx(xlsxFile='excel_final_noref.xlsx',sheet= 1 ,
                  startRow = 1,colNames = TRUE,rowNames = FALSE)



B<-as.matrix(A1[,-1])
Freq<-as.matrix(A1[1])

# Datos (Log[EAS])

data_y<-B[1:2,]

# data missing

N_miss_y <- sum(is.na(data_y))

miss_indy <- which(is.na(data_y), arr.ind = TRUE)

data_sin_na=data_y
data_sin_na[is.na(data_y)]=999

# Predictors


Rrup<-excel$`Rrup.calc.[km]`
I=c()
for (i in 1:length(Rrup)){
  I1=Rrup[i]
  I2=Rrup[i]
  I3=c(I1,I2)
  I=c(I,I3)
  
}



# List to STAN.

data_list <- list(N = c(8344),
                  NP = 2,
                  N_miss_y = N_miss_y,
                  miss_indy = miss_indy,
                  R=I,
                  freq=Freq[1:2],
                  Y = t(data_sin_na))

# STAN

setwd('C:/Users/osses/Desktop/A-ORIGEN-/Archivo_memoria/002_R_STAN_FILES')

Model_1 <- stan(file = "prueba_2.stan", model_name='modelito',
                data = data_list, chains = 2, iter = 500)

the STAN code:

 data {
   
   int N; // number of records
   int NP; //  number of periods
   int N_miss_y; // datos faltantes Y
   
   int miss_indy[N_miss_y, 2]; // index datos faltantes Y , fila y columna
   vector[N] R; // distances
   vector[NP] freq;
   vector[NP] Y[N];       // Data
   
 }
 
 
 parameters {
   
   real<lower=-10> c10;
   real<lower=-10> c20;
   real<lower=-10> c30;
   real<lower=-10> c11;
   real<lower=-10> c21;
   real<lower=-10> c31;
   real<lower=-10> c12;
   real<lower=-10> c22;
   real<lower=-10> c32;
   
   vector[N_miss_y] imputed_y;
   
   cholesky_factor_corr[NP] L_p;
   vector<lower=0>[NP] stdev;

 }
 transformed parameters {
   
   matrix[NP,NP] L_Sigma;
   vector[NP] y_con_imputed[N];
   
   L_Sigma = diag_pre_multiply(stdev, L_p);
   
   //Mike Lawrence's Solution.
   
   y_con_imputed = Y;
   
   for(i in 1:N_miss_y){
     
     y_con_imputed[miss_indy[i,2],miss_indy[i,1]]=imputed_y[i];
     
   }
   
 }

 model {
   
   vector[N] a0;
   vector[N] a1;
   vector[N] a2;
   vector[NP] mu_rec[N];
   
   stdev ~ cauchy(0,0.5);
   
   L_p ~ lkj_corr_cholesky(1);

   //prior

   c10 ~ normal(0.92362,0.37904);
   c20 ~ normal(-0.66292,0.41491);
   c30 ~ normal(0.63449,0.11123);
   c11 ~ normal(-1.35974,0.44268);
   c21 ~ normal(1.77347,0.48574);
   c31 ~ normal(-0.40108,0.13054);
   c12 ~ normal(0.93758,0.28134);
   c22 ~ normal(-1.04353,0.310557);
   c32 ~ normal(0.21054,0.08400);
   
   imputed_y ~ normal(0,10);

   for(f in 1:NP){
     for(i in 1:N){
       
       a0[i]=c10+c20*log10(R[i])+c30*square(log10(R[i]));
       a1[i]=c11+c21*log10(R[i])+c31*square(log10(R[i]));
       a2[i]=c12+c22*log10(R[i])+c32*square(log10(R[i]));
       
       mu_rec[i,f] = a0[i] + a1[i]*log10(freq[f]) +       a2[i]*square(log10(freq[f]));
     
     }

   }
   y_con_imputed ~ multi_normal_cholesky(mu_rec,L_Sigma); //llh   
 }

and the warning after running the code:

Warning messages:
1: There were 500 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See
https://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded 
2: Examine the pairs() plot to diagnose sampling problems
 
3: The largest R-hat is NA, indicating chains have not mixed.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#r-hat 
4: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess 
5: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#tail-ess 

if you have any suggestion, please comment or send me a dm!