Book Image

Mastering Scientific Computing with R

Book Image

Mastering Scientific Computing with R

Overview of this book

Table of Contents (17 chapters)
Mastering Scientific Computing with R
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Visually exploring nonlinear relationships


Let's say that we want to understand the relationship between height, weight, age, and gender. We probably have some preconceived notions about how these variables relate to one another (for example, taller people probably tend to weigh more). Let's perform the following steps:

  1. Firstly, load the data and attach the data frame using the following code:

    body.measures <- read.csv('nhanes_body.txt')
    attach(body.measures)
  2. Now, let's just look at the data visually, as shown in the following diagram, an important first step in most analyses. Let's have a look at the following function:

    plot(age, height, xlab = 'Age', ylab = 'Height', main = 'Height vs Age')

The previous dataset has thousands of data points, so a simple plot with default graphics options looks messy but it is clear that this is not a linear relationship. However, even the previous plot shows us some features about the relationship between age and height. The most obvious feature is that the...