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_LiGSR_explained_variance_GSP.m
    path of file: ./repos/CBIG/stable_projects/preprocessing/Li2019_GSR/VarianceComponentModel/scripts
    
    the code of the file until where you have to start completion: function CBIG_LiGSR_explained_variance_GSP(data_csv, trait_list, covariate_list, ...
    FD_file, DVARS_file, sub_list, rm_sub_list, FSM_file, outdir, ystem, m2_subdir, verbose)

% CBIG_LiGSR_explained_variance_GSP(data_csv, trait_list, covariate_list, ...
%     FD_file, DVARS_file, sub_list, rm_sub_list, FSM_file, outdir, ystem, m2_subdir)
%
% This function calls Morphometricity_1RandEffect.m (Sabuncu et al., 2016)
% to estimate the trait variance explained by RSFC for the Brain Genomics
% Superstruct Project (GSP) dataset.
% 
% Input:
%   - data_csv
%     A string. The full path of the csv file containing covariates and
%     trait data of the GSP dataset.
% 
%   - trait_list
%     A string. The full path to a text file of trait names. Each line in
%     this file corresponds to one trait. The trait names should exist as
%     headers in "data_csv".
%

    
function CBIG_LiGSR_explained_variance_GSP(data_csv, trait_list, covariate_list, ...
    FD_file, DVARS_file, sub_list, rm_sub_list, FSM_file, outdir, ystem, m2_subdir, verbose)

% CBIG_LiGSR_explained_variance_GSP(data_csv, trait_list, covariate_list, ...
%     FD_file, DVARS_file, sub_list, rm_sub_list, FSM_file, outdir, ystem, m2_subdir)
%
% This function calls Morphometricity_1RandEffect.m (Sabuncu et al., 2016)
% to estimate the trait variance explained by RSFC for the Brain Genomics
% Superstruct Project (GSP) dataset.
% 
% Input:
%   - data_csv
%     A string. The full path of the csv file containing covariates and
%     trait data of the GSP dataset.
% 
%   - trait_list
%     A string. The full path to a text file of trait names. Each line in
%     this file corresponds to one trait. The trait names should exist as
%     headers in "data_csv".
%
%   - covariate_list
%     A string. The full path to a text file containing the name of all
%     covariates. Each line corresponds to one covariate. Except for the
%     covariates FD and DVARS, all the other covariate names should exist
%     as headers in "data_csv".
%
%   - FD_file (optional)
%     A string. The full path to a text file of the mean framewise
%     displacement (FD) of all subjects. The number of lines in "FD_file"
%     should be the same as the number of lines in "sub_list". 
%     If the user would like to regress out FD, then the user should
%     include 'FD' in 'covariate_list'.
%     If the covariates do not include FD, this input variable is not
%     needed. The user can pass in 'NONE'.
% 
%   - DVARS_file (optional)
%     A string. The full path to a text file of the mean DVARS of all
%     subjects. The number of lines in "DVARS_file" should be the same as
%     the number of lines in "subject_list". 
%     If the user would like to regress out 'DVARS', then the user should
%     include 'DVARS' (or 'DV') in 'covariate_list'.
%     If the covariates do not include DVARS, this input variable is not
%     needed. The user can pass in 'NONE'.
%
%   - sub_list
%     A string. The full path of a text file containing all subject IDs.
%     Each line is one subject ID.
% 
%   - rm_sub_list (optional)
%     A string. The full path of a text file containing the subjects that
%     need to be removed from the full list (i.e. "sub_list"). This
%     argument is only necessary for jackknife samples. If the algorithm
%     runs on the full subject list, pass in 'none'.
%
%   - FSM_file
%     A string. The full path of the functional similarity matrix (FSM)
%     file (.mat). It is assumed that a #subject x #subject matrix called
%     "FSM" is saved in this file. #subjects equals to the number of lines
%     in "sub_list".
%
%   - outdir
%     A string. The full path of the output directory.
% 
%   - ystem
%     A string. The trait values will be read from "data_csv" and saved in
%     a .mat file: [outdir '/y_' ystem '.mat']. For example, if
%     "trait_list" contains 23 behavioral names, you can set 
%     ystem = '23behaviors'.
%   
%   - m2_subdir
%     A string. The subfolder name created to save the estimated "variance
%     explained" files. The "variance explained" files will be saved as 
%     [outdir '/' m2_subdir '/m2_QuantileNorm_' trait_name '.mat'] 
%     (for the traits with quantile normalization, i.e. non-binary traits), or
%     [outdir '/' m2_subdir '/m2_' trait_name '.mat'] 
%     (when the trait is NOT quantile normalized, i.e. binary trait (in our
%     case only "sex" is binary)).
% 
%   - verbose (optional)
%     0 (mute printout messages of this function) or 1 (print out every
%     message). Default is 1.
% 
% Written by Jingwei Li and CBIG under MIT license: https://github.com/ThomasYeoLab/CBIG/blob/master/LICENSE.md

addpath(fullfile(getenv('CBIG_CODE_DIR'), 'external_packages', 'matlab', 'non_default_packages', 'LME'))

if(~exist('verbose', 'var') || isempty(verbose))
    verbose = 1;
end

if(~exist(outdir, 'dir'))
    mkdir(outdir)
end

%% Read the traits from data_csv
[y_names, num_y] = CBIG_text2cell(trait_list);
quantile_norm_flag = ones(num_y, 1);
for i = 1:num_y
    if(strcmp(y_names{i}, 'Sex'))
        y_types{i} = 'categorical';
        quantile_norm_flag(i) = 0;
    else
        y_types{i} = 'continuous';
    end