Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB has multiple built-in datasets that could be used for data processing and

ID: 2080311 • Letter: M

Question

MATLAB has multiple built-in datasets that could be used for data processing and analysis. One of those datasets is "hospital.mat" which contains simulated hospital data. Run the following snippet code to load the data and get enveloping information about the fields in the data. load hospital summary(hospital) Your goals in this problem are to write MATLAB codes to: Obtain the number of male patients and the number of female patients in the dataset. Compare your results to the ones obtained when you run "summary(hospital)". Obtain the number of smokers and non-smokers in the dataset. Again compare your results to the ones obtained when you run "summary(hospital)". Compute the average age of the female patients and the average age of the male patients. Compute the average weight of the female patients and the average weight of the male patients. Compute the average weight for the female patients that are smoker and have an age below 45. Compute for each patient the mean of the number of trials and add the results to the table with a column header of Mean_Trials. For the patients that have missing number of trials, replace the NaN values with 0. A blood pressure less than 120/80 mmHg is normal. A blood pressure of 140/90 mmHg or more is too high. People with levels in between 120/80 and 140/90 have a condition called prehypertension, which means they are at high risk for high blood pressure. Given this information, how many patients in the provided data have a normal blood pressure, a too high blood pressure, or have the prehypertension condition? Compute the average blood pressure for the smoker and non-smoker patients. Which group is the healthiest? Justify your answer.

Explanation / Answer

%%%%% for perfect execution without altering anything simply copy and paste in a new edit in matlab.

clc;
clear all;
close all;

load hospital.mat;
hospital = sortrows(hospital,{'Sex'}); %%% sorting the loaded dataset into males and females.
Male = hospital(hospital.Sex=='Male',:); %%%% extracting only male pateints and putting in separate variable "male"
Female=hospital(hospital.Sex=='Female',:);%%% variable consisting only female
smokers = hospital(hospital.Smoker==true,:);%% variable consisting only smokers
Male_Avg_age = mean(double(Male(:,3)));%%% Mean of age of males
Female_Avg_age = mean(double(Female(:,3)));%%% Mean of age of females
Male_Avg_weight = mean(double(Male(:,4)));%%% average weight of males
Female_Avg_weight = mean(double(Female(:,4))); %% average weight of females
Female_less_than_45_and_smoker= hospital(hospital.Sex=='Female' & hospital.Age < 45 & hospital.Smoker==true,:);%%%% extracting only female pateints <45 age and are smokers and putting in separate variable
f_s_av_wt=mean(double(Female_less_than_45_and_smoker(:,4))); %%% average of the age of female <45 age and smokers.
non_smokers = hospital(hospital.Smoker==false,:);
hospital.SysPressure = hospital.BloodPressure(:,1);%%% separating systolic blood pressure and diastolic blood pressure in different columns
hospital.DiaPressure = hospital.BloodPressure(:,2);
Normal=hospital(hospital.SysPressure <= 120 & hospital.DiaPressure <= 80,:); %%% normal pateint with 120/80
Prehypertension=hospital(hospital.SysPressure > 120 & hospital.DiaPressure > 80,:); %%hypertension pateint with above 120/80
Avg_blood_smokers = mean(double(smokers(:,6)));%%% average blood pressure of smokers
Avg_blood_nonsmokers = mean(double(non_smokers(:,6)));%%% average blood pressure of non smokers
%%%%%%%%% Smokers risk is more a their average blood pressure lies between
%%%%%%%%% 120/80 and 140/90