Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/statistics.r

View File Source Download File No help file available

Function: Gibbs.normalmean

Function Description: Gibbs.normalmean

The standard Gibbs sampler for a normal distribution with unknown mean and variance.

Function Arguments:

ArgumentDefault Value
y
sigma

Arguments Description:

y is the vector of observations
sigma is the latest draw of the SD, using sqrt(Gibbs.normalvar)


Function Source:

Gibbs.normalmean=function(y,sigma)
{
y=y[!is.na(y)]
if(sd(y)==0 | length(y)==1) return(mean(y))

samplemean=mean(y)
n=length(y)

return(rnorm(1,mean=samplemean,sd=sqrt(sigma^2/n)))
}