betaGetShapes: Convert beta mean and precision parameters to two shape...

Description Usage Arguments Details Value Examples

View source: R/betaGetShapes.R

Description

Convert beta mean and precision parameters to two shape parameters

Usage

1
betaGetShapes(mean, precision)

Arguments

mean

The mean of a beta distribution

precision

The precision parameter (phi) of a beta distribution

Details

In simstudy, users specify the beta distribution as a function of two parameters - a mean and precision, where 0 < mean < 1 and precision > 0. In this case, the variance of the specified distribution is (mean)*(1-mean)/(1+precision). The base R function rbeta uses the two shape parameters to specify the beta distribution. This function converts the mean and precision into the shape1 and shape2 parameters.

Value

A list that includes the shape parameters of the beta distribution

Examples

1
2
3
4
5
6
7
8
9
set.seed(12345)
mean = 0.3; precision = 1.6
rs <- betaGetShapes(mean, precision)
c(rs$shape1, rs$shape2)
vec <- rbeta(1000, shape1 = rs$shape1, shape2 = rs$shape2)
(estMoments <- c(mean(vec), var(vec)))
(theoryMoments <- c(mean, mean*(1-mean)/(1+precision)))
(theoryMoments <- with(rs, c(shape1/(shape1 + shape2), 
  (shape1*shape2) / ((shape1 + shape2)^2*(1 + shape1 + shape2)))))

kgoldfeld/simstudy documentation built on Nov. 8, 2018, 7:41 p.m.