Home > . > posterior_moments.m

posterior_moments

PURPOSE ^

stephane.adjemian@ens.fr [09-09-2005]

SYNOPSIS ^

function [post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(xx,info)

DESCRIPTION ^

 stephane.adjemian@ens.fr [09-09-2005]
 Computes posterior mean, median, variance, HPD interval, deciles, and density from posterior draws.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(xx,info)
0002 % stephane.adjemian@ens.fr [09-09-2005]
0003 % Computes posterior mean, median, variance, HPD interval, deciles, and density from posterior draws.
0004 global options_
0005 
0006 xx = xx(:);
0007 xx = sort(xx);
0008 
0009 
0010 post_mean = mean(xx);
0011 post_median = median(xx);
0012 post_var = var(xx);
0013 
0014 n = length(xx);
0015 m = round((1-options_.mh_conf_sig)*n);
0016 k = zeros(m,1);
0017 jj = n-m;
0018 for ii = 1:m
0019   k(ii) = xx(jj)-xx(ii);
0020   jj = jj + 1;
0021 end
0022 [kmin,idx] = min(k);
0023 hpd_interval = [xx(idx) xx(idx)+kmin];
0024 
0025 post_deciles = xx([round(0.1*n) ...
0026        round(0.2*n)...
0027        round(0.3*n)...
0028        round(0.4*n)...
0029        round(0.5*n)...
0030        round(0.6*n)...
0031        round(0.7*n)...
0032        round(0.8*n)...
0033        round(0.9*n)]);
0034 
0035 if ~info
0036   density = [];
0037 else
0038   number_of_grid_points = 2^9;      % 2^9 = 512 !... Must be a power of two.
0039   bandwidth = 0;                    % Rule of thumb optimal bandwidth parameter.
0040   kernel_function = 'gaussian';     % Gaussian kernel for Fast Fourrier Transform approximaton.
0041   optimal_bandwidth = mh_optimal_bandwidth(xx,length(xx),bandwidth,kernel_function);
0042   [density(:,1),density(:,2)] = kernel_density_estimate(xx,number_of_grid_points,optimal_bandwidth,kernel_function);
0043 end

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003