View source: R/data_transform.R
data_transform | R Documentation |
data.frame
for comparable Machine Learning prediction and visualizationOften economic and other Machine Learning data are of different units or sizes making either estimation, interpretation or visualization difficult. The solution to these issues can be handled if the data can be transformed into unitless or data of similar magnitude. This is what data_transform
is set to do. It is simple and straight forward to use.
data_transform(data, method, MARGIN = 2)
data |
A |
method |
The type of transformation. There three options. |
MARGIN |
Option to either transform the data |
This function returns the output of the data transformation process as
tata_transformed |
A new |
library(Dyn4cast)
# View the data without transformation
data0 <- Transform %>%
pivot_longer(!X, names_to = "Factors", values_to = "Data")
ggplot(data = data0, aes(x = X, y = Data, fill = Factors, color = Factors)) +
geom_line() +
scale_fill_brewer(palette = "Set1") +
scale_color_brewer(palette = "Set1") +
labs(y = "Data", x = "Series", color = "Factors") +
theme_bw(base_size = 12)
# Example 1: Transformation by min-max method.
# You could also transform the `X column` but is is better not to.
data1 <- data_transform(Transform[, -1], 1)
data1 <- cbind(Transform[, 1], data1)
data1 <- data1 %>%
pivot_longer(!X, names_to = "Factors", values_to = "Data")
ggplot(data = data1, aes(x = X, y = Data, fill = Factors, color = Factors)) +
geom_line() +
scale_fill_brewer(palette = "Set1") +
scale_color_brewer(palette = "Set1") +
labs(y = "Data", x = "Series", color = "Factors") +
theme_bw(base_size = 12)
# Example 2: `log` transformation
data2 <- data_transform(Transform[, -1], 2)
data2 <- cbind(Transform[, 1], data2)
data2 <- data2 %>%
pivot_longer(!X, names_to = "Factors", values_to = "Data")
ggplot(data = data2, aes(x = X, y = Data, fill = Factors, color = Factors)) +
geom_line() +
scale_fill_brewer(palette = "Set1") +
scale_color_brewer(palette = "Set1") +
labs(y = "Data", x = "Series", color = "Factors") +
theme_bw(base_size = 12)
# Example 3: `Mean-SD` transformation
data3 <- data_transform(Transform[, -1], 3)
data3 <- cbind(Transform[, 1], data3)
data3 <- data3 %>%
pivot_longer(!X, names_to = "Factors", values_to = "Data")
ggplot(data = data3, aes(x = X, y = Data, fill = Factors, color = Factors)) +
geom_line() +
scale_fill_brewer(palette = "Set1") +
scale_color_brewer(palette = "Set1") +
labs(y = "Data", x = "Series", color = "Factors") +
theme_bw(base_size = 12)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.