Main Content

将数据分成组并计算统计数据

此示例显示了如何从中划分数据patients.mat数据文件到组。然后它显示如何计算患者组的平均重量和体重指数,以及血压读数的差异。它还显示了如何总结表中的结果。

加载患者数据

加载来自100名患者收集的样品数据。

加载patients

转变性别andS.elfAssessedHealthStatus分类阵列。

性别=分类(性别);selfassessedhealthstatus =分类(Selfassessedhealthstatus);谁是
名称大小字节类属性年龄100x1 800双舒张100x1 800双重性别100x1 330分类高度100x1 800 double lastname 100x1 11616电池位置100x1 14208细胞selfassessedhealthstatus 100x1 560分类吸烟者100x1 100逻辑收缩100x1 800双重重量100x1 800双倍

Calculate Mean Weights

使用患者将患者分成不闻名者和吸烟者吸烟者多变的。计算每组的平均重量。

[g,吸烟者] = findgroups(吸烟者);含义= splitapply(@均值,重量,g)
含义=2×1149.9091 161.9412

findgroups.函数返回G,从中创建的组号码的向量吸烟者。这splitapplyfunction usesG分开重量分为两组。splitapply适用于mean每个组的功能并将平均重量连接到向量中。

findgroups.returns a vector of group identifiers as the second output argument. The group identifiers are logical values because吸烟者包含逻辑值。第一组的患者是非助手,第二组患者是吸烟者。

吸烟者
吸烟者=2x1逻辑阵列0 1

通过性别和身份作为吸烟者将患者的重量分成并计算平均重量。

g = findgroups(性别,吸烟者);含义= splitapply(@均值,重量,g)
含义=4×1130.3250 130.9231 180.0385 181.1429

跨越的独特组合性别and吸烟者鉴定四组患者:女性非吸烟者,女性吸烟者,雄性不闻商和男性吸烟者。总结一下表中的四个群体及其平均重量。

[g,性别,吸烟者] = findgroups(性别,吸烟者);T = table(gender,smoker,meanWeight)
t =4×3表gender smoker meanWeight ______ ______ __________ Female false 130.32 Female true 130.92 Male false 180.04 Male true 181.14

T.gender包含分类值,和T.Smoker.包含逻辑值。这些表变量的数据类型匹配数据类型性别and吸烟者分别。

Calculate body mass index (BMI) for the four groups of patients. Define a function that takesHeightand重量作为其两个输入参数,并计算bmi。

meanBMIfcn = @(h,w)mean((w ./ (h.^2)) * 703); BMI = splitapply(meanBMIfcn,Height,Weight,G)
BMI =4×121.6721 21.6686 26.5775 26.4584

基于自我报告的患者

Calculate the fraction of patients who report their health as either贫穷的orFair。首先,使用splitapply计算每组患者的数量:女性非吸烟者,女吸烟者,男性非闻名者和男性吸烟者。然后,只计算那些报告健康的患者贫穷的orFair那using logical indexing onS.andG。From these two sets of counts, calculate the fraction for each group.

[g,性别,吸烟者] = findgroups(性别,吸烟者);s = selfassessedhealthstatus;我= ismember(s,{'Poor''公平的'});numpatients = sclustapply(@ numel,s,g);numpf = sclustapply(@ numel,s(i),g(i));numpf./numpatients.
ANS =.4×10.2500 0.3846 0.3077 0.1429

比较标准偏差Diastolic报告的患者的读数贫穷的orFairhealth, and those patients who report好的orExcellent健康。

stddiastolicpf = scletapply(@ std,舒张(i),g(i));stddiastolicge = splitapply(@ std,舒张(~i),g(〜i));

收集表格中的结果。对于这些患者来说,报告的女性非闻名贫穷的orFair健康表明血压读数最广泛的变化。

T = table(gender,smoker,numPatients,numPF,stdDiastolicPF,stdDiastolicGE,BMI)
t =4×7表性别吸烟者Numpatiants NumPF StddiaStolicpf StddiaStolicge BMI __________________ __________________女性假40 10 6.8872 3.9012 21.672男性False 21 4.269男性真假26 8 4.2678 4.8159 26.578男性True 21 3 5.6862 5.258 26.458

也可以看看

|

Related Topics