我的数据集中有两列:Health
和Weight
,它们都是数字类型的:
Health<-number of days when health is not good,
Weight<-weight
我只想检查一下健康和体重之间是否有关系。换句话说,Weight
的增加会增加Health
不好的天数还是相反的天数?我只想通过绘制一些图表来检查dataset中这两列之间的关系。
这里是我的样本数据集:
| Health | Weight |
|:-----------|------------:|
| 0 | 30 |
| 3 | 63 |
| 2 | 31 |
| 10 | 169 |
| 1 | 9 |
|0 | 139 |
发布于 2017-10-25 17:50:32
你可以用“健康”向量来做一个分类变量(例如,2-bin将是“高”和“低”的中间分裂,3-bin将是“高”、“中”和“低”等等的梯田),然后对每个垃圾箱做“重量”的方格图。你可能会发现,“低”和“高”是不同的。您选择的回收箱数量取决于“Health”变量的分布,您可以使用它。
library(dplyr) # for modifying datasets
library(ggplot2) # for plotting
library(magrittr) # for piping
stackodato <- data.frame("Health" = sample(0:10, 10), "Weight" = sample(0:200, 10)) # creating a pseudo dataset
stackodato %>%
mutate(binnedHealth = factor(dplyr::ntile(Health, 2), labels=c("low", "high"))) %>% # add "binnedHealth" column which has the "Health" variable categorized into two factors : "high" and "low"
ggplot()+geom_boxplot(aes(x=binnedHealth, y=Weight)) # boxplot showing the distribution of "Weight" split by the "binnedHealth" factor
您也可以尝试这样做:
stackodato %>% mutate(binnedHealth = factor(dplyr::ntile(Health, 2), labels=c("low", "high"))) %>% ggplot()+geom_boxplot(aes(x=Health, y=Weight, group = binnedHealth))
发布于 2016-08-20 10:28:16
我支持阿伦·阿尼扬的回答。通过计算Pearson的相关系数,看看这两个特征是如何相互关联的。另一种选择是通过绘制散点图来可视化数据。
发布于 2016-08-20 09:26:49
您可以对数据执行无监督的聚类(k-均值),这将给您的关系,如体重的人,其健康状况不好的特定天数。
https://datascience.stackexchange.com/questions/13564
复制相似问题