The mcmc_regression type extends the metropolis_hastings type to specifically target regression problems. The problem is formulated such that the target distribution takes the form , where is a normal distribution with as the mean and the model variance, is determined by computing the variance for the current estimate of the model.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
procedure(regression_function), | public, | pointer, nopass | :: | fcn |
The function to fit. |
||
real(kind=real64), | public, | allocatable, dimension(:) | :: | lower_limits |
An optional array that, if used, provides a lower limit to each parameter in the model. If used, be sure this array is the same dimension as the parameter array. If not used, leave this alone and no lower limits will be placed on the parameters. If used and the array is not sized correctly, it will be ignored. |
||
real(kind=real64), | public, | allocatable, dimension(:) | :: | upper_limits |
An optional array that, if used, provides an upper limit to each parameter in the model. If used, be sure this array is the same dimension as the parameter array. If not used, leave this alone and no upper limits will be placed on the parameters. If used and the array is not sized correctly, it will be ignored. |
||
real(kind=real64), | public, | allocatable, dimension(:) | :: | x |
The independent-variable data to fit. |
||
real(kind=real64), | public, | allocatable, dimension(:) | :: | y |
The dependent-variable data to fit. |
Calculates statistics for the quality of fit for the regression.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
The model parameters. Be sure to only include the model parameters. |
|
real(kind=real64), | intent(in), | optional | :: | alpha |
The significance level at which to evaluate the confidence intervals. The default value is 0.05 such that a 95% confidence interval is calculated. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
The resulting statistics for each parameter.
Evaluates the Hasting's ratio. If the proposal distribution is symmetric, this ratio is unity; however, in the case of an asymmetric distribution this ratio is not ensured to be unity.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
The current state vector. |
|
real(kind=real64), | intent(in), | dimension(size(xc)) | :: | xp |
The proposed state vector. |
The ratio.
Computes the covariance matrix for the model given the specified model parameters.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
The current set of model parameters. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
The error handling object. |
The covariance matrix.
Evaluates the proposal distribution PDF at the specified set of variables.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
The array of variables to evaluate. |
The value of the PDF at xc.
Arguments
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
The current model parameters. |
The proposed set of model parameters.
Gets the number of accepted steps.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
The number of accepted steps.
Gets a copy of the stored Markov chain.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | optional | :: | bin |
An optional input allowing for a burn-in region. The parameter represents the amount (percentage-based) of the overall chain to disregard as "burn-in" values. The value shoud exist on [0, 1). The default value is 0 such that no values are disregarded. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
The error handling object. |
The resulting chain with each parameter represented by a column.
Gets the length of the chain (number of stored state variables).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
The chain length.
Gets the variance of the observed data.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(in) | :: | this |
The mcmc_regression object. |
The variance.
Gets the Cholesky-factored (lower-triangular) form of the proposal covariance matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
The Cholesky-factored form of the proposal covariance matrix store in lower-triangular form.
Gets the covariance matrix of the proposal distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
The covariance matrix.
Gets a value determining if the proposal distribution object has been initialized.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
Returns true if the object has been initialized; else, false.
Gets the mean values of the proposal distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
An array containing the mean values.
Gets the number of state variables.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(in) | :: | this |
The metropolis_hastings object. |
The number of state variables.
Initializes the multivariate normal distribution used to generate proposals.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | mu |
An N-element array containing the mean values for the distribution. |
|
real(kind=real64), | intent(in), | dimension(:,:) | :: | sigma |
An N-by-N covariance matrix for the distribution. This matrix must be positive-definite. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Initializes the multivariate normal distribution to a mean of zero and a variance of one.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
integer(kind=int32), | intent(in) | :: | n |
The number of state variables. |
||
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Estimates the likelihood of the model.
The likelihood is computed as follows assuming is known a priori.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | x |
The current set of model parameters. |
The likelihood value.
Updates the covariance matrix of the proposal distribution upon a successful step. If overloaded, be sure to call the base method to retain the functionallity required to keep the covariance matrix up-to-date.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
integer(kind=int32), | intent(in) | :: | iter |
The current iteration number. |
||
real(kind=real64), | intent(in) | :: | alpha |
The proposal probability term used for acceptance criteria. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
The current model parameter estimates. |
|
real(kind=real64), | intent(in), | dimension(size(xc)) | :: | xp |
The recently accepted model parameter estimates. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Currently, this routine does nothing and is a placeholder for the user that inherits this class to provide functionallity upon rejection of a proposed value.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
integer(kind=int32), | intent(in) | :: | iter |
The current iteration number. |
||
real(kind=real64), | intent(in) | :: | alpha |
The proposal probabilty term used for acceptance criteria. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xc |
An N-element array containing the current state variables. |
|
real(kind=real64), | intent(in), | dimension(size(xc)) | :: | xp |
An N-element array containing the proposed state variables that were just rejected. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Pushes a new set of parameters onto the end of the chain buffer.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | x |
The new N-element state array. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Resets the object and clears out the buffer storing the chain values.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
Samples the distribution using the Metropolis-Hastings algorithm.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | xi |
An N-element array containing initial starting values of the state variables. |
|
integer(kind=int32), | intent(in), | optional | :: | niter |
An optional input defining the number of iterations to take. The default is 10,000. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
The error handling object. |
Sets the variance of the observed data.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in) | :: | x |
The variance. |
Sets the covariance matrix of the proposal distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | dimension(:,:) | :: | x |
The covariance matrix. This matrix must be positive-definite. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Sets the mean values of the proposal distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(metropolis_hastings), | intent(inout) | :: | this |
The metropolis_hastings object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | x |
The updated mean values. |
|
class(errors), | intent(inout), | optional, | target | :: | err |
An error handling object. |
Returns the probability value from the target distribution given the current set of model parameters.
The probability value is determined as follows, assuming is the function value. .
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mcmc_regression), | intent(inout) | :: | this |
The mcmc_regression object. |
||
real(kind=real64), | intent(in), | dimension(:) | :: | x |
The current set of model parameters. |
The value of the probability density function being sampled.