0% found this document useful (0 votes)
6 views1 page

Bayesian Practical 3 (Part 1) .R

The document outlines a process for generating data using a normal distribution with a specified mean and standard deviation. It includes calculations for the Bayes estimate of the mean, incorporating prior information and sample statistics. The final output is the Bayes estimate of the mean (mu_bayes).

Uploaded by

Anaya Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Bayesian Practical 3 (Part 1) .R

The document outlines a process for generating data using a normal distribution with a specified mean and standard deviation. It includes calculations for the Bayes estimate of the mean, incorporating prior information and sample statistics. The final output is the Bayes estimate of the mean (mu_bayes).

Uploaded by

Anaya Mishra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Generate data

[Link](123)
x <- rnorm(50, mean = 5, sd = 2)

# Known variance
sigma2 <- 4 # (since sd = 2)

# Prior
mu0 <- 5
tau2 <- 1

# Sample stats
n <- length(x)
xbar <- mean(x)

# Bayes estimate of mu (SELF)


mu_bayes <- ((n / sigma2) * xbar + (1 / tau2) * mu0) / ((n /
sigma2) + (1 / tau2))

mu_bayes

You might also like