%TLASSO_NEGLL Compute the negative log-likelihood for a t-regression model
% Users should refer to the 'tlasso' function to use this software.
function L = tlasso_negll(X, y, b0, b, sigma2, nu)

k = 1;
n = length(y);
mu = b0 + X*b;
e2 = (y - mu).^2 / sigma2;
L = n/2*log(sigma2)  - n*gammaln((nu+k)/2) + n*k*gammaln(0.5) + n*gammaln(nu/2) + n*k/2*log(nu);
L = L + (nu + k)/2 * sum(log(1 + e2/nu));

return