Learn R Programming

HelpersMG (version 2026.3.31)

setPriors1: Set priors for MHalgoGen()

Description

Set priors for MHalgoGen()
A check is done to verify that the Init value is well between the Min and Max range.
The order of Prior1, 2, and 3 must be similar to the order in the Density function. For this reason, it is safer to use Parameters.
As a rule of thumb, SDProp can be 1/10th of the range of posterior. For example if the posterior is thought to be from 0.1 to 0.2, you can use SDProp being (0.2-0.1)/10=0.01.

Usage

setPriors1(
  Name = stop("A name of parameter is required."),
  Prior1 = NULL,
  Prior2 = NULL,
  Prior3 = NULL,
  Parameters = NULL,
  Density = stop("A density is required."),
  SDProp = stop("A SD of proposal is required."),
  Min = -Inf,
  Max = +Inf,
  Init = stop("An initial value is required.")
)

Value

Return a data.frame with the formatted prior

Arguments

Name

Name of the parameter.

Prior1

The value for the first parameter of the prior distribution.

Prior2

The value for the second parameter of the prior distribution.

Prior3

The value for the third parameter of the prior distribution.

Parameters

A vector with parameters of the prior distribution

Density

The density function of the prior (ex. "dunif", "dnorm", "dbeta").

SDProp

The SD of the propositions for the Markov chain.

Min

The minimum value to truncate the prior distribution.

Max

The maximum value to truncate the prior distribution.

Init

The value at the first iteration.

Author

Marc Girondot marc.girondot@gmail.com

Details

setPriors1 is a general function to set priors for MHalgoGen()

See Also

Other mcmcComposite functions: +.PriorsmcmcComposite(), MHalgoGen(), as.mcmc.mcmcComposite(), as.parameters(), as.quantiles(), merge.mcmcComposite(), plot.PriorsmcmcComposite(), plot.mcmcComposite(), setPriors(), summary.mcmcComposite()

Examples

Run this code
if (FALSE) {
library(HelpersMG)
Priors <- setPriors1(Name="a0", Prior1=0, Prior2=1, Density="dunif", 
                     SDProp=0.1, Min=0, Max=1, Init=0.5)
Priors <- Priors + setPriors1(Name="a1", Prior1=0.5, Prior2=0.1, Density="dnorm", 
                     SDProp=0.05, Min=0, Max=1, Init=0.5)
# Using Parameters
Priors <- setPriors1(Name="a0", Parameters=c(min=0, max=1), Density="dunif", 
                     SDProp=0.1, Min=0, Max=1, Init=0.5)
Priors <- Priors + setPriors1(Name="a1", Parameters=c(mean=0.5, sd=0.1), Density="dnorm", 
                     SDProp=0.05, Min=0, Max=1, Init=0.5)
}

Run the code above in your browser using DataLab