%calculate marginal likelihoods for the wage 
%data example. 

clear;
clc;
cd ..
cd datasets;
load wages.txt;
cd ..
cd solutions;
wage = wages(:,1);
ed = wages(:,2);
y = log(wage);
nobs = length(y);
X = [ones(nobs,1)];

nu = 6;
lambda = (2/3)*.2;
V_beta = 1.0e100*eye(size(X,2));

Sigma = lambda*(eye(nobs) + X*V_beta*X');
invSigma = inv(lambda)*(eye(nobs) - X*inv(inv(V_beta) + X'*X)*X');
detsigma = det(V_beta)*det(inv(V_beta) + X'*X); %don't put lambda term in here, put in it normcons_ln below

normcons_ln = (nu/2)*log(nu) + gammaln( (nobs + nu)/2 ) - (nobs/2)*log(pi) - gammaln(nu/2) - (nobs/2)*log(lambda);
detln = -.5*log(detsigma);
kernel = - ( (nobs + nu)/2 ) * log ( nu + y'*invSigma*y );
log_ml = normcons_ln + detln + kernel