-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModule-3-Example-1.R
More file actions
34 lines (19 loc) · 778 Bytes
/
Copy pathModule-3-Example-1.R
File metadata and controls
34 lines (19 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Create a vector for hights
height <- c(176, 154, 138, 196, 132, 176, 181, 169, 150, 175)
# Create a vector for bodymass
bodymass <- c(82, 49, 53, 112, 47, 69, 77, 71, 62, 78)
# Create a scotterplot
plot(bodymass, height)
# A better scotterplot
plot(bodymass, height, pch = 16, cex = 1.3, col = "blue", main = "HEIGHT PLOTTED AGAINST BODY MASS", xlab = "BODY MASS (kg)", ylab = "HEIGHT (cm)")
# Correlation
cor(bodymass, height)
cor(height, bodymass)
# A simple linear regression
lm(height ~ bodymass)
# A line on the past plot
abline(98.0054, 0.9528)
# A better approach is to use variables and pass data to other functions
m <- lm(height ~ bodymass)
# better would be to do this - No hard coding of data values.
abline(m)