-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathModule-4-Example-9.R
More file actions
38 lines (23 loc) · 815 Bytes
/
Module-4-Example-9.R
File metadata and controls
38 lines (23 loc) · 815 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
35
# Transformation illustration.
# Let us generate an example data
set.seed(123456789)
# Create sequence of data between 1 and 50
x<-seq(1, 50)
y <- (runif(1, 0.1, 2.5) * x+ rnorm(50, mean = 2, sd = 6))^2
# The plot shows that this data does not have a linear pattern.
plot(x, y)
m1 <- lm(y~x)
summary(m1)
# We see also in the residual plot that the data does not show a linear pattern.
plot(x , resid(m1) )
# Now, let us transform the data to a new form.
# We calculate the square root of y
y1 <- sqrt(y)
# Now, data has a linear pattern.
plot(x, y1)
m2 <- lm(y1~x)
summary(m2)
# Residual plot also shows a clear linear pattern.
plot(x , resid(m2))
# It is important to know that after transformation,
# we need to interepret all of the prediction results using the transformation function.