Predicting Mortality of ICU Patients: The PhysioNet/Computing in Cardiology Challenge 2012 1.0.0

File: <base>/sources/alistairewj_at_gmail.com/entry1/pniExtractFeaturesB.m (3,435 bytes)
function [ X ] = pniExtractFeaturesB(data)
%PNIANDREW	Andrew's initial entry - severity of illness score
%	[ score ] = pniAndrew(data) calculates a severity of illness score for
%	each row (observation) in data
%
%   The score uses the following variables:
%		urine, platelets, BUN, creatinine, PaFi ratio, PaO2, PaCO2, pH,
%       heart_rate, temperature, BP, and age.
%
%	Inputs:
%		data    - Cell array of data.
%           Column 1 - Subject IDs
%           Column 2 - Time stamp vectors for each subject
%           Column 3 - Feature name vectors for each subject
%           Column 4 - Data value vectors for each subject
%
%	Outputs:
%		score   - Column vector of severity scores
%
%	Example
%       %=== Load data in
%       load('data_processed_cell.mat');
%
%       %=== Calculate score
%       [ score ] = pniAndrew(data);
%
%	See also PNMAIN PNPREPROCESSDATA

%	References:
%       Physionet Challenge 2012
%       http://physionet.org/challenge/2012/
%
%       APACHE III (1991)
%       Knaus WA, Wagner DP, Draper EA, Zimmerman JE, Bergner M,
%       Bastos PG, Sirio CA, Murphy DJ, Lotring T, Damiano A, et al.
%       The APACHE III prognostic system. Risk prediction of hospital
%       mortality for critically ill hospitalized adults.
%       Chest 100(6):1619-1636 (1991 Dec).

%	Copyright 2012 Alistair Johnson and Andrew Kramer

%	$LastChangedBy: alistair $
%	$LastChangedDate: 2012-04-24 22:39:24 +0100 (Tue, 24 Apr 2012) $
%	$Revision: 342 $
%	Originally written on GLNXA64 by Alistair Johnson, 15-Apr-2012 14:39:14
%	Contact: alistairewj@gmail.com



N = size(data,1);

%=== Generate labels
header1={'BUN','Creatinine','GCS',...
    'Glucose','HCO3','HCT','HR','NIDiasABP','NIMAP','NISysABP',...
    'RespRate','Temp','Urine','WBC',...
    'Weight',...
    'PaCO2','PaO2','pH'};
header2={'Age','Gender','Height','K',...
    'Mg','Na',...
    'Platelets',...
    'MechVent'}; % last values
header3={'PaFi','PaC2'};

%=== Pre-allocate
X.last = nan(N,numel(header1));
X.total = nan(N,numel(header1));
X.median = nan(N,numel(header1));
X.maximum = nan(N,numel(header1));
X.minimum = nan(N,numel(header1));

for k=1:numel(header1)
    temp = pnExtractField(data,header1{k});
    idxEmpty = ~cellfun(@isempty,temp(:,4));
    X.last(idxEmpty,k) = cellfun(@(x) x(end), temp(idxEmpty,4));
    X.total(idxEmpty,k) = cellfun(@(x) numel(x), temp(idxEmpty,4));
    X.median(idxEmpty,k) = cellfun(@(x) median(x), temp(idxEmpty,4));
    X.maximum(idxEmpty,k) = cellfun(@(x) max(x), temp(idxEmpty,4));
    X.minimum(idxEmpty,k) = cellfun(@(x) min(x), temp(idxEmpty,4));
end

%=== Combine into one data matrix
X = [X.last,X.total,X.median,X.maximum,X.minimum];



last = nan(N,numel(header2));

for k=1:numel(header2)
    temp = pnExtractField(data,header2{k});
    idxEmpty = ~cellfun(@isempty,temp(:,4));
    last(idxEmpty,k) = cellfun(@(x) x(end), temp(idxEmpty,4));
end

X = [X,last];

additional = nan(N,numel(header3));

for k=1:numel(header3)
    if strcmp(header3{k},'PaFi')
        temp = pnPaFi(data);
    else
        temp = pnPaC2(data);
    end
    idxEmpty = ~cellfun(@isempty,temp(:,4));
    additional(idxEmpty,k) = cellfun(@(x) x(end), temp(idxEmpty,4));
end

X = [X,additional];

%=== Add in severity score/day difference
[ X1 ] = pniAndrew(data);
[ X2 ] = pniLouis(data);

X = [X,X1,X2];

end