Skip to content

Instantly share code, notes, and snippets.

@divyanganar
Last active May 7, 2020 12:43
Show Gist options
  • Save divyanganar/191a0732ddc0948cd1b3cb32c35f9be0 to your computer and use it in GitHub Desktop.
Save divyanganar/191a0732ddc0948cd1b3cb32c35f9be0 to your computer and use it in GitHub Desktop.
brain_age_prediction
% to organise my data and get the same variables from it
% lh_thickness_VarNames = all_data.Properties.VariableNames(82:115);
% rh_thickness_VarNames = all_data.Properties.VariableNames(119:152);
% lh_volume_VarNames = all_data.Properties.VariableNames(156:189);
% rh_volume_VarNames = all_data.Properties.VariableNames(192:225);
% lh_subcortical_VarNames = all_data.Properties.VariableNames([232,233,234,235,239,240,242]);
% rh_subcortical_VarNames = all_data.Properties.VariableNames([250,251,252,253,254,255,256]);
% lh_area_VarNames = all_data.Properties.VariableNames(8:41);
% rh_area_VarNames = all_data.Properties.VariableNames(45:78);
% lh_ventricle_VarNames = all_data.Properties.VariableNames(228);
% rh_ventricle_VarNames = all_data.Properties.VariableNames(246);
% ICV_VarNames = all_data.Properties.VariableNames(44);
% load stored PNC data
load 'C:\Users\Divyangana\Documents\PhD\Imaging\brain_age\all_VarNames_features.mat';
ads_data = readtable('C:\Users\Divyangana\Documents\PhD\Imaging\brain_age\ADS_structure_all_data.xlsx');
load 'C:\Users\Divyangana\Documents\PhD\Imaging\brain_age\PNC_all_data.mat';
pnc_thickness = [table2array(pnc_all_data(:,lh_thickness_VarNames)) + table2array(pnc_all_data(:,rh_thickness_VarNames))]/2;
pnc_volume = [table2array(pnc_all_data(:,lh_volume_VarNames)) + table2array(pnc_all_data(:,rh_volume_VarNames))]/2;
pnc_subcortical = [table2array(pnc_all_data(:,lh_subcortical_VarNames)) + table2array(pnc_all_data(:,rh_subcortical_VarNames))]/2;
pnc_area = [table2array(pnc_all_data(:,lh_area_VarNames)) + table2array(pnc_all_data(:,rh_area_VarNames))]/2;
pnc_ventricle = [table2array(pnc_all_data(:,lh_ventricle_VarNames)) + table2array(pnc_all_data(:,rh_ventricle_VarNames))]/2;
pnc_icv = table2array(pnc_all_data(:,ICV_VarNames));
pnc_features = [pnc_thickness, pnc_volume, pnc_subcortical, pnc_area, pnc_ventricle, pnc_icv];
pnc_age = table2array(pnc_all_data(:,'Age'));
ads_thickness = [table2array(ads_data(:,lh_thickness_VarNames)) + table2array(ads_data(:,rh_thickness_VarNames))]/2;
ads_volume = [table2array(ads_data(:,lh_volume_VarNames)) + table2array(ads_data(:,rh_volume_VarNames))]/2;
ads_subcortical = [table2array(ads_data(:,lh_subcortical_VarNames)) + table2array(ads_data(:,rh_subcortical_VarNames))]/2;
ads_area = [table2array(ads_data(:,lh_area_VarNames)) + table2array(ads_data(:,rh_area_VarNames))]/2;
ads_ventricle = [table2array(ads_data(:,lh_ventricle_VarNames)) + table2array(ads_data(:,rh_ventricle_VarNames))]/2;
ads_icv = table2array(ads_data(:,ICV_VarNames));
ads_features = [ads_thickness,ads_volume,ads_subcortical,ads_area,ads_ventricle,ads_icv];
ads_age = table2array(ads_data(:,'chronological_age'));
brain_age = zeros(length(ads_features),1);
gap = zeros(length(ads_features),1);
model = fitrsvm(pnc_features,pnc_age,'Standardize',true,'KernelFunction','linear');
% Fit regression to correct for bias
brain_age_pnc = predict(model, pnc_features);
gap_pnc = brain_age_pnc - pnc_age;
coeffs = glmfit(pnc_age, gap_pnc);
% Predict brain age in ADS
brain_age = predict(model,ads_features);
gap = brain_age - ads_age;
% Correct for bias using regression coefficients from training data
bias = coeffs(1) + coeffs(2)*ads_age;
gap_corrected = gap - bias;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment