nvaricp               package:Bolstad               R Documentation

_B_a_y_e_s_i_a_n _i_n_f_e_r_e_n_c_e _f_o_r _a _n_o_r_m_a_l _s_t_a_n_d_a_r_d _d_e_v_i_a_t_i_o_n _w_i_t_h _a _s_c_a_l_e_d
_i_n_v_e_r_s_e _c_h_i-_s_q_u_a_r_e_d _d_i_s_t_r_i_b_u_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Evaluates and plots the posterior density for sigma, the standard
     deviation of a Normal distribution where the mean mu is known

_U_s_a_g_e:

     nvaricp(y, mu, S0, kappa, cred.int = FALSE, alpha = 0.05, ret = FALSE)

_A_r_g_u_m_e_n_t_s:

       y: a random sample from a normal(mu,sigma^2) distribution.

      mu: the known population mean of the random sample.

      S0: the prior scaling factor.

   kappa: the degrees of freedom of the prior.

cred.int: if TRUE then a 100(1-alpha) percent credible interval will be
          calculated for sigma

   alpha: controls the width of the credible interval. Ignored if
          cred.int is FALSE

     ret: if true then the likelihood and posterior are returned as a
          list.

_V_a_l_u_e:

     If ret is true, then a list will be returned with the following
     components:

   sigma: the vaules of sigma for which the prior, likelihood and
          posterior have been calculated

   prior: the prior density for sigma

likelihood: the likelihood function for sigma given y

posterior: the posterior density of sigma given y

      S1: the posterior scaling constant

  kappa1: the posterior degrees of freedom

_E_x_a_m_p_l_e_s:

     ## Suppose we have five observations from a normal(mu, sigma^2)
     ## distribution mu = 200 which are 206.4, 197.4, 212.7, 208.5.
     y<-c(206.4, 197.4, 212.7, 208.5, 203.4)

     ## We wish to choose a prior that has a median of 8. This happens when
     ## S0 = 29.11 and kappa = 1
     nvaricp(y,200,29.11,1)

     ##  Same as the previous example but a calculate a 95% credible
     ## interval for sigma
     nvaricp(y,200,29.11,1,cred.int=TRUE)

     ##  Same as the previous example but a calculate a 95% credible
     ## interval for sigma by hand
     results<-nvaricp(y,200,29.11,1,cred.int=TRUE,ret=TRUE)
     attach(results)
     cdf<-sintegral(sigma,posterior,ret=TRUE)
     Finv<-approxfun(cdf$y,cdf$x)
     lb<-Finv(0.025)
     ub<-Finv(0.975)
     cat(paste("95% credible interval for sigma: [",
                   signif(lb,4),", ", signif(ub,4),"]\n",sep=""))

