You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: CBIG_MMLDA_glmfit_hypotest_forestplot.m
    path of file: ./repos/CBIG/stable_projects/disorder_subtypes/Sun2019_ADJointFactors/utilities/GLM
    
    the code of the file until where you have to start completion: function p_pairwise = CBIG_MMLDA_glmfit_hypotest_forestplot(k, X, y, dependency, out_dir, out_name, compare_factor_names, CI_scale, p_thresh)
% CBIG_MMLDA_glmfit_hypotest_forestplot(k, X, y, dependency, out_dir, out_name, compare_factor_names, CI_scale, p_thresh)
%
% This function will do glmfit, hypothesis tests and forest plot.
%
% Input:
%   - k                    : number of factors
%   - X                    : regressors without constant columns 1s
%   - y                    : target variable
%   - dependency           : if 'dependent' which means the factors sum to one.
%                            the X should include only include F2, F3 not F1.
%                            if 'independent' the factors are independent to each other
%                            the X should include F1, F2, F3
%   - out_dir              : out_name directory
%   - compare_factor_names : cell array. Comparison between factors, such as {'F2-F1'}
%   - CI_scale             : (optional) confidence interval scale. Default 1.96 (95% CI)
%   - p_thresh     
    
function will do glmfit, hypothesis tests and forest plot.
%
% Input:
%   - k                    : number of factors
%   - X                    : regressors without constant columns 1s
%   - y                    : target variable
%   - dependency           : if 'dependent' which means the factors sum to one.
%                            the X should include only include F2, F3 not F1.
%                            if 'independent' the factors are independent to each other
%                            the X should include F1, F2, F3
%   - out_dir              : out_name directory
%   - compare_factor_names : cell array. Comparison between factors, such as {'F2-F1'}
%   - CI_scale             : (optional) confidence interval scale. Default 1.96 (95% CI)
%   - p_thresh             : (optional) FDR p value threshold. Default 0.05.
%
% Example:
%   CBIG_MMLDA_glmfit_hypotest_forestplot(3, X, y, 'dependent', './', 'age', {'F2-F1'})
%
% Written by Nanbo Sun and CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md

if nargin < 9
    p_thresh = 0.05;
end
if nargin < 8
    CI_scale = 1.96;
end

mkdir(out_dir)

% exclude NaN and Inf in y
y_nan = y(~(isnan(y)|isinf(y)));
X_nan = X(~(isnan(y)|isinf(y)),:);

N = length(y_nan);

% out_name to console and txt file
disp(['Length of y excluding NaN and Inf:' num2str(length(y_nan))])

% fit GLM model
[b, ~, stats] = glmfit(X_nan, y_nan);

% hypo test
if strcmp(depend