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

File: <base>/sources/reko.kemppainen_at_gmail.com/entry9/calculate_mean.m (2,412 bytes)
function means= calculate_mean(times,values,names,category,T)

tot_params=max(size(category));
file_params=max(size(names));

means=zeros(1,tot_params) + NaN;

for param_idx=1:file_params
    found_idx=strcmp(names(param_idx),category);
    if max(found_idx)==1 && ~strcmp(names(param_idx),'Urine')
        means(found_idx)=mean(values{param_idx}(times{param_idx} >= T(1) & times{param_idx} <= T(2)));
        limits=get_param_limits_by_name(names{param_idx});
        
        if  means(found_idx) < limits(1) ||  means(found_idx)>limits(2)
             means(found_idx)=NaN;
        end
%     elseif max(found_idx)==1 && strcmp(names(param_idx),'MechVent')
%           means(found_idx)=mode(values{param_idx}(times{param_idx} >= T(1) & times{param_idx} <= T(2)));
%           limits=get_param_limits_by_name(names{param_idx});
%           % non existent parameter value is set to 0 (no mechanical ventilation)
%           if isnan(means(found_idx))
%               means(found_idx)=0;
%           end
%         
%         if  means(found_idx) < limits(1) ||  means(found_idx)>limits(2)
%              means(found_idx)=NaN;
%         end
%         
%         
    elseif max(found_idx)==1 && strcmp(names(param_idx),'Urine')
        %For Urine output, get cumulative         
        urine_=values{param_idx}(times{param_idx} >= T(1) & times{param_idx} <= T(2));
        dt=diff(times{param_idx}(1:length(urine_)));
        
        if length(urine_)==0
            means(found_idx)=NaN;
        elseif length(urine_)==1
            means(found_idx)=NaN;
        else
            
            TOT_TIME=times{param_idx}(length(urine_))-times{param_idx}(1);
            speed=urine_(2:end)./dt;
            cumulative_urine=sum(speed.*dt);            
            means(found_idx)= TOT_TIME/(24*60)*cumulative_urine;
            
%             if cumulative_urine > 8000
%                 figure(1); plot(dt,speed,'*');
%                 pause(.1)
%             end
        end
        
        limits=get_param_limits_by_name('Urine');
        
        if  means(found_idx) < limits(1) ||  means(found_idx)>limits(2)
             means(found_idx)=NaN;
        end

    end
    
    
end


%NaN's on mechancal ventilation boolean are set to zero

if isnan(means(strcmp(category,'MechVent')))
    means(strcmp(category,'MechVent'))=0;
end


end