Create a contingency table from data, and visualize the table in a heatmap chart.
Load the hospital data.
load hospital
The hospital dataset array contains data on 100 hospital patients, including last name, gender, age, weight, smoking status, and systolic and diastolic blood pressure measurements.
Convert the dataset array to a MATLAB® table.
Tbl = dataset2table(hospital);
Determine whether smoking status is independent of gender by creating a 2-by-2 contingency table of smokers and nonsmokers, grouped by gender.
[conttbl,chi2,p,labels] = crosstab(Tbl.Sex,Tbl.Smoker)
conttbl = 2×2
40 13
26 21
chi2 = 4.5083
p = 0.0337
labels = 2x2 cell
{'Female'} {'0'}
{'Male' } {'1'}
The rows of the resulting contingency table conttbl correspond to patient gender, with