I have two columns in my dataset: Health and Weight, both being of numeric type:

    Health<-number of days when health is not good,

All I want to check if there is a relationship between Health and Weight. In other words, does a Weight increase yield an increase of the number of days where Health is not good, or the converse? I just want to check the relation between those two columns in dataset by plotting some graphs.

Here my sample dataset:

| Health     | Weight      | 
| 0          |      30     |        
| 3          |      63     |        
| 2          |      31     |          
| 10         |      169    |            
| 1          |      9      |    
|0           |     139     |   
  • $\begingroup$ What have you tried? Something as simple as plotting one against the other? plot(newdata$Weight, newdata$Health)? $\endgroup$ – Spacedman Aug 20 '16 at 12:50
  • $\begingroup$ @Sumanth Sharma I have somehow rephrased your question. I hope I have kept your initial goals $\endgroup$ – Laurent Duval Aug 20 '16 at 12:51
  • $\begingroup$ Also, I'd call your "Health" variable "Sickness" or "BadHealth", because the larger the value, the less healthy the subject is. $\endgroup$ – Spacedman Aug 20 '16 at 16:02
  • $\begingroup$ @Spacedman, i used the above thing which you said but as it is very big data base i can see the exact picture. How the graph is floating. $\endgroup$ – Sumanth Sharma Aug 20 '16 at 17:20
  • $\begingroup$ How many points? This would be useful information to edit into your question. $\endgroup$ – Spacedman Aug 21 '16 at 14:31

I second Arun Aniyan's answer. Look at how the two features are related to each other by computing Pearson's correlation coefficient. Another option would be to visualize your data by plotting a scatterplot



You could bin the 'Health' vector to make a categorical variable (ideally consisting of similar number of observations, for example : 2-bin would be median-split of 'high' and 'low', 3-bin would be tertiles of 'high', 'medium' and 'low', and so on), and then do box plots of 'Weight' per bin. You might see that the bin of 'low' is different from the bin of 'high'. The number of bins you choose depends on the distribution of the 'Health' variable and you can play around with that.


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

Boxplot of median-split Health - x-axis is binned Health

You can also try this :

stackodato %>% mutate(binnedHealth = factor(dplyr::ntile(Health, 2), labels=c("low", "high"))) %>% ggplot()+geom_boxplot(aes(x=Health, y=Weight, group = binnedHealth))

Boxplot of median-split Health - x-axis is Health


You could perform unsupervised clustering on the data(k-means), this will give you relationships like weights of the people whose health is not good for a particular number of days.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.