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: metrop1step.discrete

Function Description: metrop1step.discrete

A version for metrop1step where the alternative values are character states with no numeric meaning. A random draw must be taken from all possible states, each with equal probability. There is no step-size thus no adjustment.

Function Arguments:

ArgumentDefault Value
func
start.param
alter.param
...

Function Source:

metrop1step.discrete=function(func,start.param,alter.param,...)
{
origlike=func(start.param,...)

r=sample(x=1:length(alter.param),size=1)
newval=alter.param[r]
newlike=func(newval,...)

if(is.na(newlike)) browser()

likeratio=exp(newlike-origlike)
# if(is.na(likeratio)) browser()

if(runif(1) {
newscale=NULL
return(c(newval,newscale,1,newlike,origlike,newval))
}
else
{
newscale=NULL
return(c(start.param,newscale,0,origlike,newlike,newval))
}

}