##############
# Jan 6 2022
##############
# This is a simple script to make sure you have the necesary
# software and packages installed. If it runs without error,
# you are in good shape. If you do encounter an error, note
# the full text of the error you get.
##############
# load the rethinking package
library(rethinking)
# draw 10,000 random normal samples and look at them using dens()
obs <- rnorm(10e3,mean = 2,sd = 1)
dens(obs)
dens(obs,norm.comp = TRUE)
# test map() function:
# make a simple model
f <- alist(
y ~ dnorm( mu , sigma ),
mu ~ dnorm( 0 , 20 ),
sigma ~ dcauchy( 0 , 3 )
)
# fit it using maximum a posteriori / quadratic approximation
fit_quap <- quap(
f ,
data = list(y=obs) ,
start=list(mu=0,sigma=1)
)
summary(fit_quap)
# and finally, test the ulam() function
# (this should take a while to run, and will
# output some text while it does so. Be patient!)
# This fits the same model as above, using MCMC instead of MAP
fit_stan <- ulam(
f ,
data = list(y=obs)
)
summary(fit_stan)
# precis(fit_map) and precis(fit_stan) should give almost identical results
precis(fit_quap)
precis(fit_stan)