function [risk,prediction]=physionet2012(time,param,value) % [risk,prediction]=physionet2012(time,param,value) % % Sample Submission for the PhysioNet 2012 Challenge. Variables are: % % time - (Nx1 Cell Array) Cell array containing time of measurement % param - (Nx1 Cell Array) Cell array containing type (param) of % measurement % value - (Nx1 Double Array) Double array containing value of measurement % % % risk - (Scalar) estimate of the risk of the patient dying in hospital % prediction - (Logical)Binary classification if the patient is going to die % in the hospital (1 - Died, 0 - Survived) % % Example: % [risk,prediction]=physionet2012(time,param,value) % TH=0.2700; TH_SAPS=0.3900; B=[ 1.4037238316e+00; -8.1833389095e-02; -2.4939330155e-02; -1.5119424507e-02; 2.7833454606e-02; -1.4908319274e-02; 1.2317990562e-02; 1.0654354558e-02; 5.6335820205e-02; 2.0570191510e-01; -2.7707893188e-01; 4.0909316076e-04; -1.7088353456e-04; -5.4632240876e-03; 5.3569006748e-03; 1.2035782695e-02; -4.1221677189e-02]; B_saps=[ 4.8341800475e+00; 2.1514309096e-01; -2.3846361213e-01; ]; I=1; i=1; [ALL_CATEGORIES,time_series_names,descriptors]=get_param_names(); num_params=length(ALL_CATEGORIES); num_ts_params=length(time_series_names); num_descriptors=length(descriptors); MEAN_DATA_24=zeros(I,num_ts_params) + NaN; MEAN_DATA_48=zeros(I,num_ts_params) + NaN; DESCRIPTORS=zeros(I,num_descriptors) + NaN; [times,values,names]=extract_param_series(time,param,value); [ts_times,ts_values,ts_names]=get_param_subset(time_series_names,times,values,names); [des_times,des_values,des_names]=get_param_subset(descriptors,times,values,names); DESCRIPTORS(i,:)=cell2mat(des_values(:))'; means24=calculate_mean(ts_times,ts_values,ts_names,time_series_names,[0 24*60]); means48=calculate_mean(ts_times,ts_values,ts_names,time_series_names,[24*60 48*60]); MEAN_DATA_24(i,:)=means24; MEAN_DATA_48(i,:)=means48; score=saps_score(time,param,value,1,[0 24]); if isempty(score) SAPS_SCORES(i)=NaN; else SAPS_SCORES(i)=score; end score=saps_score(time,param,value,1,[24 48]); if isempty(score) SAPS_SCORES_48(i)=NaN; else SAPS_SCORES_48(i)=score; end X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'HCO3'))-MEAN_DATA_48(:,strcmp(time_series_names,'HCO3'))]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'HCO3')) X_Test]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'Glucose'))-MEAN_DATA_48(:,strcmp(time_series_names,'Glucose')) X_Test ]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'Glucose')) X_Test]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'Urine'))-MEAN_DATA_48(:,strcmp(time_series_names,'Urine')) X_Test ]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'Urine')) X_Test]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'GCS'))-MEAN_DATA_48(:,strcmp(time_series_names,'GCS')) X_Test ]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'GCS')) X_Test]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'Na'))-MEAN_DATA_48(:,strcmp(time_series_names,'Na')) X_Test ]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'Na')) X_Test]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'HR'))-MEAN_DATA_48(:,strcmp(time_series_names,'HR')) X_Test ]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'HR')) X_Test]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'BUN'))-MEAN_DATA_48(:,strcmp(time_series_names,'BUN')) X_Test ]; X_Test=[MEAN_DATA_24(:,strcmp(time_series_names,'BUN')) X_Test]; X_Test=[DESCRIPTORS(:,strcmp(des_names,'Age')) X_Test]; X_Test=[DESCRIPTORS(:,strcmp(des_names,'ICUType')) X_Test]; PHAT = mnrval(B,X_Test); if isnan(PHAT(:,2)) X_trunc_saps=[SAPS_SCORES-SAPS_SCORES_48 SAPS_SCORES ]; PHAT_saps = mnrval(B_saps,X_trunc_saps); end if isnan(PHAT(2)) risk=PHAT_saps(2); prediction=risk>TH_SAPS; elseif PHAT(2)<0.01 risk=0.01; prediction=risk>TH; elseif PHAT(2)>0.99 risk=0.99; prediction=risk>TH; else risk=PHAT(2); prediction=risk>TH; end