unigausscp: Univariate Gaussian Conjugate Prior This function takes a...

Description Usage Arguments Value Examples

View source: R/conjugatepriors.R

Description

Univariate Gaussian Conjugate Prior This function takes a vector of proportions and iteratives over it applying a gaussian conjugate prior calculation at each point, and using the posterior as the new prior in the next iteration.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
unigausscp(
  data,
  priormean,
  priorvar,
  datavar = NULL,
  singlepoll = FALSE,
  n = NULL,
  logit = F,
  invgamma = F,
  a0 = NULL,
  b0 = NULL
)

Arguments

data

a vector of the data or a single point

priormean

mean of prior distribution

priorvar

variance of prior distribution if invgamma is not true, shift parameter for variance if invgamma is true

datavar

data variance, if null var is called to estimate it

singlepoll

if true it calculates the variance based on the sample size

n

approriate sample size

logit

if a logit transformation should be used

invgamma

a logical indicator of whether or not a inverse gamma prior for sigma is (T) or isn't included

a0

prior a if invgamma is T

b0

prior b if invgamma is T

Value

A list with the following components: priormean: the prior mean, priorvar: the prior var, a0: the prior of the inverse gamma distribution if invgamma is true, b0: the prior of the inverse gamma distribution if invgamma is true, n: which is the sample size if supplied, datavar: which is the variance of the data if it is supplied, invgamma: which states if the inverse gamma prior was used, postmean: which is the posterior mean, postvar: which is the posterior variance, postsd: which is the posterior standard deviation, posta: which is the posterior a of a inverse gamma (a,b), and postb: which is the posterior of b of a inverse gamma(a, b), and dataweight: a scalar of the weight of the data over the prior.

Examples

1
2
3
4
5
6
7
8
set.seed(10)
data1 = rnorm(30, mean = .48, sd = 0.05)
n1 = floor(runif(1, 200, 800))
datavar1 = mean(sqrt(data1[1]*(1-data1[1])/n1))
unigausscp(data1, 0.5, 0.05)
unigausscp(data1[1], 0.5, 0.05, singlepoll = TRUE, n = n1)
unigausscp(data1, 0.5, 1, invgamma = TRUE, a0 = 0.0001, b0 = 0.0001)
unigausscp(data1, 0.5, 1, logit = T, invgamma = TRUE, a0 = 0.0001, b0 = 0.0001)

balexanderstats/bayesurvey documentation built on Sept. 20, 2020, 11:40 a.m.