File: Chapter.4.2.R

package info (click to toggle)
r-cran-learnbayes 2.15.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,864 kB
  • sloc: sh: 15; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 587 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
######################################################
# Section 4.2 Normal Data with Both Parameters Unknown
######################################################

library(LearnBayes)

 data(marathontimes)
 attach(marathontimes)
 d = mycontour(normchi2post, c(220, 330, 500, 9000), time,
    xlab="mean",ylab="variance")

 S = sum((time - mean(time))^2) 
 n = length(time)
 sigma2 = S/rchisq(1000, n - 1)
 mu = rnorm(1000, mean = mean(time), sd = sqrt(sigma2)/sqrt(n))

 points(mu, sigma2)

 quantile(mu, c(0.025, 0.975))

 quantile(sqrt(sigma2), c(0.025, 0.975))